diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-09-06 22:38:45 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-09-17 23:05:23 +0200 |
commit | cb54c16584cf3be746a1a536c1e37cb3022a2f1b (patch) | |
tree | 712a4ee8d6383918233654e1deeefb3e91371941 /examples/widgets/widgets/tablet/tabletcanvas.cpp | |
parent | 7db335a77e9efcfc8e0d4c1bd0834100403ec3b1 (diff) |
Cleanup QtWidgets (widgets) examples
Cleanup QtWidgets widgets examples:
- use member-init (clang-tidy)
- fix includes/don't include QtWidgets globally
- include own header first
- use nullptr (clang-tidy)
- avoid c-style casts
- use QVector instead QList
Change-Id: Ib56bb507eb2ef885f1ddc664050d3c7af92adb70
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/widgets/widgets/tablet/tabletcanvas.cpp')
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
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); |