Krita Source Code Documentation
Loading...
Searching...
No Matches
tablettester.cpp
Go to the documentation of this file.
1/*
2 Drawpile - a collaborative drawing program.
3
4 SPDX-FileCopyrightText: 2017 Calle Laakkonen
5
6 SPDX-License-Identifier: GPL-3.0-or-later
7*/
8
9#include "tablettester.h"
10#include "tablettest.h"
11#include "ui_tablettest.h"
12
13#include <QTabletEvent>
14
16 : KoDialog(parent, Qt::Dialog)
17{
18 setCaption(i18n("Tablet Tester"));
19 QWidget *page = new QWidget(this);
20 m_ui = new Ui_TabletTest;
21 m_ui->setupUi(page);
22 setMainWidget(page);
24 qApp->installEventFilter(this);
25 // Hack to work around extreme lag w/ S Pen on Android. Unless the focus is set on the tablet tester itself, pen input will appear to lag.
26 m_ui->tablettest->setFocus();
27
28 m_ui->logView->appendPlainText(
29 "## Legend:\n"
30 "# X,Y - event coordinate\n"
31 "# B - buttons pressed\n"
32 "# P - pressure\n"
33 "# TX,TY - tilt\n"
34 "# S - speed\n"
35 "\n");
36}
37
39{
40 qApp->removeEventFilter(this);
41 delete m_ui;
42}
43
44bool TabletTestDialog::eventFilter(QObject *watched, QEvent *e) {
45 Q_UNUSED(watched);
46 if(e->type() == QEvent::TabletEnterProximity || e->type() == QEvent::TabletLeaveProximity) {
47 QTabletEvent *te = static_cast<QTabletEvent*>(e);
48#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
49 bool isEraser = te->pointerType() == QTabletEvent::Eraser;
50#else
51 bool isEraser = te->pointingDevice()->pointerType() == QPointingDevice::PointerType::Eraser;
52#endif
53
54 bool isNear = e->type() == QEvent::TabletEnterProximity;
55 QString msg;
56 if(isEraser) {
57 if (isNear) {
58 msg = QStringLiteral("Eraser brought near");
59 } else {
60 msg = QStringLiteral("Eraser taken away");
61 }
62 } else {
63 if (isNear) {
64 msg = QStringLiteral("Pen tip brought near");
65 } else {
66 msg = QStringLiteral("Pen tip taken away");
67 }
68 }
69
70 m_ui->logView->appendPlainText(msg);
71 }
72 return QDialog::eventFilter(watched, e);
73}
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
@ Close
Show Close-button. (this button closes the dialog)
Definition KoDialog.h:131
Ui_TabletTest * m_ui
TabletTestDialog(QWidget *parent=nullptr)
bool eventFilter(QObject *watched, QEvent *event) override