swift
keyboardkey.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_INPUT_KEYBOARDKEY_H
7 #define SWIFT_MISC_INPUT_KEYBOARDKEY_H
8 
9 #include <QList>
10 #include <QMetaType>
11 #include <QString>
12 
13 #include "misc/input/keycodes.h"
14 #include "misc/metaclass.h"
15 #include "misc/propertyindexref.h"
16 #include "misc/swiftmiscexport.h"
17 #include "misc/valueobject.h"
18 
19 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::input, CKeyboardKey)
20 
21 namespace swift::misc::input
22 {
24  class SWIFT_MISC_EXPORT CKeyboardKey : public CValueObject<CKeyboardKey>
25  {
26  public:
29  {
30  IndexKey = CPropertyIndexRef::GlobalIndexCKeyboardKey,
31  IndexKeyAsString,
32  IndexKeyObject, // just for updates
33  };
34 
36  CKeyboardKey();
37 
40 
42  KeyCode getKey() const { return m_keyCode; }
43 
45  QString getKeyAsString() const;
46 
48  void setKey(KeyCode key) { m_keyCode = key; }
49 
51  void setKey(int key) { m_keyCode = static_cast<KeyCode>(key); }
52 
54  void setKey(char key) { m_keyCode = static_cast<KeyCode>(key); }
55 
57  bool isUnknown() const { return !this->hasKey(); }
58 
60  bool isModifier() const { return allModifiers().contains(m_keyCode); }
61 
63  bool hasKey() const { return !(m_keyCode == KeyCode::Key_Unknown); }
64 
66  void setKeyObject(CKeyboardKey key);
67 
69  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
70 
72  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
73 
75  QString convertToQString(bool i18n = false) const;
76 
77  private:
78  static const QList<KeyCode> &allModifiers();
79 
80  KeyCode m_keyCode;
81 
84  SWIFT_METAMEMBER(keyCode));
85  };
86 } // namespace swift::misc::input
87 
88 Q_DECLARE_METATYPE(swift::misc::input::CKeyboardKey)
89 
90 #endif // SWIFT_MISC_INPUT_KEYBOARDKEY_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object representing a keyboard key.
Definition: keyboardkey.h:25
void setKey(int key)
Set key code.
Definition: keyboardkey.h:51
bool isUnknown() const
Is unknown?
Definition: keyboardkey.h:57
bool isModifier() const
Modifier?
Definition: keyboardkey.h:60
void setKey(char key)
Set key code.
Definition: keyboardkey.h:54
void setKey(KeyCode key)
Set key code.
Definition: keyboardkey.h:48
KeyCode getKey() const
Get key code.
Definition: keyboardkey.h:42
ColumnIndex
Properties by index.
Definition: keyboardkey.h:29
bool hasKey() const
with key?
Definition: keyboardkey.h:63
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
KeyCode
Key code http://www.kbdlayout.info/.
Definition: keycodes.h:16
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65