mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Enable Screenshot & Screenshot history shortcut changing in MACOS (#2098)
* 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". * - Change message text for screenshot shortcut * - Format code using clang-format Co-authored-by: adrienpixodeo <adrien@pixodeo.net>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <QLayout>
|
||||
#include <QPixmap>
|
||||
|
||||
SetShortcutDialog::SetShortcutDialog(QDialog* parent)
|
||||
SetShortcutDialog::SetShortcutDialog(QDialog* parent, QString shortcutName)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
@@ -32,13 +32,20 @@ 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("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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user