Changeset View
Changeset View
Standalone View
Standalone View
src/util/kmodifierkeyinfoprovider.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | Lesser General Public License for more details. | 15 | Lesser General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "kmodifierkeyinfoprovider_p.h" | 21 | #include "kmodifierkeyinfoprovider_p.h" | ||
22 | 22 | | |||
23 | KModifierKeyInfoProvider::KModifierKeyInfoProvider() | ||||
24 | : QObject(nullptr) | ||||
25 | { | ||||
26 | } | ||||
27 | | ||||
28 | KModifierKeyInfoProvider::~KModifierKeyInfoProvider() | ||||
29 | { | ||||
30 | } | ||||
31 | | ||||
32 | bool KModifierKeyInfoProvider::setKeyLatched(Qt::Key key, bool latched) | ||||
33 | { | ||||
34 | Q_UNUSED(key); | ||||
35 | Q_UNUSED(latched); | ||||
36 | return false; | ||||
37 | } | ||||
38 | | ||||
39 | bool KModifierKeyInfoProvider::setKeyLocked(Qt::Key key, bool locked) | ||||
40 | { | ||||
41 | Q_UNUSED(key); | ||||
42 | Q_UNUSED(locked); | ||||
43 | return false; | ||||
44 | } | ||||
45 | | ||||
23 | bool KModifierKeyInfoProvider::isKeyPressed(Qt::Key key) const | 46 | bool KModifierKeyInfoProvider::isKeyPressed(Qt::Key key) const | ||
24 | { | 47 | { | ||
25 | if (m_modifierStates.contains(key)) { | 48 | if (m_modifierStates.contains(key)) { | ||
26 | return m_modifierStates[key] & Pressed; | 49 | return m_modifierStates[key] & Pressed; | ||
27 | } | 50 | } | ||
28 | return false; | 51 | return false; | ||
29 | } | 52 | } | ||
30 | 53 | | |||
Show All 26 Lines | 79 | { | |||
57 | return m_modifierStates.contains(key); | 80 | return m_modifierStates.contains(key); | ||
58 | } | 81 | } | ||
59 | 82 | | |||
60 | const QList<Qt::Key> KModifierKeyInfoProvider::knownKeys() const | 83 | const QList<Qt::Key> KModifierKeyInfoProvider::knownKeys() const | ||
61 | { | 84 | { | ||
62 | return m_modifierStates.keys(); | 85 | return m_modifierStates.keys(); | ||
63 | } | 86 | } | ||
64 | 87 | | |||
65 | #include "moc_kmodifierkeyinfoprovider_p.cpp" | 88 | void KModifierKeyInfoProvider::stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates newState) | ||
89 | { | ||||
90 | auto &state = m_modifierStates[key]; | ||||
zzag: Abuse of `auto`. | |||||
Calling this an "abuse" is very arguable, see https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/ dfaure: Calling this an "abuse" is very arguable, see https://herbsutter.com/2013/08/12/gotw-94… | |||||
There is a Qt recommendation though: https://wiki.qt.io/Coding_Conventions#auto_Keyword alexeymin: There is a Qt recommendation though: https://wiki.qt.io/Coding_Conventions#auto_Keyword | |||||
91 | if (newState != state) { | ||||
92 | const auto difference = (newState ^ state); | ||||
zzag: Same here. | |||||
93 | state = newState; | ||||
94 | if (difference & Pressed) { | ||||
95 | emit keyPressed(key, newState & Pressed); | ||||
96 | } | ||||
97 | if (difference & Latched) { | ||||
98 | emit keyLatched(key, newState & Latched); | ||||
99 | } | ||||
100 | if (difference & Locked) { | ||||
101 | emit keyLocked(key, newState & Locked); | ||||
102 | } | ||||
103 | } | ||||
104 | } |
Abuse of auto.