BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
shortcutcatcher.h
1 /******************************************************************************
2 Copyright (c) 2010, Artem Galichkin <doomer3d@gmail.com>
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the <organization> nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
28 
29 #ifndef SHORTCUTCATCHER_H
30 #define SHORTCUTCATCHER_H
31 
32 #include <QWidget>
33 
34 
35 class QHBoxLayout;
36 class QToolButton;
37 class ShortcutButton;
38 
39 /// \brief Represents extra widget for changing single keyboard shortcut.
40 /// \ingroup keyboard-shortcuts
41 class ShortcutCatcher : public QWidget {
42  Q_OBJECT
43 
44  friend class ShortcutButton;
45  friend class DynamicShortcutsWidget;
46 
47  public:
48  /// \brief Constructor.
49  /// \param parent Pointer to parent widget.
50  explicit ShortcutCatcher(QWidget *parent = 0);
51  virtual ~ShortcutCatcher();
52 
53  /// \brief Performs time-dependent check of current shortcut check and stops
54  /// the recording if time is up.
56 
57  /// \brief Updates text displayed in catcher according to active shortcut.
58  void updateDisplayShortcut();
59 
60  /// \brief Access to active shortcut.
61  /// \return Returns active shortcut.
62  inline QKeySequence shortcut() const {
63  return m_currentSequence;
64  }
65 
66  /// \brief Sets default shortcut for the widget.
67  /// \param key Shortcut to set.
68  inline void setDefaultShortcut(const QKeySequence &key) {
69  m_defaultSequence = key;
70  setShortcut(key);
71  }
72 
73  /// \brief Sets active shortcut for the widget.
74  /// \param key Shortcut to set.
75  inline void setShortcut(const QKeySequence &key) {
76  m_currentSequence = key;
77  doneRecording();
78  }
79 
80  public slots:
81  /// \brief Resets active shortcut to default shortcut.
82  inline void resetShortcut() {
83  setShortcut(m_defaultSequence);
84  }
85 
86  /// \brief Clears current active shortcut.
87  inline void clearShortcut() {
88  setShortcut(QKeySequence());
89  }
90 
91  protected slots:
92  void startRecording();
93  void doneRecording();
94 
95  signals:
96  void shortcutChanged(const QKeySequence &seguence);
97 
98  private:
99  QToolButton *m_btnReset;
100  QToolButton *m_btnClear;
101  ShortcutButton *m_btnChange;
102  QHBoxLayout *m_layout;
103 
104  QKeySequence m_currentSequence;
105  QKeySequence m_defaultSequence;
106 
107  bool m_isRecording;
108  int m_numKey;
109  uint m_modifierKeys;
110 };
111 
112 #endif // KEYSEQUENCECATCHER_H
Widget for displaying and editing shortcuts.
ShortcutCatcher(QWidget *parent=0)
Constructor.
void updateDisplayShortcut()
Updates text displayed in catcher according to active shortcut.
void setDefaultShortcut(const QKeySequence &key)
Sets default shortcut for the widget.
void resetShortcut()
Resets active shortcut to default shortcut.
QKeySequence shortcut() const
Access to active shortcut.
void setShortcut(const QKeySequence &key)
Sets active shortcut for the widget.
void clearShortcut()
Clears current active shortcut.
Represents single button for changing keyboard shortcut.
Represents extra widget for changing single keyboard shortcut.
void controlModifierlessTimeout()
Performs time-dependent check of current shortcut check and stops the recording if time is up...