Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Screenshot & Screenshot history shortcut changing in MACOS #2098

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable Screenshot & Screenshot history shortcut changing in MACOS
From issue #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
commit da69d01e5bc3a8cc71671a9bab6d5ef2d0416d78
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(
borgmanJeremy marked this conversation as resolved.
Show resolved Hide resolved
"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");
borgmanJeremy marked this conversation as resolved.
Show resolved Hide resolved
}
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 = "");
borgmanJeremy marked this conversation as resolved.
Show resolved Hide resolved
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