Mercurial > trustbridge
comparison ui/mainwindow.cpp @ 0:cb0cde2c5eb9
Initial commit. Basically a Hello World with a Tray Icon.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 07 Feb 2014 11:41:15 +0000 |
parents | |
children | cf88cc432b9d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb0cde2c5eb9 |
---|---|
1 #include "mainwindow.h" | |
2 | |
3 #include <QDebug> | |
4 #include <QMessageBox> | |
5 #include <QSystemTrayIcon> | |
6 #include <QAction> | |
7 #include <QDialog> | |
8 #include <QMenu> | |
9 | |
10 MainWindow::MainWindow() { | |
11 createActions(); | |
12 createTrayIcon(); | |
13 | |
14 connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), | |
15 this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); | |
16 } | |
17 | |
18 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) | |
19 { | |
20 showMessage(); | |
21 qDebug() << "Activated for reason: " << reason; | |
22 switch (reason) { | |
23 case QSystemTrayIcon::Trigger: | |
24 case QSystemTrayIcon::DoubleClick: | |
25 case QSystemTrayIcon::MiddleClick: | |
26 showMessage(); | |
27 break; | |
28 default: | |
29 ; | |
30 } | |
31 } | |
32 | |
33 void MainWindow::showMessage() | |
34 { | |
35 mTrayIcon->showMessage("Hello", "World", QSystemTrayIcon::Information, | |
36 10000); | |
37 } | |
38 void MainWindow::manualCheck() | |
39 { | |
40 QMessageBox::information(0, "Yay", | |
41 "It Woarx.\n"); | |
42 } | |
43 | |
44 void MainWindow::createActions() | |
45 { | |
46 mCheckUpdates = new QAction(tr("Check for Updates"), this); | |
47 connect(mCheckUpdates, SIGNAL(triggered()), this, SLOT(manualCheck())); | |
48 } | |
49 | |
50 void MainWindow::createTrayIcon() | |
51 { | |
52 QIcon trayImg = QIcon(":/img/tray_22.png"); | |
53 | |
54 qDebug() << "Creating tray icon"; | |
55 mTrayMenu = new QMenu(this); | |
56 mTrayMenu->addAction(mCheckUpdates); | |
57 | |
58 mTrayIcon = new QSystemTrayIcon(this); | |
59 mTrayIcon->setContextMenu(mTrayMenu); | |
60 | |
61 mTrayIcon->setIcon(trayImg); | |
62 setWindowIcon(trayImg); | |
63 mTrayIcon->show(); | |
64 mTrayIcon->setToolTip(tr("m13ui")); | |
65 showMessage(); | |
66 } |