diff options
Diffstat (limited to 'examples/widgets/widgets/tablet/tabletcanvas.cpp')
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp index dc56702142..59ca608cef 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.cpp +++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp @@ -48,21 +48,17 @@ ** ****************************************************************************/ -#include <QtWidgets> -#include <math.h> - #include "tabletcanvas.h" +#include <QCoreApplication> +#include <QPainter> +#include <QtMath> +#include <cstdlib> + //! [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 +134,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 +204,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 +215,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 +257,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 +285,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); |