diff options
Diffstat (limited to 'Slimber/Qt/QtMenulet.h')
-rw-r--r-- | Slimber/Qt/QtMenulet.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Slimber/Qt/QtMenulet.h b/Slimber/Qt/QtMenulet.h new file mode 100644 index 0000000..4ac9140 --- /dev/null +++ b/Slimber/Qt/QtMenulet.h @@ -0,0 +1,65 @@ +#pragma once + +#include <QCoreApplication> +#include <QMenu> +#include <QString> +#include <QSystemTrayIcon> +#include <QObject> +#include <QPixmap> + +#include "Slimber/Menulet.h" + +class QtMenulet : public QObject, public Menulet { + Q_OBJECT + public: + QtMenulet() { + trayIcon.setIcon(QPixmap(":/icons/UsersOffline.png")); + trayIcon.setContextMenu(&menu); + trayIcon.show(); + } + + void clear() { + menu.clear(); + } + + void addItem(const Swift::String& name, const Swift::String& icon) { + menu.addAction(getIcon(icon), QString::fromUtf8(name.getUTF8Data())); + } + + void addAboutItem() { + menu.addAction("About"); + } + + void addRestartItem() { + menu.addAction("Restart", this, SLOT(restart())); + } + + void addExitItem() { + menu.addAction("Exit", qApp, SLOT(quit())); + } + + void addSeparator() { + menu.addSeparator(); + } + + void setIcon(const Swift::String& icon) { + trayIcon.setIcon(getIcon(icon)); + } + + private: + QPixmap getIcon(const Swift::String& name) { + return QPixmap(":/icons/" + QString::fromUtf8(name.getUTF8Data()) + ".png"); + } + + private slots: + void showAboutDialog() { + } + + void restart() { + onRestartClicked(); + } + + private: + QMenu menu; + QSystemTrayIcon trayIcon; +}; |