Skip to content

Commit c5f7398

Browse files
authored
Show keyboard shortcut in the tray icon menu (flameshot-org#4258)
* Show keyboard shortcut in the tray icon menu * add the guard for macOS-specific shortcut
1 parent d76013f commit c5f7398

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/widgets/trayicon.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ TrayIcon::TrayIcon(QObject* parent)
8585
connect(ConfigHandler::getInstance(),
8686
&ConfigHandler::fileChanged,
8787
this,
88-
[this]() {});
88+
[this]() { updateCaptureActionShortcut(); });
8989
}
9090

9191
TrayIcon::~TrayIcon()
@@ -104,8 +104,11 @@ void TrayIcon::initMenu()
104104
{
105105
m_menu = new QMenu();
106106

107-
auto* captureAction = new QAction(tr("&Take Screenshot"), this);
108-
connect(captureAction, &QAction::triggered, this, [this]() {
107+
m_captureAction = new QAction(tr("&Take Screenshot"), this);
108+
109+
updateCaptureActionShortcut();
110+
111+
connect(m_captureAction, &QAction::triggered, this, [this]() {
109112
#if defined(Q_OS_MACOS)
110113
auto currentMacOsVersion = QOperatingSystemVersion::current();
111114
if (currentMacOsVersion >= QOperatingSystemVersion::MacOSBigSur) {
@@ -170,7 +173,7 @@ void TrayIcon::initMenu()
170173
Flameshot::instance(),
171174
&Flameshot::openSavePath);
172175

173-
m_menu->addAction(captureAction);
176+
m_menu->addAction(m_captureAction);
174177
m_menu->addAction(launcherAction);
175178
m_menu->addSeparator();
176179
#ifdef ENABLE_IMGUR
@@ -188,6 +191,18 @@ void TrayIcon::initMenu()
188191
m_menu->addAction(quitAction);
189192
}
190193

194+
void TrayIcon::updateCaptureActionShortcut()
195+
{
196+
#if defined(Q_OS_MACOS)
197+
if (!m_captureAction) {
198+
return;
199+
}
200+
201+
QString shortcut = ConfigHandler().shortcut("TAKE_SCREENSHOT");
202+
m_captureAction->setShortcut(QKeySequence(shortcut));
203+
#endif
204+
}
205+
191206
#if !defined(DISABLE_UPDATE_CHECKER)
192207
void TrayIcon::enableCheckUpdatesAction(bool enable)
193208
{

src/widgets/trayicon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class TrayIcon : public QSystemTrayIcon
1818
private:
1919
void initTrayIcon();
2020
void initMenu();
21+
void updateCaptureActionShortcut();
2122
#if !defined(DISABLE_UPDATE_CHECKER)
2223
void enableCheckUpdatesAction(bool enable);
2324
#endif
2425

2526
void startGuiCapture();
2627

2728
QMenu* m_menu;
29+
QAction* m_captureAction;
2830
#if !defined(DISABLE_UPDATE_CHECKER)
2931
QAction* m_appUpdates;
3032
#endif

0 commit comments

Comments
 (0)