ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvModalShortcut.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #ifndef ecvModalShortcut_h
9 #define ecvModalShortcut_h
10 
11 // Local
12 #include "CV_db.h"
13 
14 // Qt
15 #include <QKeySequence>
16 #include <QObject>
17 #include <QPointer>
18 
19 class QAction;
20 class QShortcut;
21 class QWidget;
22 
43 class CV_DB_LIB_API ecvModalShortcut : public QObject {
44  Q_OBJECT
45 
46 public:
47  using Superclass = QObject;
48  ~ecvModalShortcut() override;
49 
58  void setContextWidget(QWidget* contextWidget,
59  Qt::ShortcutContext contextArea = Qt::WindowShortcut);
60 
64  bool isEnabled() const;
65 
72  void setEnabled(bool shouldEnable, bool changeFocus = true);
73 
77  QKeySequence keySequence() const;
78 
79 Q_SIGNALS:
89  void enabled();
90 
97  void disabled();
98 
104  void unregister();
105 
109  void activated();
110 
111 protected:
112  friend class ecvKeySequences;
113 
117  ecvModalShortcut(const QKeySequence& key,
118  QAction* action = nullptr,
119  QWidget* parent = nullptr);
120 
121  QKeySequence m_key;
122  QPointer<QShortcut> m_shortcut;
123  QPointer<QAction> m_action;
124 };
125 
126 #endif // ecvModalShortcut_h
#define CV_DB_LIB_API
Definition: CV_db.h:15
Manage key sequences used for shortcuts.
Manage an action and/or widget's responsivity to a shortcut.
void setEnabled(bool shouldEnable, bool changeFocus=true)
ecvModalShortcut(const QKeySequence &key, QAction *action=nullptr, QWidget *parent=nullptr)
QPointer< QAction > m_action
~ecvModalShortcut() override
QPointer< QShortcut > m_shortcut
QKeySequence m_key
bool isEnabled() const
void setContextWidget(QWidget *contextWidget, Qt::ShortcutContext contextArea=Qt::WindowShortcut)
QKeySequence keySequence() const