diff --git a/include/mainwindow.h b/include/mainwindow.h index 0fde5f4..ea75345 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -43,6 +43,8 @@ public slots: void showMainToolbar(const bool &show = true); void showStatusIconToolbar(const bool &show = true); + // handle changed content at quit + void quit(); protected: @@ -52,10 +54,6 @@ protected: // show/hide toolbars, otherwise pass on the event to GraphWidget void keyPressEvent(QKeyEvent *event); -private slots: - - void quit(); - private: void setUpMainToolbar(); diff --git a/include/systemtray.h b/include/systemtray.h index 147f7e1..2c4dc66 100644 --- a/include/systemtray.h +++ b/include/systemtray.h @@ -14,20 +14,20 @@ class SystemTray : public QWidget public: explicit SystemTray(MainWindow *mainWindow, QWidget *parent = 0); - void setup(); - void show(); -private: + // access private member + void show() { m_systemTrayIcon->show(); } - MainWindow *m_mainWindow; +private: - QSystemTrayIcon *m_systemTrayIcon; - QMenu *m_trayIconMenu; - QAction *m_minimizeAction; - QAction *m_maximizeAction; - QAction *m_restoreAction; - QAction *m_quitAction; - QIcon *m_icon; + MainWindow *m_parent; + QSystemTrayIcon *m_systemTrayIcon; + QMenu *m_trayIconMenu; + QAction *m_minimizeAction; + QAction *m_maximizeAction; + QAction *m_restoreAction; + QAction *m_quitAction; + QIcon *m_icon; }; diff --git a/src/main.cpp b/src/main.cpp index 7743bdf..c8752d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) // system tray? MainWindow w; - SystemTray systemtray(&w); + SystemTray *systemtray; if (argParser.isSystemTray() or argParser.isShowMinimized()) { if (!QSystemTrayIcon::isSystemTrayAvailable()) @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } QApplication::setQuitOnLastWindowClosed(false); - systemtray.setup(); - systemtray.show(); + systemtray = new SystemTray(&w); + systemtray->show(); } // open file if any diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b364eeb..42666ad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -313,6 +313,14 @@ void MainWindow::showStatusIconToolbar(const bool &show) false); } +void MainWindow::quit() +{ + if (m_contentChanged && !closeFile()) + return; + + QApplication::instance()->quit(); +} + void MainWindow::closeEvent(QCloseEvent * event) { m_contentChanged && !closeFile() ? event->ignore() : event->accept(); @@ -338,15 +346,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) QMainWindow::keyPressEvent(event); } -void MainWindow::quit() -{ - if (m_contentChanged && !closeFile()) - return; - - QApplication::instance()->quit(); -} - - void MainWindow::setUpMainToolbar() { // why can't I do this with qtcreator? (adding actions to toolbar) diff --git a/src/systemtray.cpp b/src/systemtray.cpp index 4968880..5cf23a8 100644 --- a/src/systemtray.cpp +++ b/src/systemtray.cpp @@ -2,24 +2,27 @@ #include -void SystemTray::setup() + +SystemTray::SystemTray(MainWindow *mainWindow, QWidget *parent) + : QWidget(parent), + m_parent(mainWindow) { m_systemTrayIcon = new QSystemTrayIcon(0); m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon); - connect(m_minimizeAction, SIGNAL(triggered()), m_mainWindow, + connect(m_minimizeAction, SIGNAL(triggered()), m_parent, SLOT(hide())); m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon); - connect(m_maximizeAction, SIGNAL(triggered()), m_mainWindow, + connect(m_maximizeAction, SIGNAL(triggered()), m_parent, SLOT(showMaximized())); m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon); - connect(m_restoreAction, SIGNAL(triggered()), m_mainWindow, + connect(m_restoreAction, SIGNAL(triggered()), m_parent, SLOT(showNormal())); m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon); - connect(m_quitAction, SIGNAL(triggered()), qApp, + connect(m_quitAction, SIGNAL(triggered()), m_parent, SLOT(quit())); m_trayIconMenu = new QMenu(this); @@ -34,15 +37,3 @@ void SystemTray::setup() m_icon = new QIcon(":/qtmindmap.svg"); m_systemTrayIcon->setIcon(QIcon(":/qtmindmap.svg")); } - -SystemTray::SystemTray(MainWindow *mainWindow, QWidget *parent) : - QWidget(parent), - m_mainWindow(mainWindow) -{ -} - - -void SystemTray::show() -{ - m_systemTrayIcon->show(); -}