summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-21 16:36:06 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-21 16:36:06 +0300
commita45582585d706f379b69e96759a6ae4b915e4598 (patch)
treeded3378a7a91ef929523cc44bf17581d8d8a97a8 /include
parentSnappy sidebar (diff)
downloadnheko-a45582585d706f379b69e96759a6ae4b915e4598.tar.xz
Minimize to tray
Diffstat (limited to 'include')
-rw-r--r--include/ChatPage.h1
-rw-r--r--include/MainWindow.h10
-rw-r--r--include/TrayIcon.h58
3 files changed, 69 insertions, 0 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h

index 7e8bc9e9..12eaf6b7 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h
@@ -44,6 +44,7 @@ public: signals: void close(); void changeWindowTitle(const QString &msg); + void unreadMessages(int count); private slots: void showUnreadMessageNotification(int count); diff --git a/include/MainWindow.h b/include/MainWindow.h
index ae8d1648..a58cc668 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h
@@ -27,6 +27,7 @@ #include "OverlayModal.h" #include "RegisterPage.h" #include "SlidingStackWidget.h" +#include "TrayIcon.h" #include "WelcomePage.h" class MainWindow : public QMainWindow @@ -37,7 +38,13 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +protected: + void closeEvent(QCloseEvent *event); + private slots: + // Handle interaction with the tray icon. + void iconActivated(QSystemTrayIcon::ActivationReason reason); + // Show the welcome page in the main window. void showWelcomePage(); @@ -74,4 +81,7 @@ private: // Matrix Client API provider. QSharedPointer<MatrixClient> client_; + + // Tray icon that shows the unread message count. + TrayIcon *trayIcon_; }; diff --git a/include/TrayIcon.h b/include/TrayIcon.h new file mode 100644
index 00000000..bef8564f --- /dev/null +++ b/include/TrayIcon.h
@@ -0,0 +1,58 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <QAction> +#include <QIcon> +#include <QIconEngine> +#include <QMenu> +#include <QPainter> +#include <QRect> +#include <QSystemTrayIcon> + +class MsgCountComposedIcon : public QIconEngine +{ +public: + MsgCountComposedIcon(const QString &filename); + + virtual void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state); + virtual QIconEngine *clone() const; + + int msgCount = 0; + +private: + const int BubbleDiameter = 15; + + QIcon icon_; +}; + +class TrayIcon : public QSystemTrayIcon +{ + Q_OBJECT +public: + TrayIcon(const QString &filename, QWidget *parent); + +public slots: + void setUnreadCount(int count); + +private: + QAction *viewAction_; + QAction *quitAction_; + + MsgCountComposedIcon *icon_; +};