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 all commits
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
17 changes: 12 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,20 @@ 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("Flameshot must be restarted for changes to take effect.");
}
QLabel* infoBottom = new QLabel(msg);
infoBottom->setMargin(10);
infoBottom->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoBottom);
Expand Down
3 changes: 2 additions & 1 deletion src/config/setshortcutwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ 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
11 changes: 5 additions & 6 deletions src/config/shortcutswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ 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 +190,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
9 changes: 4 additions & 5 deletions src/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,19 @@ Controller::Controller()
currentScreen->grabWindow(QApplication::desktop()->winId(), 0, 0, 1, 1);

// set global shortcuts for MacOS
m_HotkeyScreenshotCapture =
new QHotkey(QKeySequence("Ctrl+Alt+Shift+4"), true, this);
m_HotkeyScreenshotCapture = 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);
m_HotkeyScreenshotHistory = 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