1 /***************************************************************************
2     qgsconfigureshortcutsdialog.h
3     -----------------------------
4     begin                : May 2009
5     copyright            : (C) 2009 by Martin Dobias
6     email                : wonder dot sk at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSCONFIGURESHORTCUTSDIALOG_H
17 #define QGSCONFIGURESHORTCUTSDIALOG_H
18 
19 #include <QDialog>
20 #include "qgis_sip.h"
21 
22 #include "ui_qgsconfigureshortcutsdialog.h"
23 #include "qgshelp.h"
24 #include "qgis_gui.h"
25 
26 class QShortcut;
27 class QgsShortcutsManager;
28 
29 /**
30  * \ingroup gui
31  * \class QgsConfigureShortcutsDialog
32  * \brief Reusable dialog for allowing users to configure shortcuts contained in a QgsShortcutsManager.
33  * \since QGIS 2.16
34  */
35 
36 class GUI_EXPORT QgsConfigureShortcutsDialog : public QDialog, private Ui::QgsConfigureShortcutsDialog
37 {
38     Q_OBJECT
39 
40   public:
41 
42     /**
43      * Constructor for QgsConfigureShortcutsDialog.
44      * \param parent parent widget
45      * \param manager associated QgsShortcutsManager, or leave as NULLPTR to use the default
46      * singleton QgsShortcutsManager instance.
47      */
48     QgsConfigureShortcutsDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsShortcutsManager *manager = nullptr );
49 
50   protected:
51     void keyPressEvent( QKeyEvent *event ) override;
52     void keyReleaseEvent( QKeyEvent *event ) override;
53 
54   private slots:
55     void changeShortcut();
56     void resetShortcut();
57     void setNoShortcut();
58     void saveShortcuts();
59     void loadShortcuts();
60     void mLeFilter_textChanged( const QString &text );
61 
62     void actionChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous );
63 
64     //! Open the associated help
65     void showHelp();
66 
67   private:
68 
69     //! Populates the dialog with all actions from the manager
70     void populateActions();
71 
72     //! Returns the currently selected shortcut object (QAction or QShortcut)
73     QObject *currentObject();
74 
75     //! Returns the currently selected action, or NULLPTR if no action selected
76     QAction *currentAction();
77 
78     //! Returns the currently selected QShortcut, or NULLPTR if no shortcut selected
79     QShortcut *currentShortcut();
80 
81     void setGettingShortcut( bool getting );
82     void setCurrentActionShortcut( const QKeySequence &s );
83     void updateShortcutText();
84 
85     QgsShortcutsManager *mManager = nullptr;
86 
87     bool mGettingShortcut = false;
88     int mModifiers = 0, mKey = 0;
89 
90 };
91 
92 #endif //QGSCONFIGURESHORTCUTSDIALOG_H
93