From 3cc882829aab0014456f8451cc4454bf158f12c1 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 19 Dec 2020 04:26:43 -0800 Subject: [PATCH] fix PR #1601 (#1610) * fix PR #1601 * use mono icon on macOS --- src/core/coreconfig.cpp | 15 -- src/core/coreconfig.h | 9 -- src/core/global.h | 2 + src/core/iconfig.h | 11 +- src/core/sessionconfig.cpp | 19 ++- src/core/sessionconfig.h | 9 ++ src/core/singleinstanceguard.cpp | 2 - src/data/core/core.qrc | 2 + src/data/core/logo/vnote_mono.png | Bin 0 -> 10438 bytes src/main.cpp | 8 +- src/widgets/dialogs/settings/editorpage.cpp | 2 +- src/widgets/dialogs/settings/editorpage.h | 1 + src/widgets/dialogs/settings/generalpage.cpp | 25 ++-- src/widgets/dialogs/settings/generalpage.h | 1 - src/widgets/mainwindow.cpp | 138 +++++++++---------- src/widgets/mainwindow.h | 25 ++-- src/widgets/systemtrayhelper.cpp | 50 +++++++ src/widgets/systemtrayhelper.h | 19 +++ src/widgets/toolbarhelper.cpp | 5 + src/widgets/viewarea.h | 1 - src/widgets/widgets.pri | 2 + 21 files changed, 214 insertions(+), 132 deletions(-) create mode 100644 src/data/core/logo/vnote_mono.png create mode 100644 src/widgets/systemtrayhelper.cpp create mode 100644 src/widgets/systemtrayhelper.h diff --git a/src/core/coreconfig.cpp b/src/core/coreconfig.cpp index 7c2d7cc6..56c44289 100644 --- a/src/core/coreconfig.cpp +++ b/src/core/coreconfig.cpp @@ -41,10 +41,6 @@ void CoreConfig::init(const QJsonObject &p_app, if (m_toolBarIconSize <= 0) { m_toolBarIconSize = 16; } - - if (!isUndefinedKey(appObj, userObj, "minimize_to_system_tray")) { - m_minimizeToSystemTray = READBOOL(QStringLiteral("minimize_to_system_tray")) ? 1 : 0; - } } QJsonObject CoreConfig::toJson() const @@ -54,9 +50,6 @@ QJsonObject CoreConfig::toJson() const obj[QStringLiteral("locale")] = m_locale; obj[QStringLiteral("shortcuts")] = saveShortcuts(); obj[QStringLiteral("toolbar_icon_size")] = m_toolBarIconSize; - if (m_minimizeToSystemTray != -1) { - obj[QStringLiteral("minimize_to_system_tray")] = m_minimizeToSystemTray > 0; - } return obj; } @@ -130,11 +123,3 @@ void CoreConfig::setToolBarIconSize(int p_size) Q_ASSERT(p_size > 0); updateConfig(m_toolBarIconSize, p_size, this); } - -int CoreConfig::getMinimizeToSystemTray() const { - return m_minimizeToSystemTray; -} - -void CoreConfig::setMinimizeToSystemTray(bool state){ - updateConfig(m_minimizeToSystemTray, int(state), this); -} diff --git a/src/core/coreconfig.h b/src/core/coreconfig.h index 533a74d4..71d61806 100644 --- a/src/core/coreconfig.h +++ b/src/core/coreconfig.h @@ -48,9 +48,6 @@ namespace vnotex int getToolBarIconSize() const; void setToolBarIconSize(int p_size); - int getMinimizeToSystemTray() const; - void setMinimizeToSystemTray(bool state); - static const QStringList &getAvailableLocales(); private: @@ -70,12 +67,6 @@ namespace vnotex // Icon size of MainWindow tool bar. int m_toolBarIconSize = 16; - // Whether to minimize to tray. - // -1 for prompting for user; - // 0 for disabling minimizing to system tray; - // 1 for enabling minimizing to system tray; - int m_minimizeToSystemTray = -1; - static QStringList s_availableLocales; }; } // ns vnotex diff --git a/src/core/global.h b/src/core/global.h index 1c9962a3..88a727c9 100644 --- a/src/core/global.h +++ b/src/core/global.h @@ -73,6 +73,8 @@ namespace vnotex }; Q_DECLARE_FLAGS(FindOptions, FindOption); + enum { RESTART_EXIT_CODE = 1000 }; + } // ns vnotex Q_DECLARE_OPERATORS_FOR_FLAGS(vnotex::FindOptions); diff --git a/src/core/iconfig.h b/src/core/iconfig.h index daf0db78..27412734 100644 --- a/src/core/iconfig.h +++ b/src/core/iconfig.h @@ -130,10 +130,13 @@ namespace vnotex const QJsonObject &p_user, const QString &p_key) { - if (p_user.find(p_key) == p_user.end() && p_default.find(p_key) == p_default.end()) { - return true; - } - return false; + return !p_default.contains(p_key) && !p_user.contains(p_key); + } + + static bool isUndefinedKey(const QJsonObject &p_obj, + const QString &p_key) + { + return !p_obj.contains(p_key); } template diff --git a/src/core/sessionconfig.cpp b/src/core/sessionconfig.cpp index 29c6df46..4a0273d3 100644 --- a/src/core/sessionconfig.cpp +++ b/src/core/sessionconfig.cpp @@ -72,7 +72,7 @@ void SessionConfig::loadCore(const QJsonObject &p_session) m_openGL = stringToOpenGL(option); } - if (coreObj.contains(QStringLiteral("system_title_bar"))) { + if (!isUndefinedKey(coreObj, QStringLiteral("system_title_bar"))) { m_systemTitleBarEnabled = readBool(coreObj, QStringLiteral("system_title_bar")); } else { // Enable system title bar on macOS by default. @@ -82,6 +82,10 @@ void SessionConfig::loadCore(const QJsonObject &p_session) m_systemTitleBarEnabled = false; #endif } + + if (!isUndefinedKey(coreObj, QStringLiteral("minimize_to_system_tray"))) { + m_minimizeToSystemTray = readBool(coreObj, QStringLiteral("minimize_to_system_tray")) ? 1 : 0; + } } QJsonObject SessionConfig::saveCore() const @@ -91,6 +95,9 @@ QJsonObject SessionConfig::saveCore() const coreObj[QStringLiteral("current_notebook_root_folder_path")] = m_currentNotebookRootFolderPath; coreObj[QStringLiteral("opengl")] = openGLToString(m_openGL); coreObj[QStringLiteral("system_title_bar")] = m_systemTitleBarEnabled; + if (m_minimizeToSystemTray != -1) { + coreObj[QStringLiteral("minimize_to_system_tray")] = m_minimizeToSystemTray > 0; + } return coreObj; } @@ -260,3 +267,13 @@ void SessionConfig::setSystemTitleBarEnabled(bool p_enabled) { updateConfig(m_systemTitleBarEnabled, p_enabled, this); } + +int SessionConfig::getMinimizeToSystemTray() const +{ + return m_minimizeToSystemTray; +} + +void SessionConfig::setMinimizeToSystemTray(bool p_enabled) +{ + updateConfig(m_minimizeToSystemTray, p_enabled ? 1 : 0, this); +} diff --git a/src/core/sessionconfig.h b/src/core/sessionconfig.h index d91d9a26..5b6dcf22 100644 --- a/src/core/sessionconfig.h +++ b/src/core/sessionconfig.h @@ -79,6 +79,9 @@ namespace vnotex static QString openGLToString(OpenGL p_option); static OpenGL stringToOpenGL(const QString &p_str); + int getMinimizeToSystemTray() const; + void setMinimizeToSystemTray(bool p_enabled); + private: void loadCore(const QJsonObject &p_session); @@ -105,6 +108,12 @@ namespace vnotex // Whether use system's title bar or not. bool m_systemTitleBarEnabled = false; + + // Whether to minimize to tray. + // -1 for prompting for user; + // 0 for disabling minimizing to system tray; + // 1 for enabling minimizing to system tray. + int m_minimizeToSystemTray = -1; }; } // ns vnotex diff --git a/src/core/singleinstanceguard.cpp b/src/core/singleinstanceguard.cpp index f16e6029..daeaeed6 100644 --- a/src/core/singleinstanceguard.cpp +++ b/src/core/singleinstanceguard.cpp @@ -23,8 +23,6 @@ bool SingleInstanceGuard::tryRun() // this will attach to the old segment, then exit, freeing the old segment. if (m_sharedMemory.attach()) { qInfo() << "another instance is running"; - // So try to show it? - showInstance(); return false; } diff --git a/src/data/core/core.qrc b/src/data/core/core.qrc index e348781a..46ba2be0 100644 --- a/src/data/core/core.qrc +++ b/src/data/core/core.qrc @@ -74,5 +74,7 @@ icons/find_replace_editor.svg logo/vnote.svg logo/vnote.png + logo/256x256/vnote.png + logo/vnote_mono.png diff --git a/src/data/core/logo/vnote_mono.png b/src/data/core/logo/vnote_mono.png new file mode 100644 index 0000000000000000000000000000000000000000..bcea9434a3f8c0c326956abb5d1c10608b428590 GIT binary patch literal 10438 zcmeHtc{tSX_xDJaWT`AE4Jm6vik7jAr7&dQ_ceP|3?fEKYB0(gWr?vHOGt>Zgs3bN zV+)bxGsfPCVaz;0bFeV_ZB`<(MSulu|(Hq_zbIL!fp zK)4XPH%%cBCdR>+ofW*X*%)d8e+~y~BFx#r=MlU6bMSoRo~}(G1j5~V@MZELzBmG2 zo(j5U9b^{Z5ftL`;0`1tBt*{J-#5_B<=!2+fCrv$R#i?zAZHuzb3NPKPiD5iA_Yw80r-L$GPxw8Iv?g`sW*3x|s+ zJPfO}t#dpO^1uFZma%5@x-nw^KC4uD<=u;(JR~1vw79ND*d$ZU18Pnf9FlbE9E_En7wy3XH{u|PIb*Ck1 zM^09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C6LSxC<&vJTU=!Je@CGI zGlDE7mtNZiV}<035=(R6;IzOz@X0(15BhW+h6&;oB?vFPH4j*igZV{$(H-cGZ~$c> z6LSo2gT*N1a}}WJ2jt!$j6~VC-fkdS3KDf{?;ScUPELl=1=AJYn8Pc8CWqpkp=yr% z8CV4QIwVT=vNVYow5VWar>|$z>OTYiDCH^Ml06_Ts2F($()wpeT=gu8yK|0p%W=bv zto~4k+CK!ElT;h~vr8*UfH{M###sNTC}Y?G(iW77|MlKFut00t9^ #include #include +#include #include #include @@ -16,13 +17,12 @@ #include #include #include +#include #include #include #include #include -#include - using namespace vnotex; void loadTranslators(QApplication &p_app); @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) loadTranslators(app); - MainWindow window(nullptr); + MainWindow window; window.show(); VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base)); @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) int ret = app.exec(); if (ret == RESTART_EXIT_CODE) { - // Ask to restart VNote. + // Asked to restart VNote. guard.exit(); QProcess::startDetached(qApp->applicationFilePath(), QStringList()); return 0; diff --git a/src/widgets/dialogs/settings/editorpage.cpp b/src/widgets/dialogs/settings/editorpage.cpp index 49d8958b..9624f928 100644 --- a/src/widgets/dialogs/settings/editorpage.cpp +++ b/src/widgets/dialogs/settings/editorpage.cpp @@ -43,7 +43,7 @@ void EditorPage::setupUI() m_toolBarIconSizeSpinBox->setRange(1, 48); m_toolBarIconSizeSpinBox->setSingleStep(1); - const QString label(tr("Toolbar icon size:")); + const QString label(tr("Tool bar icon size:")); mainLayout->addRow(label, m_toolBarIconSizeSpinBox); addSearchItem(label, m_toolBarIconSizeSpinBox->toolTip(), m_toolBarIconSizeSpinBox); connect(m_toolBarIconSizeSpinBox, QOverload::of(&QSpinBox::valueChanged), diff --git a/src/widgets/dialogs/settings/editorpage.h b/src/widgets/dialogs/settings/editorpage.h index 8e39e791..5f53b22f 100644 --- a/src/widgets/dialogs/settings/editorpage.h +++ b/src/widgets/dialogs/settings/editorpage.h @@ -28,6 +28,7 @@ namespace vnotex void setupUI(); QComboBox *m_autoSavePolicyComboBox = nullptr; + QSpinBox *m_toolBarIconSizeSpinBox = nullptr; }; } diff --git a/src/widgets/dialogs/settings/generalpage.cpp b/src/widgets/dialogs/settings/generalpage.cpp index d44e2e16..74b0ddee 100644 --- a/src/widgets/dialogs/settings/generalpage.cpp +++ b/src/widgets/dialogs/settings/generalpage.cpp @@ -57,21 +57,23 @@ void GeneralPage::setupUI() } #endif -#if not defined(Q_OS_MACOS) +#if !defined(Q_OS_MACOS) { - m_systemTrayCheckBox = WidgetsFactory::createCheckBox("System tray"); + const QString label(tr("Minimize to system tray")); + m_systemTrayCheckBox = WidgetsFactory::createCheckBox(label, this); + m_systemTrayCheckBox->setToolTip(tr("Minimize to system tray when closing")); mainLayout->addRow(m_systemTrayCheckBox); - + addSearchItem(label, m_systemTrayCheckBox->toolTip(), m_systemTrayCheckBox); connect(m_systemTrayCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::pageIsChanged); } #endif - } void GeneralPage::loadInternal() { const auto &coreConfig = ConfigMgr::getInst().getCoreConfig(); + const auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); { int idx = m_localeComboBox->findData(coreConfig.getLocale()); @@ -80,22 +82,21 @@ void GeneralPage::loadInternal() } if (m_openGLComboBox) { - const auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); int idx = m_openGLComboBox->findData(sessionConfig.getOpenGL()); Q_ASSERT(idx != -1); m_openGLComboBox->setCurrentIndex(idx); } - if(m_systemTrayCheckBox){ - auto toTray = coreConfig.getMinimizeToSystemTray(); - if(toTray) - m_systemTrayCheckBox->setChecked(true); + if (m_systemTrayCheckBox) { + int toTray = sessionConfig.getMinimizeToSystemTray(); + m_systemTrayCheckBox->setChecked(toTray > 0); } } void GeneralPage::saveInternal() { auto &coreConfig = ConfigMgr::getInst().getCoreConfig(); + auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); { auto locale = m_localeComboBox->currentData().toString(); @@ -103,13 +104,13 @@ void GeneralPage::saveInternal() } if (m_openGLComboBox) { - auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); int opt = m_openGLComboBox->currentData().toInt(); sessionConfig.setOpenGL(static_cast(opt)); } - if(m_systemTrayCheckBox) { - coreConfig.setMinimizeToSystemTray(m_systemTrayCheckBox->isChecked()); + if (m_systemTrayCheckBox) { + // This will override the -1 state. That is fine. + sessionConfig.setMinimizeToSystemTray(m_systemTrayCheckBox->isChecked()); } } diff --git a/src/widgets/dialogs/settings/generalpage.h b/src/widgets/dialogs/settings/generalpage.h index 90717e6d..af4e580e 100644 --- a/src/widgets/dialogs/settings/generalpage.h +++ b/src/widgets/dialogs/settings/generalpage.h @@ -29,7 +29,6 @@ namespace vnotex QComboBox *m_openGLComboBox = nullptr; QCheckBox *m_systemTrayCheckBox = nullptr; - }; } diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index f15af38e..18a939ea 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -16,8 +16,7 @@ #include #include #include -#include -#include +#include #include "toolbox.h" #include "notebookexplorer.h" @@ -30,12 +29,14 @@ #include #include #include +#include #include #include "viewwindow.h" #include "outlineviewer.h" #include #include "navigationmodemgr.h" -#include +#include "messageboxhelper.h" +#include "systemtrayhelper.h" #include @@ -50,18 +51,11 @@ MainWindow::MainWindow(QWidget *p_parent) setupUI(); - initSystemTrayIcon(); - setupShortcuts(); loadStateAndGeometry(); -#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) - QApplication::setQuitOnLastWindowClosed(false); -#endif - - // The signal is particularly useful if your application has - // to do some last-second cleanup. + // The signal is particularly useful if your application has to do some last-second cleanup. // Note that no user interaction is possible in this state. connect(qApp, &QCoreApplication::aboutToQuit, this, &MainWindow::closeOnQuit); @@ -91,6 +85,7 @@ void MainWindow::setupUI() setupDocks(); setupToolBar(); setupStatusBar(); + setupSystemTray(); activateDock(m_docks[DockIndex::NavigationDock]); } @@ -289,36 +284,27 @@ void MainWindow::setupNotebookExplorer(QWidget *p_parent) void MainWindow::closeEvent(QCloseEvent *p_event) { - // TODO: support minimized to system tray. + const int toTray = ConfigMgr::getInst().getSessionConfig().getMinimizeToSystemTray(); + bool isExit = m_requestQuit > -1 || toTray == 0; + const int exitCode = m_requestQuit; + m_requestQuit = -1; - auto toTray = ConfigMgr::getInst().getCoreConfig().getMinimizeToSystemTray(); - bool isExit = m_requestQuit; - m_requestQuit = 0; - - if (isVisible()) { - saveStateAndGeometry(); - } - -#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) +#if defined(Q_OS_MACOS) // Do not support minimized to tray on macOS. - if (!isExit) { - p_event->accept(); - return; - } + isExit = true; #endif if(!isExit && toTray == -1){ int ret = MessageBoxHelper::questionYesNo(MessageBoxHelper::Question, - tr("Close VNote"), - tr("Do you want to minimize VNote to system tray " - "instead of quitting it when closing VNote?"), + tr("Close %1").arg(qApp->applicationName()), + tr("Do you want to minimize %1 to system tray " + "instead of quitting when closing %1?").arg(qApp->applicationName()), tr("You could change the option in Settings later."), this); if (ret == QMessageBox::Yes) { - ConfigMgr::getInst().getCoreConfig().setMinimizeToSystemTray(true); - hide(); + ConfigMgr::getInst().getSessionConfig().setMinimizeToSystemTray(true); } else if (ret == QMessageBox::No) { - ConfigMgr::getInst().getCoreConfig().setMinimizeToSystemTray(false); + ConfigMgr::getInst().getSessionConfig().setMinimizeToSystemTray(false); isExit = true; } else { p_event->ignore(); @@ -326,10 +312,11 @@ void MainWindow::closeEvent(QCloseEvent *p_event) } } - if(isExit || toTray == 0 || !m_trayIcon->isVisible()){ - // really to quit, process workspace - // TODO: process workspace + if (isVisible()) { + saveStateAndGeometry(); + } + if (isExit || !m_trayIcon->isVisible()) { // Signal out the close event. auto event = QSharedPointer::create(); event->m_response = true; @@ -341,8 +328,8 @@ void MainWindow::closeEvent(QCloseEvent *p_event) } QMainWindow::closeEvent(p_event); - qApp->quit(); - }else { + qApp->exit(exitCode > -1 ? exitCode : 0); + } else { hide(); p_event->ignore(); } @@ -523,7 +510,7 @@ void MainWindow::setStayOnTop(bool p_enabled) bool shown = isVisible(); Qt::WindowFlags flags = windowFlags(); - Qt::WindowFlags magicFlag = Qt::WindowStaysOnTopHint; + const Qt::WindowFlags magicFlag = Qt::WindowStaysOnTopHint; if (p_enabled) { setWindowFlags(flags | magicFlag); } else { @@ -535,42 +522,49 @@ void MainWindow::setStayOnTop(bool p_enabled) } } -void MainWindow::initSystemTrayIcon(){ - QMenu *menu = new QMenu(this); - QAction *showMainWindowAct = menu->addAction(tr("Show VNote")); - connect(showMainWindowAct, &QAction::triggered, - this, &MainWindow::show); - - QAction *exitAct = menu->addAction(tr("Quit")); - connect(exitAct, &QAction::triggered, - this, [this](){ - this->m_requestQuit = 1; - this->close(); - }); - - QIcon sysIcon(":/vnotex/data/core/logo/vnote.png"); - -#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) - sysIcon.setIsMask(true); -#endif - - m_trayIcon = new QSystemTrayIcon(sysIcon, this); - m_trayIcon->setToolTip(tr("VNote")); - m_trayIcon->setContextMenu(menu); - - connect(m_trayIcon, &QSystemTrayIcon::activated, - this, [this](QSystemTrayIcon::ActivationReason p_reason){ -#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC) - if (p_reason == QSystemTrayIcon::Trigger) { - this->show(); - this->activateWindow(); - } -#endif - }); - +void MainWindow::setupSystemTray() +{ + m_trayIcon = SystemTrayHelper::setupSystemTray(this); m_trayIcon->show(); } -void MainWindow::restart(){ - QCoreApplication::exit(RESTART_EXIT_CODE); +void MainWindow::restart() +{ + m_requestQuit = RESTART_EXIT_CODE; + close(); +} + +void MainWindow::changeEvent(QEvent *p_event) +{ + if (p_event->type() == QEvent::WindowStateChange) { + QWindowStateChangeEvent *eve = static_cast(p_event); + m_windowOldState = eve->oldState(); + } + + QMainWindow::changeEvent(p_event); +} + +void MainWindow::showMainWindow() +{ + if (isMinimized()) { + if (m_windowOldState & Qt::WindowMaximized) { + showMaximized(); + } else if (m_windowOldState & Qt::WindowFullScreen) { + showFullScreen(); + } else { + showNormal(); + } + } else { + show(); + // Need to call raise() in macOS. + raise(); + } + + activateWindow(); +} + +void MainWindow::quitApp() +{ + m_requestQuit = 0; + close(); } diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index 1b739eeb..3fd5bea2 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -7,8 +7,6 @@ #include "toolbarhelper.h" #include "statusbarhelper.h" -#define RESTART_EXIT_CODE 1000 - class QDockWidget; class QSystemTrayIcon; @@ -47,6 +45,10 @@ namespace vnotex void restart(); + void showMainWindow(); + + void quitApp(); + signals: void mainWindowStarted(); @@ -61,6 +63,8 @@ namespace vnotex protected: void closeEvent(QCloseEvent *p_event) Q_DECL_OVERRIDE; + void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE; + private slots: void closeOnQuit(); @@ -105,13 +109,7 @@ namespace vnotex void setupShortcuts(); - // Init system tray and correspondign context menu. - void initSystemTrayIcon(); - - // Tray icon. - QSystemTrayIcon *m_trayIcon; - - bool m_requestQuit = false; + void setupSystemTray(); ToolBarHelper m_toolBarHelper; @@ -130,7 +128,14 @@ namespace vnotex QVector m_docks; bool m_layoutReset = false; - + + // -1: do not request to quit; + // 0 and above: exit code. + int m_requestQuit = -1; + + Qt::WindowStates m_windowOldState = Qt::WindowMinimized; + + QSystemTrayIcon *m_trayIcon = nullptr; }; } // ns vnotex diff --git a/src/widgets/systemtrayhelper.cpp b/src/widgets/systemtrayhelper.cpp new file mode 100644 index 00000000..1b97bc06 --- /dev/null +++ b/src/widgets/systemtrayhelper.cpp @@ -0,0 +1,50 @@ +#include "systemtrayhelper.h" + +#include +#include +#include +#include + +#include "mainwindow.h" +#include "widgetsfactory.h" + +using namespace vnotex; + +QSystemTrayIcon *SystemTrayHelper::setupSystemTray(MainWindow *p_win) +{ +#if defined(Q_OS_MACOS) + QIcon icon(":/vnotex/data/core/logo/vnote_mono.png"); + icon.setIsMask(true); +#else + QIcon icon(":/vnotex/data/core/logo/256x256/vnote.png"); +#endif + + auto trayIcon = new QSystemTrayIcon(icon, p_win); + trayIcon->setToolTip(qApp->applicationName()); + + MainWindow::connect(trayIcon, &QSystemTrayIcon::activated, + p_win, [p_win](QSystemTrayIcon::ActivationReason p_reason) { +#if !defined(Q_OS_MACOS) + if (p_reason == QSystemTrayIcon::Trigger) { + p_win->showMainWindow(); + } +#endif + }); + + auto menu = WidgetsFactory::createMenu(p_win); + trayIcon->setContextMenu(menu); + + menu->addAction(MainWindow::tr("Show Main Window"), + menu, + [p_win]() { + p_win->showMainWindow(); + }); + + menu->addAction(MainWindow::tr("Quit"), + menu, + [p_win]() { + p_win->quitApp(); + }); + + return trayIcon; +} diff --git a/src/widgets/systemtrayhelper.h b/src/widgets/systemtrayhelper.h new file mode 100644 index 00000000..b50666aa --- /dev/null +++ b/src/widgets/systemtrayhelper.h @@ -0,0 +1,19 @@ +#ifndef SYSTEMTRAYHELPER_H +#define SYSTEMTRAYHELPER_H + +class QSystemTrayIcon; + +namespace vnotex +{ + class MainWindow; + + class SystemTrayHelper + { + public: + SystemTrayHelper() = delete; + + static QSystemTrayIcon *setupSystemTray(MainWindow *p_win); + }; +} + +#endif // SYSTEMTRAYHELPER_H diff --git a/src/widgets/toolbarhelper.cpp b/src/widgets/toolbarhelper.cpp index 487492b2..6731dadc 100644 --- a/src/widgets/toolbarhelper.cpp +++ b/src/widgets/toolbarhelper.cpp @@ -308,6 +308,11 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too menu->addSeparator(); + menu->addAction(MainWindow::tr("Quit"), + menu, + [p_win]() { + p_win->quitApp(); + }); menu->addAction(MainWindow::tr("Restart"), menu, [p_win]() { diff --git a/src/widgets/viewarea.h b/src/widgets/viewarea.h index 404c49a7..b4864c33 100644 --- a/src/widgets/viewarea.h +++ b/src/widgets/viewarea.h @@ -13,7 +13,6 @@ class QLayout; class QSplitter; -class QTimer; namespace vnotex { diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri index 2bab2a94..634fefc9 100644 --- a/src/widgets/widgets.pri +++ b/src/widgets/widgets.pri @@ -43,6 +43,7 @@ SOURCES += \ $$PWD/outlineprovider.cpp \ $$PWD/outlineviewer.cpp \ $$PWD/propertydefs.cpp \ + $$PWD/systemtrayhelper.cpp \ $$PWD/textviewwindow.cpp \ $$PWD/toolbarhelper.cpp \ $$PWD/treeview.cpp \ @@ -122,6 +123,7 @@ HEADERS += \ $$PWD/outlineprovider.h \ $$PWD/outlineviewer.h \ $$PWD/propertydefs.h \ + $$PWD/systemtrayhelper.h \ $$PWD/textviewwindow.h \ $$PWD/textviewwindowhelper.h \ $$PWD/toolbarhelper.h \