Add local history for last screenshots

This commit is contained in:
Yuriy Puchkov
2020-07-16 16:36:15 +03:00
committed by Yuriy Puchkov
parent c84db1fa03
commit 5861b21fcf
14 changed files with 335 additions and 29 deletions

View File

@@ -22,14 +22,19 @@
#include "src/config/configwindow.h"
#include "src/widgets/capture/capturebutton.h"
#include "src/widgets/capturelauncher.h"
#include "src/widgets/notificationwidget.h"
#include "src/utils/systemnotification.h"
#include "src/utils/screengrabber.h"
#include "src/utils/history.h"
#include "src/utils/configenterprise.h"
#include "src/tools/historywidget.h"
#include <QFile>
#include <QApplication>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QDesktopWidget>
#include <QClipboard>
#ifdef Q_OS_WIN
#include "src/core/globalshortcutfilter.h"
@@ -171,6 +176,8 @@ void Controller::enableTrayIcon() {
if (m_trayIcon) {
return;
}
QMenu *trayIconMenu = new QMenu();
ConfigHandler().setDisabledTrayIcon(false);
QAction *captureAction = new QAction(tr("&Take Screenshot"), this);
connect(captureAction, &QAction::triggered, this, [this](){
@@ -180,6 +187,7 @@ void Controller::enableTrayIcon() {
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
connect(launcherAction, &QAction::triggered, this,
&Controller::openLauncherWindow);
QAction *configAction = new QAction(tr("&Configuration"), this);
connect(configAction, &QAction::triggered, this,
&Controller::openConfigWindow);
@@ -190,10 +198,16 @@ void Controller::enableTrayIcon() {
connect(quitAction, &QAction::triggered, qApp,
&QCoreApplication::quit);
QMenu *trayIconMenu = new QMenu();
// recent screenshots
QAction *recentAction = new QAction(tr("&Recent Screenshot"), this);
connect(recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
// generate menu
trayIconMenu->addAction(captureAction);
trayIconMenu->addAction(launcherAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(recentAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(configAction);
trayIconMenu->addAction(infoAction);
trayIconMenu->addSeparator();
@@ -239,6 +253,11 @@ void Controller::updateConfigComponents() {
}
}
void Controller::showRecentScreenshots() {
HistoryWidget *pHistory = new HistoryWidget();
pHistory->show();
}
void Controller::startFullscreenCapture(const uint id) {
bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));

View File

@@ -24,10 +24,17 @@
#include <QMap>
#include <QTimer>
#include <functional>
#include <QAction>
#include <QSpinBox>
#include <QLabel>
#include <QHBoxLayout>
#include <QWidgetAction>
class CaptureWidget;
class ConfigWindow;
class InfoWindow;
class QMenu;
class QSystemTrayIcon;
using lambda = std::function<void(void)>;
@@ -61,6 +68,8 @@ public slots:
void updateConfigComponents();
void showRecentScreenshots();
private slots:
void startFullscreenCapture(const uint id = 0);
void startVisualCapture(const uint id = 0,

View File

@@ -17,14 +17,20 @@
#include "globalshortcutfilter.h"
#include "src/core/controller.h"
#include "src/tools/historywidget.h"
#include <qt_windows.h>
#include <QDebug>
GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) :
QObject(parent)
{
// Forced Print Screen
if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) {
// ok
// ok - capture screen
}
if (RegisterHotKey(NULL, 2, MOD_SHIFT, VK_SNAPSHOT)) {
// ok - show screenshots history
}
}
@@ -38,13 +44,24 @@ bool GlobalShortcutFilter::nativeEventFilter(
MSG* msg = static_cast<MSG*>(message);
if (msg->message == WM_HOTKEY) {
//const quint32 keycode = HIWORD(msg->lParam);
//const quint32 modifiers = LOWORD(msg->lParam);
// TODO: this is just a temporal workwrround, proper global
// support would need custom shortcuts defined by the user.
Controller::getInstance()->requestCapture(
CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
const quint32 keycode = HIWORD(msg->lParam);
const quint32 modifiers = LOWORD(msg->lParam);
// Show screenshots history
if(VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
qDebug() << "Show screenshots history";
HistoryWidget *pHistory = new HistoryWidget();
pHistory->show();
}
// Capture screen
if(VK_SNAPSHOT == keycode && 0 == modifiers) {
Controller::getInstance()->requestCapture(
CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
}
return true;
}
return false;