diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-14 17:46:16 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-14 17:46:34 +0200 |
commit | 440286655e0ca271506cf7cc02ad0dbf4baef9ca (patch) | |
tree | 896fa81adb8b14a69355a3a6cf64d06ec8173c9a /examples/widgets/widgets/tablet | |
parent | 1e27ad1697187549151657ba187928e439300db7 (diff) | |
parent | e164d61ca8263fc4b46fdd916e1ea77c7dd2b735 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I4a78428a8ea273b6960792e3b8043f816fa37fcf
Diffstat (limited to 'examples/widgets/widgets/tablet')
-rw-r--r-- | examples/widgets/widgets/tablet/main.cpp | 2 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/mainwindow.cpp | 11 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/mainwindow.h | 2 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletapplication.cpp | 2 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.cpp | 29 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.h | 25 |
6 files changed, 33 insertions, 38 deletions
diff --git a/examples/widgets/widgets/tablet/main.cpp b/examples/widgets/widgets/tablet/main.cpp index 5726e79166..0fec526de0 100644 --- a/examples/widgets/widgets/tablet/main.cpp +++ b/examples/widgets/widgets/tablet/main.cpp @@ -48,8 +48,6 @@ ** ****************************************************************************/ -#include <QtWidgets> - #include "mainwindow.h" #include "tabletapplication.h" #include "tabletcanvas.h" diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp index a048119533..8bcb9ada63 100644 --- a/examples/widgets/widgets/tablet/mainwindow.cpp +++ b/examples/widgets/widgets/tablet/mainwindow.cpp @@ -48,14 +48,19 @@ ** ****************************************************************************/ -#include <QtWidgets> - #include "mainwindow.h" #include "tabletcanvas.h" +#include <QApplication> +#include <QColorDialog> +#include <QDir> +#include <QFileDialog> +#include <QMenuBar> +#include <QMessageBox> + //! [0] MainWindow::MainWindow(TabletCanvas *canvas) - : m_canvas(canvas), m_colorDialog(nullptr) + : m_canvas(canvas) { createMenus(); setWindowTitle(tr("Tablet Example")); diff --git a/examples/widgets/widgets/tablet/mainwindow.h b/examples/widgets/widgets/tablet/mainwindow.h index 4be28784b5..3ea9af7ccf 100644 --- a/examples/widgets/widgets/tablet/mainwindow.h +++ b/examples/widgets/widgets/tablet/mainwindow.h @@ -81,7 +81,7 @@ private: void createMenus(); TabletCanvas *m_canvas; - QColorDialog *m_colorDialog; + QColorDialog *m_colorDialog = nullptr; }; //! [0] diff --git a/examples/widgets/widgets/tablet/tabletapplication.cpp b/examples/widgets/widgets/tablet/tabletapplication.cpp index 37be018276..a27491a86c 100644 --- a/examples/widgets/widgets/tablet/tabletapplication.cpp +++ b/examples/widgets/widgets/tablet/tabletapplication.cpp @@ -50,8 +50,6 @@ #include "tabletapplication.h" -#include <QtWidgets> - //! [0] bool TabletApplication::event(QEvent *event) { diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp index dc56702142..9a8029486d 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.cpp +++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp @@ -48,21 +48,16 @@ ** ****************************************************************************/ -#include <QtWidgets> -#include <math.h> - #include "tabletcanvas.h" +#include <QCoreApplication> +#include <QPainter> +#include <QtMath> + //! [0] TabletCanvas::TabletCanvas() - : QWidget(nullptr) - , m_alphaChannelValuator(TangentialPressureValuator) - , m_colorSaturationValuator(NoValuator) - , m_lineWidthValuator(PressureValuator) - , m_color(Qt::red) - , m_brush(m_color) - , m_pen(m_brush, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) - , m_deviceDown(false) + : QWidget(nullptr), m_brush(m_color) + , m_pen(m_brush, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) { resize(500, 500); setAutoFillBackground(true); @@ -138,7 +133,7 @@ void TabletCanvas::tabletEvent(QTabletEvent *event) void TabletCanvas::initPixmap() { qreal dpr = devicePixelRatioF(); - QPixmap newPixmap = QPixmap(width() * dpr, height() * dpr); + QPixmap newPixmap = QPixmap(qRound(width() * dpr), qRound(height() * dpr)); newPixmap.setDevicePixelRatio(dpr); newPixmap.fill(Qt::white); QPainter painter(&newPixmap); @@ -208,7 +203,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event) const QString error(tr("This input device is not supported by the example.")); #if QT_CONFIG(statustip) QStatusTipEvent status(error); - QApplication::sendEvent(this, &status); + QCoreApplication::sendEvent(this, &status); #else qWarning() << error; #endif @@ -219,7 +214,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event) const QString error(tr("Unknown tablet device - treating as stylus")); #if QT_CONFIG(statustip) QStatusTipEvent status(error); - QApplication::sendEvent(this, &status); + QCoreApplication::sendEvent(this, &status); #else qWarning() << error; #endif @@ -261,7 +256,8 @@ void TabletCanvas::updateBrush(const QTabletEvent *event) m_color.setAlpha(255); break; case TiltValuator: - m_color.setAlpha(maximum(abs(vValue - 127), abs(hValue - 127))); + m_color.setAlpha(std::max(std::abs(vValue - 127), + std::abs(hValue - 127))); break; default: m_color.setAlpha(255); @@ -288,7 +284,8 @@ void TabletCanvas::updateBrush(const QTabletEvent *event) m_pen.setWidthF(pressureToWidth(event->pressure())); break; case TiltValuator: - m_pen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12); + m_pen.setWidthF(std::max(std::abs(vValue - 127), + std::abs(hValue - 127)) / 12); break; default: m_pen.setWidthF(1); diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h index c63ef76893..4c10731b0f 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.h +++ b/examples/widgets/widgets/tablet/tabletcanvas.h @@ -51,14 +51,13 @@ #ifndef TABLETCANVAS_H #define TABLETCANVAS_H -#include <QWidget> -#include <QPixmap> -#include <QPoint> -#include <QTabletEvent> -#include <QColor> #include <QBrush> +#include <QColor> #include <QPen> +#include <QPixmap> #include <QPoint> +#include <QTabletEvent> +#include <QWidget> QT_BEGIN_NAMESPACE class QPaintEvent; @@ -92,8 +91,6 @@ public: { return m_color; } void setTabletDevice(QTabletEvent *event) { updateCursor(event); } - int maximum(int a, int b) - { return a > b ? a : b; } protected: void tabletEvent(QTabletEvent *event) override; @@ -108,19 +105,19 @@ private: void updateBrush(const QTabletEvent *event); void updateCursor(const QTabletEvent *event); - Valuator m_alphaChannelValuator; - Valuator m_colorSaturationValuator; - Valuator m_lineWidthValuator; - QColor m_color; + Valuator m_alphaChannelValuator = TangentialPressureValuator; + Valuator m_colorSaturationValuator = NoValuator; + Valuator m_lineWidthValuator = PressureValuator; + QColor m_color = Qt::red; QPixmap m_pixmap; QBrush m_brush; QPen m_pen; - bool m_deviceDown; + bool m_deviceDown = false; struct Point { QPointF pos; - qreal pressure; - qreal rotation; + qreal pressure = 0; + qreal rotation = 0; } lastPoint; }; //! [0] |