From 009b6fb71a5e4596025964b5b6b680612c0250d8 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Wed, 11 Apr 2018 19:27:33 +0200 Subject: [PATCH] Systray: add Take Screenshot menu item --- src/core/controller.cpp | 14 ++++++++++++++ src/core/controller.h | 12 ++++++++++++ src/core/flameshotdbusadapter.cpp | 17 ----------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/core/controller.cpp b/src/core/controller.cpp index f40a9eef..cf8dce81 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -105,6 +105,11 @@ void Controller::enableTrayIcon() { return; } ConfigHandler().setDisabledTrayIcon(false); + QAction *captureAction = new QAction(tr("&Take Screenshot"), this); + connect(captureAction, &QAction::triggered, this, [this](){ + // Wait 400 ms to hide the QMenu + doLater(400, this, [this](){ this->createVisualCapture(); }); + }); QAction *configAction = new QAction(tr("&Configuration"), this); connect(configAction, &QAction::triggered, this, &Controller::openConfigWindow); @@ -116,6 +121,7 @@ void Controller::enableTrayIcon() { &QCoreApplication::quit); QMenu *trayIconMenu = new QMenu(); + trayIconMenu->addAction(captureAction); trayIconMenu->addAction(configAction); trayIconMenu->addAction(infoAction); trayIconMenu->addSeparator(); @@ -160,3 +166,11 @@ void Controller::updateConfigComponents() { m_configWindow->updateChildren(); } } + +void doLater(int msec, QObject *receiver, lambda func) { + QTimer *timer = new QTimer(receiver); + QObject::connect(timer, &QTimer::timeout, receiver, + [timer, func](){ func(); timer->deleteLater(); }); + timer->setInterval(msec); + timer->start(); +} diff --git a/src/core/controller.h b/src/core/controller.h index 317f7d7b..6b1948f2 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -26,6 +26,18 @@ class ConfigWindow; class InfoWindow; class QSystemTrayIcon; +//////////////////////////////////// +// TODO Separate later +#include +#include + +using lambda = std::function; + +// replace QTimer::singleShot introduced in QT 5.4 +// the actual target QT version is QT 5.3 +void doLater(int msec, QObject *receiver, lambda func); +//////////////////////////////////// + class Controller : public QObject { Q_OBJECT diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp index bcb98304..8e4afae6 100644 --- a/src/core/flameshotdbusadapter.cpp +++ b/src/core/flameshotdbusadapter.cpp @@ -21,25 +21,8 @@ #include "src/core/controller.h" #include "src/utils/screenshotsaver.h" #include "src/utils/systemnotification.h" -#include -#include #include -namespace { - using std::function; - using lambda = function; - - // replace QTimer::singleShot introduced in QT 5.4 - // the actual target QT version is QT 5.3 - void doLater(int msec, QObject *receiver, lambda func) { - QTimer *timer = new QTimer(receiver); - QObject::connect(timer, &QTimer::timeout, receiver, - [timer, func](){ func(); timer->deleteLater(); }); - timer->setInterval(msec); - timer->start(); - } -} - FlameshotDBusAdapter::FlameshotDBusAdapter(QObject *parent) : QDBusAbstractAdaptor(parent) {