refactor: systemtray is now a separate object

master
Denes Matetelki 14 years ago
parent e2ed4ce25a
commit 68422f166b

1
.gitignore vendored

@ -0,0 +1 @@
*.qm

@ -7,6 +7,7 @@
#include <QTranslator>
#include "mainwindow.h"
#include "systemtray.h"
void printUsage()
@ -82,7 +83,8 @@ int main(int argc, char *argv[])
}
// system tray?
MainWindow w(isSystemTray or isShowMinimized);
MainWindow w;
SystemTray systemtray(&w);
if (isSystemTray or isShowMinimized)
{
if (!QSystemTrayIcon::isSystemTrayAvailable())
@ -93,7 +95,9 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
QApplication::setQuitOnLastWindowClosed(false);
w.showSysTray();
// w.showSysTray();
systemtray.setup();
systemtray.show();
}
if (!isShowMinimized) w.show();

@ -30,7 +30,7 @@ extern void exportScaneToPng(QGraphicsScene *scene,
*/
MainWindow::MainWindow(bool isSystemtray, QWidget *parent) :
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow),
m_aboutDialog(0)
@ -49,8 +49,6 @@ MainWindow::MainWindow(bool isSystemtray, QWidget *parent) :
m_graphicsView = new GraphWidget(m_ui->centralWidget);
setCentralWidget(m_graphicsView);
if (isSystemtray) setupSystemTray();
}
MainWindow::~MainWindow()
@ -104,35 +102,6 @@ void MainWindow::exportScene()
}
}
void MainWindow::setupSystemTray()
{
m_systemTrayIcon = new QSystemTrayIcon(0);
m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon);
connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon);
connect(m_maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon);
connect(m_restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon);
connect(m_quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
m_trayIconMenu = new QMenu(this);
m_trayIconMenu->addAction(m_minimizeAction);
m_trayIconMenu->addAction(m_maximizeAction);
m_trayIconMenu->addAction(m_restoreAction);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_quitAction);
m_systemTrayIcon->setContextMenu(m_trayIconMenu);
m_icon = new QIcon(":/heart.svg");
m_systemTrayIcon->setIcon(QIcon(":/heart.svg"));
}
void MainWindow::about()
{
qDebug() << __PRETTY_FUNCTION__;
@ -151,8 +120,3 @@ void MainWindow::aboutDestroyed()
setEnabled(true);
}
void MainWindow::showSysTray()
{
m_systemTrayIcon->show();
}

@ -16,9 +16,8 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
explicit MainWindow(bool isSystemTray = false, QWidget *parent = 0);
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void showSysTray();
public slots:
void klakk();
@ -28,20 +27,10 @@ public slots:
private:
void setupSystemTray();
Ui::MainWindow *m_ui;
AboutDialog *m_aboutDialog;
GraphWidget *m_graphicsView;
QSystemTrayIcon *m_systemTrayIcon;
MainWindow *m_mainWindow;
QMenu *m_trayIconMenu;
QAction *m_minimizeAction;
QAction *m_maximizeAction;
QAction *m_restoreAction;
QAction *m_quitAction;
QIcon *m_icon;
};
#endif // MAINWINDOW_H

@ -15,13 +15,15 @@ SOURCES += main.cpp\
aboutdialog.cpp \
graphwidget.cpp \
node.cpp \
edge.cpp
edge.cpp \
systemtray.cpp
HEADERS += mainwindow.h \
aboutdialog.h \
graphwidget.h \
node.h \
edge.h
edge.h \
systemtray.h
FORMS += mainwindow.ui \
aboutdialog.ui

