Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_extended_modifiers_mapper.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
9
10#include <KisApplication.h>
11#include <QKeyEvent>
12
14
15#ifdef Q_OS_MACOS
16
18
19#endif /* Q_OS_MACOS */
20
21#ifdef Q_OS_WIN
22
23#include <windows.h>
24#include <commctrl.h>
25#include <winuser.h>
26
28#include "kis_config.h"
29
30
31QVector<Qt::Key> queryPressedKeysWin()
32{
33 QVector<Qt::Key> result;
34 BYTE vkeys[256];
35
36 KisConfig cfg(true);
37
38 const int maxFunctionKey = cfg.ignoreHighFunctionKeys() ? VK_F12 : VK_F24;
39
40 if (GetKeyboardState(vkeys)) {
41 for (int i = 0; i < 256; i++) {
42 if (vkeys[i] & 0x80) {
43 if (i == VK_SHIFT) {
44 result << Qt::Key_Shift;
45 } else if (i == VK_CONTROL) {
46 result << Qt::Key_Control;
47 } else if (i == VK_MENU) {
48 result << Qt::Key_Alt;
49 } else if (i == VK_LWIN || i == VK_RWIN) {
50 result << Qt::Key_Meta;
51 } else if (i == VK_SPACE) {
52 result << Qt::Key_Space;
53 } else if (i >= 0x30 && i <= 0x39) {
54 result << static_cast<Qt::Key>(Qt::Key_0 + i - 0x30);
55 } else if (i >= 0x41 && i <= 0x5A) {
56 result << static_cast<Qt::Key>(Qt::Key_A + i - 0x41);
57 } else if (i >= 0x60 && i <= 0x69) {
58 result << static_cast<Qt::Key>(Qt::Key_0 + i - 0x60);
59 } else if (i >= VK_F1 && i <= maxFunctionKey) {
60 result << static_cast<Qt::Key>(Qt::Key_F1 + i - VK_F1);
61 }
62 }
63 }
64 }
65
67
68 return result;
69}
70
71#endif /* Q_OS_WIN */
72
76
81
85
86#ifdef Q_OS_MACOS
87void KisExtendedModifiersMapper::setLocalMonitor(bool activate, KisShortcutMatcher *matcher)
88{
89 Q_UNUSED(matcher);
90 activateLocalMonitor(activate);
91}
92#endif
93
96{
98 static_cast<KisApplication*>(qApp)->extendedModifiersPluginInterface();
99
100 if (plugin) {
101 return plugin->queryExtendedModifiers();
102 }
103
104 ExtendedModifiers modifiers;
105
106#if defined Q_OS_WIN
107 modifiers = queryPressedKeysWin();
108#elif defined Q_OS_MACOS
109 modifiers = queryPressedKeysMac();
110#else
112#endif
113
114 return modifiers;
115}
116
118{
119 return QApplication::queryKeyboardModifiers();
120}
121
123{
124 Qt::Key key = (Qt::Key)keyEvent->key();
125
126 if (keyEvent->key() == Qt::Key_Meta &&
127 keyEvent->modifiers().testFlag(Qt::ShiftModifier)) {
128
129 key = Qt::Key_Alt;
130 }
131
132 return key;
133}
134
136{
137 ExtendedModifiers modifiers;
138
139 if (standardModifiers & Qt::ShiftModifier) {
140 modifiers << Qt::Key_Shift;
141 }
142
143 if (standardModifiers & Qt::ControlModifier) {
144 modifiers << Qt::Key_Control;
145 }
146
147 if (standardModifiers & Qt::AltModifier) {
148 modifiers << Qt::Key_Alt;
149 }
150
151 if (standardModifiers & Qt::MetaModifier) {
152 modifiers << Qt::Key_Meta;
153 }
154
155 return modifiers;
156};
Base class for the Krita app.
virtual ExtendedModifiers queryExtendedModifiers()=0
static ExtendedModifiers qtModifiersToQtKeys(Qt::KeyboardModifiers standardModifiers)
static Qt::Key workaroundShiftAltMetaHell(const QKeyEvent *keyEvent)
void activateLocalMonitor(bool activate)
QVector< Qt::Key > queryPressedKeysMac()
void makeContainerUnique(C &container)