Skip to content

Commit

Permalink
Enable Screenshot & Screenshot history shortcut changing in MACOS
Browse files Browse the repository at this point in the history
From issue flameshot-org#1259 and my experience, I've fix and test this feature in my Hackintosh. So now you can change shortcut to take screenshot and show screenshot history (require restart flameshot).
- Default key to take screenshot is "Cmd + Shift + X", screenshot history is "Option + Shift + X".
- Added new translate text "Require restart flameshot".
  • Loading branch information
adrienpixodeo committed Nov 20, 2021
1 parent 53cc11a commit da69d01
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/config/setshortcutwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QLayout>
#include <QPixmap>

SetShortcutDialog::SetShortcutDialog(QDialog* parent)
SetShortcutDialog::SetShortcutDialog(QDialog* parent, QString shortcutName)
: QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
Expand All @@ -32,13 +32,16 @@ SetShortcutDialog::SetShortcutDialog(QDialog* parent)

m_layout->addWidget(infoIcon);

QString msg = "";
#if defined(Q_OS_MAC)
QLabel* infoBottom = new QLabel(tr(
"Press Esc to cancel or ⌘+Backspace to disable the keyboard shortcut."));
msg = tr("Press Esc to cancel or ⌘+Backspace to disable the keyboard shortcut.");
#else
QLabel* infoBottom = new QLabel(
tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
msg = tr("Press Esc to cancel or Backspace to disable the keyboard shortcut.");
#endif
if (shortcutName == "TAKE_SCREENSHOT" || shortcutName == "SCREENSHOT_HISTORY"){
msg += "\n" + tr("Require restart flameshot");
}
QLabel* infoBottom = new QLabel(msg);
infoBottom->setMargin(10);
infoBottom->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoBottom);
Expand Down
2 changes: 1 addition & 1 deletion src/config/setshortcutwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SetShortcutDialog : public QDialog
{
Q_OBJECT
public:
explicit SetShortcutDialog(QDialog* parent = nullptr);
explicit SetShortcutDialog(QDialog* parent = nullptr, QString shortcutName = "");
const QKeySequence& shortcut();

public:
Expand Down
10 changes: 4 additions & 6 deletions src/config/shortcutswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ void ShortcutsWidget::onShortcutCellClicked(int row, int col)
return;
}

SetShortcutDialog* setShortcutDialog = new SetShortcutDialog();
QString shortcutName = m_shortcuts.at(row).at(0);
SetShortcutDialog* setShortcutDialog = new SetShortcutDialog(nullptr, shortcutName);
if (0 != setShortcutDialog->exec()) {
QString shortcutName = m_shortcuts.at(row).at(0);
QKeySequence shortcutValue = setShortcutDialog->shortcut();

// set no shortcut is Backspace
Expand Down Expand Up @@ -189,10 +189,8 @@ void ShortcutsWidget::loadShortcuts()

// Global hotkeys
#if defined(Q_OS_MACOS)
m_shortcuts << (QStringList()
<< "" << QObject::tr("Screenshot history") << "⇧⌘⌥H");
m_shortcuts << (QStringList()
<< "" << QObject::tr("Capture screen") << "⇧⌘⌥4");
appendShortcut("TAKE_SCREENSHOT", "Capture screen");
appendShortcut("SCREENSHOT_HISTORY", "Screenshot history");
#elif defined(Q_OS_WIN)
m_shortcuts << (QStringList() << "" << QObject::tr("Screenshot history")
<< "Shift+Print Screen");
Expand Down
5 changes: 2 additions & 3 deletions src/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ Controller::Controller()

// set global shortcuts for MacOS
m_HotkeyScreenshotCapture =
new QHotkey(QKeySequence("Ctrl+Alt+Shift+4"), true, this);
new QHotkey(QKeySequence(ConfigHandler().shortcut("TAKE_SCREENSHOT")), true, this);
QObject::connect(m_HotkeyScreenshotCapture,
&QHotkey::activated,
qApp,
[&]() { this->startVisualCapture(); });
m_HotkeyScreenshotHistory =
new QHotkey(QKeySequence("Ctrl+Alt+Shift+H"), true, this);
new QHotkey(QKeySequence(ConfigHandler().shortcut("SCREENSHOT_HISTORY")), true, this);
QObject::connect(m_HotkeyScreenshotHistory,
&QHotkey::activated,
qApp,
[&]() { this->showRecentUploads(); });
#endif

if (ConfigHandler().checkForUpdates()) {
getLatestAvailableVersion();
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
SHORTCUT("TYPE_COMMIT_CURRENT_TOOL" , "Ctrl+Return" ),
#if defined(Q_OS_MACOS)
SHORTCUT("TYPE_DELETE_CURRENT_TOOL" , "Backspace" ),
SHORTCUT("TAKE_SCREENSHOT" , "Ctrl+Shift+X" ),
SHORTCUT("SCREENSHOT_HISTORY" , "Alt+Shift+X" ),
#else
SHORTCUT("TYPE_DELETE_CURRENT_TOOL" , "Delete" ),
#endif
Expand Down

0 comments on commit da69d01

Please sign in to comment.