@ -42,66 +42,80 @@ p, li { white-space: pre-wrap; }
<translation type="unfinished">Fajl</translation>
</message>
<message>
<location filename="mainwindow.ui" line="39"/>
<location filename="mainwindow.ui" line="41"/>
<source>&amp;Help</source>
<translation type="unfinished">Segitseg</translation>
</message>
<message>
<location filename="mainwindow.ui" line="57"/>
<location filename="mainwindow.ui" line="59"/>
<source>&amp;New</source>
<translation type="unfinished">Uj</translation>
</message>
<message>
<location filename="mainwindow.ui" line="65"/>
<location filename="mainwindow.ui" line="67"/>
<source>&amp;Open</source>
<translation type="unfinished">Megnyitas</translation>
</message>
<message>
<location filename="mainwindow.ui" line="73"/>
<location filename="mainwindow.ui" line="75"/>
<source>&amp;Save</source>
<translation type="unfinished">Mentes</translation>
</message>
<message>
<location filename="mainwindow.ui" line="81"/>
<location filename="mainwindow.cpp" line="40"/>
<location filename="mainwindow.ui" line="83"/>
<source>&amp;Quit</source>
<translation type="unfinished">Kilepes</translation>
</message>
<message>
<location filename="mainwindow.ui" line="89"/>
<location filename="mainwindow.ui" line="91"/>
<source>&amp;About QtMindMap</source>
<translation type="unfinished">A QtMindMap-rol</translation>
</message>
<message>
<location filename="mainwindow.ui" line="94"/>
<location filename="mainwindow.ui" line="96"/>
<source>&amp;Close</source>
<translation type="unfinished">Bezaras</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="31"/>
<source>Mi&amp;nimize</source>
<translation type="unfinished">&amp;Talcara</translation>
<location filename="mainwindow.ui" line="104"/>
<source>E&amp;xport</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="34"/>
<source>Ma&amp;ximize</source>
<translation type="unfinished">Teljes &amp;meret</translation>
<location filename="mainwindow.ui" line="107"/>
<source>Export</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="37"/>
<source>&amp;Restore</source>
<translation type="unfinished">&amp;Visszaallita</translation>
<location filename="mainwindow.ui" line="110"/>
<source>Ctrl+X</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="71"/>
<source>Export MindMap to image</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="73"/>
<source>PNG image file (*.png)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="99"/>
<source>MindMap exported as </source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="main.cpp" line="95"/>
<location filename="main.cpp" line="93"/>
<source>QtMindMap Error</source>
<translation type="unfinished">QtMindMap hiba</translation>
</message>
<message>
<location filename="main.cpp" line="96"/>
<location filename="main.cpp" line="94"/>
<source>I couldn&apos;t detect any system tray on this system.</source>
<translation type="unfinished">Nem talalhato talca a jelenlegi rendszerben.</translation>
</message>
@ -109,20 +123,24 @@ p, li { white-space: pre-wrap; }
<context>
<name>SystemTray</name>
<message>
<location filename="systemtray.cpp" line="13"/>
<source>Mi&amp;nimize</source>
<translation type="obsolete">&amp;Talcara</translation>
<translation type="unfinished">&amp;Talcara</translation>
</message>
<message>
<location filename="systemtray.cpp" line="16"/>
<source>Ma&amp;ximize</source>
<translation type="obsolete">Teljes &amp;meret</translation>
<translation type="unfinished">Teljes &amp;meret</translation>
</message>
<message>
<location filename="systemtray.cpp" line="19"/>
<source>&amp;Restore</source>
<translation type="obsolete">&amp;Visszaallita</translation>
<translation type="unfinished">&amp;Visszaallita</translation>
</message>
<message>
<location filename="systemtray.cpp" line="22"/>
<source>&amp;Quit</source>
<translation type="obsolete">&amp;Kilepes</translation>
<translation type="unfinished">&amp;Kilepes</translation>
</message>
</context>
</TS>

@ -0,0 +1,51 @@
#include "systemtray.h"
#include <QApplication>
#include <QDebug>
void SystemTray::setup()
{
qDebug() << __PRETTY_FUNCTION__;
m_systemTrayIcon = new QSystemTrayIcon(0);
m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon);
connect(m_minimizeAction, SIGNAL(triggered()), m_mainWindow, SLOT(hide()));
m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon);
connect(m_maximizeAction, SIGNAL(triggered()), m_mainWindow, SLOT(showMaximized()));
m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon);
connect(m_restoreAction, SIGNAL(triggered()), m_mainWindow, SLOT(showNormal()));
m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon);
connect(m_quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
m_trayIconMenu = new QMenu(this);
m_trayIconMenu->addAction(m_minimizeAction);
m_trayIconMenu->addAction(m_maximizeAction);
m_trayIconMenu->addAction(m_restoreAction);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_quitAction);
m_systemTrayIcon->setContextMenu(m_trayIconMenu);
m_icon = new QIcon(":/heart.svg");
m_systemTrayIcon->setIcon(QIcon(":/heart.svg"));
}
SystemTray::SystemTray(MainWindow *mainWindow, QWidget *parent) :
QWidget(parent),
m_mainWindow(mainWindow)
{
qDebug() << __PRETTY_FUNCTION__;
}
void SystemTray::show()
{
m_systemTrayIcon->show();
}

@ -0,0 +1,34 @@
#ifndef SYSTEMTRAY_H
#define SYSTEMTRAY_H
#include <QObject>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include "mainwindow.h"
class SystemTray : public QWidget
{
Q_OBJECT
public:
explicit SystemTray(MainWindow *mainWindow, QWidget *parent = 0);
void setup();
void show();
private:
MainWindow *m_mainWindow;
QSystemTrayIcon *m_systemTrayIcon;
QMenu *m_trayIconMenu;
QAction *m_minimizeAction;
QAction *m_maximizeAction;
QAction *m_restoreAction;
QAction *m_quitAction;
QIcon *m_icon;
};
#endif // SYSTEMTRAY_H
Loading…
Cancel
Save