Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tablet_debugger.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QEvent>
10#include <QMessageBox>
11#include <QApplication>
12
13#include <kis_debug.h>
14#include <kis_config.h>
15#include <KisPortingUtils.h>
16
17#include <QGlobalStatic>
18
19#include <klocalizedstring.h>
20
22
23
24inline QString button(const QWheelEvent &ev) {
25 Q_UNUSED(ev);
26 return "-";
27}
28
29template <class T>
30QString button(const T &ev) {
31 return QString::number(ev.button());
32}
33
34template <class T>
35QString buttons(const T &ev) {
36 return QString::number(ev.buttons());
37}
38
39template <class Event>
40 void dumpBaseParams(QTextStream &s, const Event &ev, const QString &prefix)
41{
42 s << qSetFieldWidth(5) << Qt::left << prefix << Qt::reset << " ";
43 s << qSetFieldWidth(17) << Qt::left << KisTabletDebugger::exTypeToString(ev.type()) << Qt::reset;
44}
45
46template <class Event>
47 void dumpMouseRelatedParams(QTextStream &s, const Event &ev)
48{
49 s << "btn: " << button(ev) << " ";
50 s << "btns: " << buttons(ev) << " ";
51 s << "pos: " << qSetFieldWidth(4) << ev.x() << qSetFieldWidth(0) << "," << qSetFieldWidth(4) << ev.y() << qSetFieldWidth(0) << " ";
52 s << "gpos: " << qSetFieldWidth(4) << ev.globalX() << qSetFieldWidth(0) << "," << qSetFieldWidth(4) << ev.globalY() << qSetFieldWidth(0) << " ";
53}
54
55template <>
56 void dumpMouseRelatedParams(QTextStream &s, const QWheelEvent &ev)
57{
58 s << "btn: " << button(ev) << " ";
59 s << "btns: " << buttons(ev) << " ";
60 s << "pos: " << qSetFieldWidth(4) << ev.position().x() << qSetFieldWidth(0) << "," << qSetFieldWidth(4) << ev.position().y() << qSetFieldWidth(0) << " ";
61 s << "gpos: " << qSetFieldWidth(4) << ev.globalPosition().x() << qSetFieldWidth(0) << "," << qSetFieldWidth(4) << ev.globalPosition().y() << qSetFieldWidth(0) << " ";
62}
63
64QString KisTabletDebugger::exTypeToString(QEvent::Type type) {
65 return
66 type == QEvent::TabletEnterProximity ? "TabletEnterProximity" :
67 type == QEvent::TabletLeaveProximity ? "TabletLeaveProximity" :
68 type == QEvent::Enter ? "Enter" :
69 type == QEvent::Leave ? "Leave" :
70 type == QEvent::FocusIn ? "FocusIn" :
71 type == QEvent::FocusOut ? "FocusOut" :
72 type == QEvent::Wheel ? "Wheel" :
73 type == QEvent::KeyPress ? "KeyPress" :
74 type == QEvent::KeyRelease ? "KeyRelease" :
75 type == QEvent::ShortcutOverride ? "ShortcutOverride" :
76 type == QMouseEvent::MouseButtonPress ? "MouseButtonPress" :
77 type == QMouseEvent::MouseButtonRelease ? "MouseButtonRelease" :
78 type == QMouseEvent::MouseButtonDblClick ? "MouseButtonDblClick" :
79 type == QMouseEvent::MouseMove ? "MouseMove" :
80 type == QTabletEvent::TabletMove ? "TabletMove" :
81 type == QTabletEvent::TabletPress ? "TabletPress" :
82 type == QTabletEvent::TabletRelease ? "TabletRelease" :
83 type == QTouchEvent::TouchBegin ? "TouchBegin" :
84 type == QTouchEvent::TouchUpdate ? "TouchUpdate" :
85 type == QTouchEvent::TouchEnd ? "TouchEnd" :
86 type == QTouchEvent::TouchCancel ? "TouchCancel" :
87 "unknown";
88}
89
90
92 : m_debugEnabled(false)
93{
94 KisConfig cfg(true);
96}
97
99{
100 return s_instance;
101}
102
104{
106 QMessageBox::information(qApp->activeWindow(), i18nc("@title:window", "Krita"), m_debugEnabled ?
107 i18n("Tablet Event Logging Enabled") :
108 i18n("Tablet Event Logging Disabled"));
109 if (m_debugEnabled) {
110 dbgTablet << "vvvvvvvvvvvvvvvvvvvvvvv START TABLET EVENT LOG vvvvvvvvvvvvvvvvvvvvvvv";
111 }
112 else {
113 dbgTablet << "^^^^^^^^^^^^^^^^^^^^^^^ END TABLET EVENT LOG ^^^^^^^^^^^^^^^^^^^^^^^";
114 }
115}
116
118{
119 return m_debugEnabled;
120}
121
123{
124 // FIXME: make configurable!
125 return true;
126}
127
129{
130 // FIXME: make configurable!
131 return m_debugEnabled;
132}
133
138
139QString KisTabletDebugger::eventToString(const QMouseEvent &ev, const QString &prefix)
140{
141 QString string;
142 QTextStream s(&string);
143
144 dumpBaseParams(s, ev, prefix);
146 s << "hires: " << qSetFieldWidth(8) << ev.screenPos().x() << qSetFieldWidth(0) << "," << qSetFieldWidth(8) << ev.screenPos().y() << qSetFieldWidth(0) << " ";
147 s << "Source:" << ev.source();
148
149 return string;
150}
151
152QString KisTabletDebugger::eventToString(const QKeyEvent &ev, const QString &prefix)
153{
154 QString string;
155 QTextStream s(&string);
157
158 dumpBaseParams(s, ev, prefix);
159
160 s << "key: 0x" << Qt::hex << ev.key() << Qt::reset << " ";
161 s << "mod: 0x" << Qt::hex << ev.modifiers() << Qt::reset << " ";
162 s << "text: " << (ev.text().isEmpty() ? "none" : ev.text()) << " ";
163 s << "autorepeat: " << bool(ev.isAutoRepeat());
164
165 return string;
166}
167
168QString KisTabletDebugger::eventToString(const QWheelEvent &ev, const QString &prefix)
169{
170 QString string;
171 QTextStream s(&string);
173
174 dumpBaseParams(s, ev, prefix);
176
177 s << "delta: x: " << ev.angleDelta().x() << " y: " << ev.angleDelta().y() << " ";
178
179 return string;
180}
181
182QString KisTabletDebugger::eventToString(const QTouchEvent &ev, const QString &prefix)
183{
184 QString string;
185 QTextStream s(&string);
187
188 dumpBaseParams(s, ev, prefix);
189#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
190 s << (ev.device()->type() ? "TouchPad" : "TouchScreen") << " ";
191#else
192 if (ev.deviceType() == QInputDevice::DeviceType::TouchPad) {
193 s << "Touchpad";
194 }
195 else if (ev.deviceType() == QInputDevice::DeviceType::TouchScreen) {
196 s << "TouchScreen";
197 }
198 s << " ";
199#endif
200 for (const auto& touchpoint: ev.touchPoints()) {
201 s << "id: " << touchpoint.id() << " ";
202 s << "hires: " << qSetFieldWidth(8) << touchpoint.screenPos().x() << qSetFieldWidth(0) << "," << qSetFieldWidth(8) << touchpoint.screenPos().y() << qSetFieldWidth(0) << " ";
203 s << "prs: " << touchpoint.pressure() << " ";
204 s << "rot: "<< touchpoint.rotation() << " ";
205 s << "state: 0x" << Qt::hex << touchpoint.state() << "; ";
206 s << Qt::dec;
207 }
208
209 return string;
210}
211
212QString KisTabletDebugger::eventToString(const QEvent &ev, const QString &prefix)
213{
214 QString string;
215 QTextStream s(&string);
217
218 dumpBaseParams(s, ev, prefix);
219
220 return string;
221}
222
223template <class Event>
224 QString tabletEventToString(const Event &ev, const QString &prefix)
225{
226 QString string;
227 QTextStream s(&string);
229
230 dumpBaseParams(s, ev, prefix);
232
233 s << "hires: " << qSetFieldWidth(8) << ev.globalPosF().x() << qSetFieldWidth(0) << "," << qSetFieldWidth(8) << ev.globalPosF().y() << qSetFieldWidth(0) << " ";
234 s << "prs: " << qSetFieldWidth(4) << Qt::fixed << ev.pressure() << Qt::reset << " ";
235
236
239
240 s << "id: " << ev.uniqueId() << " ";
241
242 s << "xTilt: " << ev.xTilt() << " ";
243 s << "yTilt: " << ev.yTilt() << " ";
244 s << "rot: " << ev.rotation() << " ";
245 s << "z: " << ev.z() << " ";
246 s << "tp: " << ev.tangentialPressure() << " ";
247
248 return string;
249}
250
251QString KisTabletDebugger::eventToString(const QTabletEvent &ev, const QString &prefix)
252{
253 return tabletEventToString(ev, prefix);
254}
255
256QString KisTabletDebugger::tabletDeviceToString(const QTabletEvent &event)
257{
258#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
259 return
260 event.deviceType() == QTabletEvent::NoDevice ? "NoDevice" :
261 event.deviceType() == QTabletEvent::Puck ? "Puck" :
262 event.deviceType() == QTabletEvent::Stylus ? "Stylus" :
263 event.deviceType() == QTabletEvent::Airbrush ? "Airbrush" :
264 event.deviceType() == QTabletEvent::FourDMouse ? "FourDMouse" :
265 event.deviceType() == QTabletEvent::XFreeEraser ? "XFreeEraser" :
266 event.deviceType() == QTabletEvent::RotationStylus ? "RotationStylus" :
267 "Unknown";
268#else
269 QInputDevice::DeviceType deviceType = event.deviceType();
270
271 return
272 deviceType == QInputDevice::DeviceType::Puck ? "Puck" :
273 deviceType == QInputDevice::DeviceType::Stylus ? "Stylus" :
274 deviceType == QInputDevice::DeviceType::Airbrush ? "Airbrush" :
275 "Unknown";
276#endif
277}
278
279QString KisTabletDebugger::pointerTypeToString(const QTabletEvent &event) {
280#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
281 return
282 event.pointerType() == QTabletEvent::UnknownPointer ? "UnknownPointer" :
283 event.pointerType() == QTabletEvent::Pen ? "Pen" :
284 event.pointerType() == QTabletEvent::Cursor ? "Cursor" :
285 event.pointerType() == QTabletEvent::Eraser ? "Eraser" :
286 "Unknown";
287#else
288 QPointingDevice::PointerType pointerType = event.pointerType();
289 return
290 pointerType == QPointingDevice::PointerType::Pen ? "Pen" :
291 pointerType == QPointingDevice::PointerType::Cursor ? "Cursor" :
292 pointerType == QPointingDevice::PointerType::Eraser ? "Eraser" :
293 "Unknown";
294#endif
295
296}
297
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
bool shouldEatDriverShortcuts(bool defaultValue=false) const
QString eventToString(const QMouseEvent &ev, const QString &prefix)
static KisTabletDebugger * instance()
static QString pointerTypeToString(const QTabletEvent &event)
static QString tabletDeviceToString(const QTabletEvent &event)
static QString exTypeToString(QEvent::Type type)
bool initializationDebugEnabled() const
bool shouldEatDriverShortcuts() const
bool debugRawTabletValues() const
#define dbgTablet
Definition kis_debug.h:59
QString tabletEventToString(const Event &ev, const QString &prefix)
void dumpBaseParams(QTextStream &s, const Event &ev, const QString &prefix)
QString button(const QWheelEvent &ev)
void dumpMouseRelatedParams(QTextStream &s, const Event &ev)
QString buttons(const T &ev)
void setUtf8OnStream(QTextStream &stream)