SystemTray does not care about contentchange at quit bugfix

master
Denes Matetelki 14 years ago
parent f68dab9bd0
commit 497bda949e

@ -43,6 +43,8 @@ public slots:
void showMainToolbar(const bool &show = true); void showMainToolbar(const bool &show = true);
void showStatusIconToolbar(const bool &show = true); void showStatusIconToolbar(const bool &show = true);
// handle changed content at quit
void quit();
protected: protected:
@ -52,10 +54,6 @@ protected:
// show/hide toolbars, otherwise pass on the event to GraphWidget // show/hide toolbars, otherwise pass on the event to GraphWidget
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
private slots:
void quit();
private: private:
void setUpMainToolbar(); void setUpMainToolbar();

@ -14,20 +14,20 @@ class SystemTray : public QWidget
public: public:
explicit SystemTray(MainWindow *mainWindow, QWidget *parent = 0); 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; MainWindow *m_parent;
QMenu *m_trayIconMenu; QSystemTrayIcon *m_systemTrayIcon;
QAction *m_minimizeAction; QMenu *m_trayIconMenu;
QAction *m_maximizeAction; QAction *m_minimizeAction;
QAction *m_restoreAction; QAction *m_maximizeAction;
QAction *m_quitAction; QAction *m_restoreAction;
QIcon *m_icon; QAction *m_quitAction;
QIcon *m_icon;
}; };

@ -37,7 +37,7 @@ int main(int argc, char *argv[])
// system tray? // system tray?
MainWindow w; MainWindow w;
SystemTray systemtray(&w); SystemTray *systemtray;
if (argParser.isSystemTray() or argParser.isShowMinimized()) if (argParser.isSystemTray() or argParser.isShowMinimized())
{ {
if (!QSystemTrayIcon::isSystemTrayAvailable()) if (!QSystemTrayIcon::isSystemTrayAvailable())
@ -48,8 +48,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
systemtray.setup(); systemtray = new SystemTray(&w);
systemtray.show(); systemtray->show();
} }
// open file if any // open file if any

@ -313,6 +313,14 @@ void MainWindow::showStatusIconToolbar(const bool &show)
false); false);
} }
void MainWindow::quit()
{
if (m_contentChanged && !closeFile())
return;
QApplication::instance()->quit();
}
void MainWindow::closeEvent(QCloseEvent * event) void MainWindow::closeEvent(QCloseEvent * event)
{ {
m_contentChanged && !closeFile() ? event->ignore() : event->accept(); m_contentChanged && !closeFile() ? event->ignore() : event->accept();
@ -338,15 +346,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
QMainWindow::keyPressEvent(event); QMainWindow::keyPressEvent(event);
} }
void MainWindow::quit()
{
if (m_contentChanged && !closeFile())
return;
QApplication::instance()->quit();
}
void MainWindow::setUpMainToolbar() void MainWindow::setUpMainToolbar()
{ {
// why can't I do this with qtcreator? (adding actions to toolbar) // why can't I do this with qtcreator? (adding actions to toolbar)

@ -2,24 +2,27 @@
#include <QApplication> #include <QApplication>
void SystemTray::setup()
SystemTray::SystemTray(MainWindow *mainWindow, QWidget *parent)
: QWidget(parent),
m_parent(mainWindow)
{ {
m_systemTrayIcon = new QSystemTrayIcon(0); m_systemTrayIcon = new QSystemTrayIcon(0);
m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon); 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())); SLOT(hide()));
m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon); 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())); SLOT(showMaximized()));
m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon); m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon);
connect(m_restoreAction, SIGNAL(triggered()), m_mainWindow, connect(m_restoreAction, SIGNAL(triggered()), m_parent,
SLOT(showNormal())); SLOT(showNormal()));
m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon); m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon);
connect(m_quitAction, SIGNAL(triggered()), qApp, connect(m_quitAction, SIGNAL(triggered()), m_parent,
SLOT(quit())); SLOT(quit()));
m_trayIconMenu = new QMenu(this); m_trayIconMenu = new QMenu(this);
@ -34,15 +37,3 @@ void SystemTray::setup()
m_icon = new QIcon(":/qtmindmap.svg"); m_icon = new QIcon(":/qtmindmap.svg");
m_systemTrayIcon->setIcon(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();
}

Loading…
Cancel
Save