diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/mainwindow.cpp	Fri Feb 07 11:41:15 2014 +0000
@@ -0,0 +1,66 @@
+#include "mainwindow.h"
+
+#include <QDebug>
+#include <QMessageBox>
+#include <QSystemTrayIcon>
+#include <QAction>
+#include <QDialog>
+#include <QMenu>
+
+MainWindow::MainWindow() {
+    createActions();
+    createTrayIcon();
+
+    connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+}
+
+void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+    showMessage();
+    qDebug() << "Activated for reason: " << reason;
+    switch (reason) {
+    case QSystemTrayIcon::Trigger:
+    case QSystemTrayIcon::DoubleClick:
+    case QSystemTrayIcon::MiddleClick:
+        showMessage();
+        break;
+    default:
+        ;
+    }
+}
+
+void MainWindow::showMessage()
+{
+    mTrayIcon->showMessage("Hello", "World", QSystemTrayIcon::Information,
+                          10000);
+}
+void MainWindow::manualCheck()
+{
+    QMessageBox::information(0, "Yay",
+                             "It Woarx.\n");
+}
+
+void MainWindow::createActions()
+{
+    mCheckUpdates = new QAction(tr("Check for Updates"), this);
+    connect(mCheckUpdates, SIGNAL(triggered()), this, SLOT(manualCheck()));
+}
+
+void MainWindow::createTrayIcon()
+{
+    QIcon trayImg = QIcon(":/img/tray_22.png");
+
+    qDebug() << "Creating tray icon";
+    mTrayMenu = new QMenu(this);
+    mTrayMenu->addAction(mCheckUpdates);
+
+    mTrayIcon = new QSystemTrayIcon(this);
+    mTrayIcon->setContextMenu(mTrayMenu);
+
+    mTrayIcon->setIcon(trayImg);
+    setWindowIcon(trayImg);
+    mTrayIcon->show();
+    mTrayIcon->setToolTip(tr("m13ui"));
+    showMessage();
+}

http://wald.intevation.org/projects/trustbridge/