diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt --- a/libs/ui/CMakeLists.txt +++ b/libs/ui/CMakeLists.txt @@ -421,6 +421,8 @@ canvas/kis_animation_player.cpp kis_animation_importer.cpp KisSyncedAudioPlayback.cpp + input/wintab/drawpile_tablettester/tablettester.cpp + input/wintab/drawpile_tablettester/tablettest.cpp ) if(UNIX) @@ -522,6 +524,7 @@ wdgsplash.ui input/wintab/kis_screen_size_choice_dialog.ui + input/wintab/drawpile_tablettester/tablettest.ui ) diff --git a/libs/ui/dialogs/kis_dlg_preferences.h b/libs/ui/dialogs/kis_dlg_preferences.h --- a/libs/ui/dialogs/kis_dlg_preferences.h +++ b/libs/ui/dialogs/kis_dlg_preferences.h @@ -195,6 +195,9 @@ public: TabletSettingsTab(QWidget *parent = 0, const char *name = 0); +private Q_SLOTS: + void slotTabletTest(); + public: void setDefault(); WdgTabletSettings *m_page; diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc --- a/libs/ui/dialogs/kis_dlg_preferences.cc +++ b/libs/ui/dialogs/kis_dlg_preferences.cc @@ -82,6 +82,7 @@ #include #include "input/config/kis_input_configuration_page.h" +#include "input/wintab/drawpile_tablettester/tablettester.h" #ifdef Q_OS_WIN # include @@ -663,6 +664,13 @@ #else m_page->grpTabletApi->setVisible(false); #endif + connect(m_page->btnTabletTest, SIGNAL(clicked()), SLOT(slotTabletTest())); +} + +void TabletSettingsTab::slotTabletTest() +{ + TabletTestDialog tabletTestDialog(this); + tabletTestDialog.exec(); } diff --git a/libs/ui/forms/wdgtabletsettings.ui b/libs/ui/forms/wdgtabletsettings.ui --- a/libs/ui/forms/wdgtabletsettings.ui +++ b/libs/ui/forms/wdgtabletsettings.ui @@ -7,7 +7,7 @@ 0 0 569 - 366 + 433 @@ -152,7 +152,7 @@ - + Qt::Vertical @@ -165,6 +165,13 @@ + + + + Open Tablet Tester... + + + diff --git a/libs/ui/input/wintab/drawpile_tablettester/README.md b/libs/ui/input/wintab/drawpile_tablettester/README.md new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/README.md @@ -0,0 +1,17 @@ +Notes on code originating from external source: + +Tablet Tester +============= + +Files are taken and possibly modified from the git repo of [Drawpile] on +commit bc06dceba83e8c758d25cfe81b986e18f38aae95. + +[Drawpile]: https://github.com/drawpile/Drawpile + +File | Original in repo of Drawpile +-------------------- | --- +tablettester.cpp | src/desktop/dialogs/tablettester.cpp +tablettester.h | src/desktop/dialogs/tablettester.h +tablettest.cpp | src/desktop/widgets/tablettest.cpp +tablettest.h | src/desktop/widgets/tablettest.h +tablettest.ui | src/desktop/ui/tablettest.ui diff --git a/libs/ui/input/wintab/drawpile_tablettester/tablettest.h b/libs/ui/input/wintab/drawpile_tablettester/tablettest.h new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/tablettest.h @@ -0,0 +1,51 @@ +/* + Drawpile - a collaborative drawing program. + + Copyright (C) 2017 Calle Laakkonen + + Drawpile is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Drawpile is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Drawpile. If not, see . +*/ + +#ifndef TABLETTEST_WIDGET_H +#define TABLETTEST_WIDGET_H + +#include + +class TabletTester : public QWidget { + Q_OBJECT +public: + TabletTester(QWidget *parent=nullptr); + +public Q_SLOTS: + void clear(); + +Q_SIGNALS: + void eventReport(const QString &msg); + +protected: + void paintEvent(QPaintEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void tabletEvent(QTabletEvent *e) override; + +private: + QPolygon m_mousePath; + QPolygon m_tabletPath; + + bool m_mouseDown; + bool m_tabletDown; +}; + +#endif diff --git a/libs/ui/input/wintab/drawpile_tablettester/tablettest.cpp b/libs/ui/input/wintab/drawpile_tablettester/tablettest.cpp new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/tablettest.cpp @@ -0,0 +1,131 @@ +/* + Drawpile - a collaborative drawing program. + + Copyright (C) 2017 Calle Laakkonen + + Drawpile is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Drawpile is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Drawpile. If not, see . +*/ + +#include "tablettest.h" + +#include +#include + +TabletTester::TabletTester(QWidget *parent) + : QWidget(parent), m_mouseDown(false), m_tabletDown(false) +{ +} + +void TabletTester::clear() +{ + m_mousePath.clear(); + m_tabletPath.clear(); + update(); +} + +void TabletTester::paintEvent(QPaintEvent *e) +{ + Q_UNUSED(e); + const int w = width(); + const int h = height(); + QPainter p(this); + p.fillRect(0, 0, w, h, QColor(200, 200, 200)); + p.setPen(QColor(128, 128, 128)); + + // Draw grid + for(int i=w/8;ix()).arg(e->y()).arg(e->button())); + m_mouseDown = true; + m_mousePath.clear(); + update(); +} + +void TabletTester::mouseMoveEvent(QMouseEvent *e) +{ + Q_EMIT eventReport(QString("Mouse move X=%1 Y=%2 B=%3").arg(e->x()).arg(e->y()).arg(e->buttons())); + m_mousePath << e->pos(); + update(); +} + +void TabletTester::mouseReleaseEvent(QMouseEvent *e) +{ + Q_UNUSED(e); + Q_EMIT eventReport(QString("Mouse release")); + m_mouseDown = false; +} + +void TabletTester::tabletEvent(QTabletEvent *e) +{ + e->accept(); + + QString msg; + switch(e->device()) { + case QTabletEvent::Stylus: msg = "Stylus"; break; + default: msg = QString("Device(%1)").arg(e->device()); break; + } + + switch(e->type()) { + case QEvent::TabletMove: + msg += " move"; + break; + case QEvent::TabletPress: + msg += " press"; + m_tabletPath.clear(); + m_tabletDown = true; + break; + case QEvent::TabletRelease: + msg += " release"; + m_tabletDown = false; + break; + default: + msg += QString(" event-%1").arg(e->type()); + break; + } + + msg += QString(" X=%1 Y=%2 B=%3 P=%4%") + .arg(e->posF().x(), 0, 'f', 2) + .arg(e->posF().y(), 0, 'f', 2) + .arg(e->buttons()) + .arg(e->pressure()*100, 0, 'f', 1) + ; + + if(e->type() == QEvent::TabletMove) { + if(m_tabletDown) { + msg += " (DRAW)"; + m_tabletPath << e->pos(); + update(); + } else { + msg += " (HOVER)"; + } + } + + Q_EMIT eventReport(msg); +} diff --git a/libs/ui/input/wintab/drawpile_tablettester/tablettest.ui b/libs/ui/input/wintab/drawpile_tablettester/tablettest.ui new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/tablettest.ui @@ -0,0 +1,99 @@ + + + TabletTest + + + + 0 + 0 + 730 + 385 + + + + Tablet Tester + + + + + + + + + + + true + + + + + + + Clear + + + + + + + + + + TabletTester + QWidget +
input/wintab/drawpile_tablettester/tablettest.h
+ 1 +
+
+ + + + pushButton + clicked() + logView + clear() + + + 722 + 377 + + + 659 + 84 + + + + + pushButton + clicked() + tablettest + clear() + + + 419 + 359 + + + 142 + 242 + + + + + tablettest + eventReport(QString) + logView + appendPlainText(QString) + + + 287 + 187 + + + 546 + 207 + + + + +
diff --git a/libs/ui/input/wintab/drawpile_tablettester/tablettester.h b/libs/ui/input/wintab/drawpile_tablettester/tablettester.h new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/tablettester.h @@ -0,0 +1,39 @@ +/* + Drawpile - a collaborative drawing program. + + Copyright (C) 2017 Calle Laakkonen + + Drawpile is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Drawpile is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Drawpile. If not, see . +*/ +#ifndef TABLETTESTDIALOG_H +#define TABLETTESTDIALOG_H + +#include + +class Ui_TabletTest; + +class TabletTestDialog : public QDialog +{ + Q_OBJECT +public: + TabletTestDialog(QWidget *parent=nullptr); + ~TabletTestDialog(); + bool eventFilter(QObject *watched, QEvent *event) override; + +private: + Ui_TabletTest *m_ui; + +}; + +#endif diff --git a/libs/ui/input/wintab/drawpile_tablettester/tablettester.cpp b/libs/ui/input/wintab/drawpile_tablettester/tablettester.cpp new file mode 100644 --- /dev/null +++ b/libs/ui/input/wintab/drawpile_tablettester/tablettester.cpp @@ -0,0 +1,63 @@ +/* + Drawpile - a collaborative drawing program. + + Copyright (C) 2017 Calle Laakkonen + + Drawpile is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Drawpile is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Drawpile. If not, see . +*/ + +#include "tablettester.h" +#include "tablettest.h" +#include "ui_tablettest.h" + +TabletTestDialog::TabletTestDialog( QWidget *parent) : + QDialog(parent, Qt::Window) +{ + m_ui = new Ui_TabletTest; + m_ui->setupUi(this); + + qApp->installEventFilter(this); +} + +TabletTestDialog::~TabletTestDialog() +{ + qApp->removeEventFilter(this); + delete m_ui; +} + +bool TabletTestDialog::eventFilter(QObject *watched, QEvent *e) { + Q_UNUSED(watched); + if(e->type() == QEvent::TabletEnterProximity || e->type() == QEvent::TabletLeaveProximity) { + QTabletEvent *te = static_cast(e); + bool isEraser = te->pointerType() == QTabletEvent::Eraser; + bool isNear = e->type() == QEvent::TabletEnterProximity; + QString msg; + if(isEraser) { + if (isNear) { + msg = QStringLiteral("Eraser brought near"); + } else { + msg = QStringLiteral("Eraser taken away"); + } + } else { + if (isNear) { + msg = QStringLiteral("Pen tip brought near"); + } else { + msg = QStringLiteral("Pen tip taken away"); + } + } + + m_ui->logView->appendPlainText(msg); + } + return QDialog::eventFilter(watched, e); +}