diff --git a/libs/ui/widgets/kis_pressure_callibration_helper.cpp b/libs/ui/widgets/kis_pressure_callibration_helper.cpp index d4e35fbc61..90ec8f0d04 100644 --- a/libs/ui/widgets/kis_pressure_callibration_helper.cpp +++ b/libs/ui/widgets/kis_pressure_callibration_helper.cpp @@ -1,139 +1,125 @@ /* * Copyright (c) 2019 Wolthera van Hövell tot Westerflier * * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_pressure_callibration_helper.h" #include #include #include +#include KisPressureCallibrationHelper::KisPressureCallibrationHelper(QWidget *parent) : QWidget(parent), - m_highestValue(0.0), - m_lowestValue(1.0), - m_progress(WAITING) + m_callibrationTime(new QTimer(this)) { setMinimumHeight(256); + m_callibrationTime->setInterval(10000); + m_caption = "Please click to start callibrating tablet pressure."; + connect(m_callibrationTime, &QTimer::timeout, this, SIGNAL(callibrationDone())); } KisPressureCallibrationHelper::~KisPressureCallibrationHelper() { } QList KisPressureCallibrationHelper::callibrationInfo() { + QList callibrationInfo; + if (!m_callibrationInfo.isEmpty()) { - return m_callibrationInfo; + //return m_callibrationInfo; + } else { + //Dummyvalues to avoid crashes. + callibrationInfo.append(QPointF(0.0, 0.0)); + callibrationInfo.append(QPointF(0.5, 0.5)); + callibrationInfo.append(QPointF(1.0, 1.0)); } - QList dummy; - dummy.append(QPointF(0.0, 0.0)); - dummy.append(QPointF(0.5, 0.5)); - dummy.append(QPointF(1.0, 1.0)); - return dummy; + return callibrationInfo; } void KisPressureCallibrationHelper::paintEvent(QPaintEvent *e) { Q_UNUSED(e); const int w = width(); const int h = height(); QPainter p(this); p.fillRect(0, 0, w, h, QApplication::palette().background()); p.setBrush(QApplication::palette().foreground()); - QString text = QString(); - switch (m_progress) { - case WAITING: - text = "Please click to start callibrating tablet pressure."; - break; - case LIGHT_STROKE: - text = "Press as lightly as you can."; - break; - case MEDIUM_STROKE: - text = "Draw a medium stroke."; - break; - case HEAVY_STROKE: - text = "Press as hard as you hard."; - break; - case DONE: - text = "Done! Click me to start again."; - } + QString text = m_caption; int center = (w/2) - (this->fontMetrics().width(text)/2); QPoint o = QPoint(center, h/2); p.drawText(o, text); p.setBrush(Qt::transparent); p.setPen(QPen(QApplication::palette().foreground(), 2)); p.drawPolyline(m_currentPath); p.drawRect(0, 0, w, h); } void KisPressureCallibrationHelper::tabletEvent(QTabletEvent *e) { + m_callibrationInfo.append(e->pressure()); + if(e->type() == QEvent::TabletLeaveProximity) { + if (!m_callibrationTime->isActive()) { + m_caption = "Please click to start callibrating tablet pressure."; + } + } if(e->type() == QEvent::TabletRelease) { - if (m_progress == LIGHT_STROKE) { - m_callibrationInfo.append(QPointF(m_lowestValue, 0.0)); - } else if (m_progress == MEDIUM_STROKE) { - m_callibrationInfo.append(QPointF((m_lowestValue+m_highestValue)/2, 0.5)); - } else if (m_progress == HEAVY_STROKE) { - m_callibrationInfo.append(QPointF(m_highestValue, 1.0)); + m_currentPath.clear(); + if (m_callibrationTime->isActive()) { + UpdateCaption(); } else { - m_callibrationInfo.clear(); + m_caption = "Done! Click again to start over."; } - m_highestValue = 0.0; - m_lowestValue = 1.0; - nextSection(); return; } + if(e->type() == QEvent::TabletPress || e->type() == QEvent::TabletMove) { - if (e->pressure() > m_highestValue) { - m_highestValue = e->pressure(); - } - if (e->pressure() < m_lowestValue) { - m_lowestValue = e->pressure(); + if (!m_callibrationTime->isActive()) { + m_callibrationInfo.clear(); + m_callibrationTime->start(); } m_currentPath.append(e->pos()); repaint(); } - - } -void KisPressureCallibrationHelper::nextSection() +void KisPressureCallibrationHelper::UpdateCaption() { - m_currentPath.clear(); - switch (m_progress) { - case WAITING: - m_progress = LIGHT_STROKE; - break; - case LIGHT_STROKE: - m_progress = MEDIUM_STROKE; - break; - case MEDIUM_STROKE: - m_progress = HEAVY_STROKE; - break; - case HEAVY_STROKE: - m_progress = DONE; - emit(callibrationDone()); - break; - case DONE: - m_progress = LIGHT_STROKE; - break; + int random = QRandomGenerator::global()->bounded(0, 2); + while (random == m_oldCaption) { + random = QRandomGenerator::global()->bounded(0, 2); + } + + switch(random) { + case 1: { + m_caption = "Press as hard as you can."; + break; } - repaint(); + case 2: { + m_caption = "Draw a medium stroke."; + break; + } + default: { + m_caption = "Press as lightly as you can."; + } + } + + m_oldCaption = random; } diff --git a/libs/ui/widgets/kis_pressure_callibration_helper.h b/libs/ui/widgets/kis_pressure_callibration_helper.h index 792c1f1822..949b966019 100644 --- a/libs/ui/widgets/kis_pressure_callibration_helper.h +++ b/libs/ui/widgets/kis_pressure_callibration_helper.h @@ -1,71 +1,72 @@ /* * Copyright (c) 2019 Wolthera van Hövell tot Westerflier * * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_PRESSURE_CALLIBRATION_HELPER_H #define KIS_PRESSURE_CALLIBRATION_HELPER_H #include #include #include #include +#include /** * @brief The KisPressureCallibrationHelper class * This class helps users configure the tablet pressure. */ class KRITAUI_EXPORT KisPressureCallibrationHelper : public QWidget { Q_OBJECT public: explicit KisPressureCallibrationHelper(QWidget *parent = nullptr); ~KisPressureCallibrationHelper() override; /** * @brief callibrationInfo * @return QVector with values for lowest pressure, middle pressure and highest presure. */ QList callibrationInfo(); enum progressState { WAITING = 0, MEDIUM_STROKE, HEAVY_STROKE, LIGHT_STROKE, DONE }; Q_SIGNALS: void callibrationDone(); protected: void paintEvent(QPaintEvent *e) override; void tabletEvent(QTabletEvent *e) override; private: - void nextSection(); + void UpdateCaption(); - QList m_callibrationInfo; - qreal m_highestValue; - qreal m_lowestValue; - progressState m_progress; + QList m_callibrationInfo; QPolygon m_currentPath; + QTimer *m_callibrationTime; + QString m_caption; + int m_oldCaption; }; #endif /* KIS_PRESSURE_CALLIBRATION_HELPER_H */