Skip to content

Commit

Permalink
Merge pull request #40 from namecheap/feature/RND-600-flameshot-custo…
Browse files Browse the repository at this point in the history
…m-hotkeys-for-tools

Add configurable shortcuts for drawing tools
  • Loading branch information
panpuchkov authored Sep 15, 2020
2 parents 2834084 + d061290 commit 513bae7
Show file tree
Hide file tree
Showing 40 changed files with 4,725 additions and 1,149 deletions.
6 changes: 6 additions & 0 deletions flameshot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ DEFINES += QAPPLICATION_CLASS=QApplication

SOURCES += src/main.cpp \
src/config/filepathconfiguration.cpp \
src/config/setshortcutwidget.cpp \
src/config/shortcutswidget.cpp \
src/tools/imgs3/imgs3settings.cpp \
src/utils/configshortcuts.cpp \
src/widgets/historywidget.cpp \
src/utils/configenterprise.cpp \
src/utils/history.cpp \
Expand Down Expand Up @@ -165,7 +168,10 @@ SOURCES += src/main.cpp \

HEADERS += src/widgets/capture/buttonhandler.h \
src/config/filepathconfiguration.h \
src/config/setshortcutwidget.h \
src/config/shortcutswidget.h \
src/tools/imgs3/imgs3settings.h \
src/utils/configshortcuts.h \
src/widgets/historywidget.h \
src/utils/configenterprise.h \
src/utils/history.h \
Expand Down
5 changes: 5 additions & 0 deletions graphics.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@
<file>img/material/white/circle-outline.svg</file>
<file>img/material/white/blur.svg</file>
<file>img/material/white/arrow-bottom-left.svg</file>
<file>img/app/keyboard.svg</file>
<file>img/material/black/shortcut.svg</file>
<file>img/material/white/shortcut.svg</file>
<file>img/material/black/filepath.svg</file>
<file>img/material/white/filepath.svg</file>
</qresource>
</RCC>
1,427 changes: 1,427 additions & 0 deletions img/app/keyboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions img/material/black/filepath.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/material/black/shortcut.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions img/material/white/filepath.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions img/material/white/shortcut.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 11 additions & 5 deletions src/config/configwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "src/config/geneneralconf.h"
#include "src/config/filenameeditor.h"
#include "src/config/filepathconfiguration.h"
#include "src/config/shortcutswidget.h"
#include "src/config/strftimechooserwidget.h"
#include "src/config/visualseditor.h"
#include "src/utils/globalvalues.h"
Expand Down Expand Up @@ -67,16 +68,21 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
addTab(m_filenameEditor, QIcon(modifier + "name_edition.svg"),
tr("Filename Editor"));

// filepath
m_filePathConfiguration = new FilePathConfiguration();
addTab(m_filePathConfiguration, QIcon(modifier + "name_edition.svg"),
tr("Path Default"));

// general
m_generalConfig = new GeneneralConf();
addTab(m_generalConfig, QIcon(modifier + "config.svg"),
tr("General"));

// shortcuts
m_shortcuts = new ShortcutsWidget();
addTab(m_shortcuts, QIcon(modifier + "shortcut.svg"),
tr("Shortcuts"));

// filepath
m_filePathConfiguration = new FilePathConfiguration();
addTab(m_filePathConfiguration, QIcon(modifier + "filepath.svg"),
tr("Path Default"));

// connect update sigslots
connect(this, &ConfigWindow::updateChildren,
m_filenameEditor, &FileNameEditor::updateComponents);
Expand Down
2 changes: 2 additions & 0 deletions src/config/configwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class FileNameEditor;
class FilePathConfiguration;
class ShortcutsWidget;
class GeneneralConf;
class QFileSystemWatcher;
class VisualsEditor;
Expand All @@ -39,6 +40,7 @@ class ConfigWindow : public QTabWidget {
private:
FileNameEditor *m_filenameEditor;
FilePathConfiguration *m_filePathConfiguration;
ShortcutsWidget *m_shortcuts;
GeneneralConf *m_generalConfig;
VisualsEditor *m_visuals;
QFileSystemWatcher *m_configWatcher;
Expand Down
59 changes: 59 additions & 0 deletions src/config/setshortcutwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "setshortcutwidget.h"
#include <QKeyEvent>
#include <QLayout>
#include <QLabel>
#include <QIcon>
#include <QPixmap>

SetShortcutDialog::SetShortcutDialog(QDialog *parent) : QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("Set Shortcut"));
m_ks = QKeySequence();

m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignHCenter);

QLabel *infoTop = new QLabel(tr("Enter new shortcut to change "));
infoTop->setMargin(10);
infoTop->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoTop);

QLabel *infoIcon = new QLabel();
infoIcon->setAlignment(Qt::AlignCenter);
infoIcon->setPixmap(QPixmap(":/img/app/keyboard.svg"));
m_layout->addWidget(infoIcon);

m_layout->addWidget(infoIcon);

QLabel *infoBottom = new QLabel(tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
infoBottom->setMargin(10);
infoBottom->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoBottom);
}

const QKeySequence& SetShortcutDialog::shortcut() {
return m_ks;
}

void SetShortcutDialog::keyPressEvent(QKeyEvent *ke) {
if (ke->modifiers() & Qt::ShiftModifier)
m_modifier += "Shift+";
if (ke->modifiers() & Qt::ControlModifier)
m_modifier += "Ctrl+";
if (ke->modifiers() & Qt::AltModifier)
m_modifier += "Alt+";
if (ke->modifiers() & Qt::MetaModifier)
m_modifier += "Meta+";

QString key = QKeySequence(ke->key()).toString();
m_ks = QKeySequence(m_modifier + key);
}

void SetShortcutDialog::keyReleaseEvent(QKeyEvent *event) {
if (m_ks == QKeySequence(Qt::Key_Escape)) {
reject();
}
accept();
}
30 changes: 30 additions & 0 deletions src/config/setshortcutwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef SETSHORTCUTWIDGET_H
#define SETSHORTCUTWIDGET_H

#include <QObject>
#include <QDialog>
#include <QKeySequence>

class QVBoxLayout;


class SetShortcutDialog : public QDialog
{
Q_OBJECT
public:
explicit SetShortcutDialog(QDialog *parent = nullptr);
const QKeySequence& shortcut();

public:
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *event);

signals:

private:
QVBoxLayout *m_layout;
QString m_modifier;
QKeySequence m_ks;
};

#endif // SETSHORTCUTWIDGET_H
Loading

0 comments on commit 513bae7

Please sign in to comment.