From cf0146050e4b4760ea9d606d11e30c19b6e3c3a0 Mon Sep 17 00:00:00 2001 From: chendapao Date: Sat, 16 Apr 2022 09:51:13 +0800 Subject: [PATCH] add global shortcut wakeup (#2097) * add global shortcut wakeup * del useless * add ann * upgrade git mod * add short text * update * Simplify logic and add QKeySequence non-null judgment. * Simplify logic. * Simplify logic. --- libs/QHotkey | 2 +- src/core/coreconfig.h | 1 + src/data/core/vnotex.json | 3 ++- src/widgets/mainwindow.cpp | 9 +++++++++ src/widgets/systemtrayhelper.cpp | 21 ++++++++++++++++----- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/libs/QHotkey b/libs/QHotkey index 79990520..18ac0110 160000 --- a/libs/QHotkey +++ b/libs/QHotkey @@ -1 +1 @@ -Subproject commit 7999052006382afbb8708bf73f877240ed8ad1e5 +Subproject commit 18ac011008d3ae55abc19233ba94fad1ea9801d8 diff --git a/src/core/coreconfig.h b/src/core/coreconfig.h index 2b4e9088..1f40720d 100644 --- a/src/core/coreconfig.h +++ b/src/core/coreconfig.h @@ -72,6 +72,7 @@ namespace vnotex Copy, Paste, Properties, + Global_WakeUp, MaxShortcut }; Q_ENUM(Shortcut) diff --git a/src/data/core/vnotex.json b/src/data/core/vnotex.json index 6c6d7619..e53cd52d 100644 --- a/src/data/core/vnotex.json +++ b/src/data/core/vnotex.json @@ -63,7 +63,8 @@ "UnitedEntry" : "Ctrl+G, G", "Copy" : "Ctrl+C", "Paste" : "Ctrl+V", - "Properties" : "F2" + "Properties" : "F2", + "Global_WakeUp" : "Ctrl+Alt+U" }, "file_type_suffixes" : [ { diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index ab9f1702..d297f93d 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "toolbox.h" #include "notebookexplorer.h" @@ -595,6 +596,14 @@ void MainWindow::closeOnQuit() void MainWindow::setupShortcuts() { + const auto &coreConfig = ConfigMgr::getInst().getCoreConfig(); + + // For cross-platform global shortcuts, the external library QHotkey is used. + QKeySequence wakeUp(coreConfig.getShortcut(CoreConfig::Global_WakeUp)); + if (!wakeUp.isEmpty()) { + auto qHotkey = new QHotkey(wakeUp, true, this); + connect(qHotkey , &QHotkey::activated, this, &MainWindow::showMainWindow); + } } void MainWindow::setStayOnTop(bool p_enabled) diff --git a/src/widgets/systemtrayhelper.cpp b/src/widgets/systemtrayhelper.cpp index 19df4bec..d8a8d7d4 100644 --- a/src/widgets/systemtrayhelper.cpp +++ b/src/widgets/systemtrayhelper.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include +#include #include "mainwindow.h" #include "widgetsfactory.h" @@ -35,11 +38,19 @@ QSystemTrayIcon *SystemTrayHelper::setupSystemTray(MainWindow *p_win) auto menu = WidgetsFactory::createMenu(p_win); trayIcon->setContextMenu(menu); - menu->addAction(MainWindow::tr("Show Main Window"), - menu, - [p_win]() { - p_win->showMainWindow(); - }); + const auto &coreConfig = ConfigMgr::getInst().getCoreConfig(); + + { + auto act = menu->addAction(MainWindow::tr("Show Main Window"), + menu, + [p_win]() { + p_win->showMainWindow(); + }); + + WidgetUtils::addActionShortcutText(act, coreConfig.getShortcut(CoreConfig::Global_WakeUp)); + } + + menu->addSeparator(); menu->addAction(MainWindow::tr("Quit"), menu,