diff options
-rw-r--r-- | examples/widgets/widgets/tablet/images.qrc | 8 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/images/cursor-airbrush.png | bin | 0 -> 823 bytes | |||
-rw-r--r-- | examples/widgets/widgets/tablet/images/cursor-eraser.png | bin | 0 -> 1454 bytes | |||
-rw-r--r-- | examples/widgets/widgets/tablet/images/cursor-felt-marker.png | bin | 0 -> 513 bytes | |||
-rw-r--r-- | examples/widgets/widgets/tablet/images/cursor-pencil.png | bin | 0 -> 1307 bytes | |||
-rw-r--r-- | examples/widgets/widgets/tablet/tablet.pro | 11 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletapplication.cpp | 3 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.cpp | 44 | ||||
-rw-r--r-- | examples/widgets/widgets/tablet/tabletcanvas.h | 7 |
9 files changed, 62 insertions, 11 deletions
diff --git a/examples/widgets/widgets/tablet/images.qrc b/examples/widgets/widgets/tablet/images.qrc new file mode 100644 index 0000000000..eb3eabbace --- /dev/null +++ b/examples/widgets/widgets/tablet/images.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource> + <file>images/cursor-airbrush.png</file> + <file>images/cursor-eraser.png</file> + <file>images/cursor-felt-marker.png</file> + <file>images/cursor-pencil.png</file> + </qresource> +</RCC> diff --git a/examples/widgets/widgets/tablet/images/cursor-airbrush.png b/examples/widgets/widgets/tablet/images/cursor-airbrush.png Binary files differnew file mode 100644 index 0000000000..bea756ed6f --- /dev/null +++ b/examples/widgets/widgets/tablet/images/cursor-airbrush.png diff --git a/examples/widgets/widgets/tablet/images/cursor-eraser.png b/examples/widgets/widgets/tablet/images/cursor-eraser.png Binary files differnew file mode 100644 index 0000000000..e5488a89f2 --- /dev/null +++ b/examples/widgets/widgets/tablet/images/cursor-eraser.png diff --git a/examples/widgets/widgets/tablet/images/cursor-felt-marker.png b/examples/widgets/widgets/tablet/images/cursor-felt-marker.png Binary files differnew file mode 100644 index 0000000000..132f09aa39 --- /dev/null +++ b/examples/widgets/widgets/tablet/images/cursor-felt-marker.png diff --git a/examples/widgets/widgets/tablet/images/cursor-pencil.png b/examples/widgets/widgets/tablet/images/cursor-pencil.png Binary files differnew file mode 100644 index 0000000000..cc2f447d02 --- /dev/null +++ b/examples/widgets/widgets/tablet/images/cursor-pencil.png diff --git a/examples/widgets/widgets/tablet/tablet.pro b/examples/widgets/widgets/tablet/tablet.pro index de81e7b198..9b8927f483 100644 --- a/examples/widgets/widgets/tablet/tablet.pro +++ b/examples/widgets/widgets/tablet/tablet.pro @@ -1,12 +1,13 @@ QT += widgets HEADERS = mainwindow.h \ - tabletcanvas.h \ - tabletapplication.h + tabletcanvas.h \ + tabletapplication.h SOURCES = mainwindow.cpp \ - main.cpp \ - tabletcanvas.cpp \ - tabletapplication.cpp + main.cpp \ + tabletcanvas.cpp \ + tabletapplication.cpp +RESOURCES += images.qrc # install target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/tablet diff --git a/examples/widgets/widgets/tablet/tabletapplication.cpp b/examples/widgets/widgets/tablet/tabletapplication.cpp index c3210f822c..3e1356ee9c 100644 --- a/examples/widgets/widgets/tablet/tabletapplication.cpp +++ b/examples/widgets/widgets/tablet/tabletapplication.cpp @@ -47,8 +47,7 @@ bool TabletApplication::event(QEvent *event) { if (event->type() == QEvent::TabletEnterProximity || event->type() == QEvent::TabletLeaveProximity) { - myCanvas->setTabletDevice( - static_cast<QTabletEvent *>(event)->device()); + myCanvas->setTabletDevice(static_cast<QTabletEvent *>(event)); return true; } return QApplication::event(event); diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp index bf98a6d621..8ff3d41e0e 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.cpp +++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp @@ -103,6 +103,8 @@ void TabletCanvas::tabletEvent(QTabletEvent *event) } break; case QEvent::TabletMove: + if (event->device() == QTabletEvent::RotationStylus) + updateCursor(event); if (deviceDown) { updateBrush(event); QPainter painter(&pixmap); @@ -201,7 +203,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event) //! [5] //! [7] -void TabletCanvas::updateBrush(QTabletEvent *event) +void TabletCanvas::updateBrush(const QTabletEvent *event) { int hue, saturation, value, alpha; myColor.getHsv(&hue, &saturation, &value, &alpha); @@ -266,6 +268,46 @@ void TabletCanvas::updateBrush(QTabletEvent *event) } //! [11] +void TabletCanvas::updateCursor(const QTabletEvent *event) +{ + QCursor cursor; + if (event->type() != QEvent::TabletLeaveProximity) { + if (event->pointerType() == QTabletEvent::Eraser) { + cursor = QCursor(QPixmap(":/images/cursor-eraser.png"), 3, 28); + } else { + switch (event->device()) { + case QTabletEvent::Stylus: + cursor = QCursor(QPixmap(":/images/cursor-pencil.png"), 0, 0); + break; + case QTabletEvent::Airbrush: + cursor = QCursor(QPixmap(":/images/cursor-airbrush.png"), 3, 4); + break; + case QTabletEvent::RotationStylus: { + QImage origImg(QLatin1String(":/images/cursor-felt-marker.png")); + QImage img(32, 32, QImage::Format_ARGB32); + QColor solid = myColor; + solid.setAlpha(255); + img.fill(solid); + QPainter painter(&img); + QTransform transform = painter.transform(); + transform.translate(16, 16); + transform.rotate(-event->rotation()); + painter.setTransform(transform); + painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); + painter.drawImage(-24, -24, origImg); + painter.setCompositionMode(QPainter::CompositionMode_HardLight); + painter.drawImage(-24, -24, origImg); + painter.end(); + cursor = QCursor(QPixmap::fromImage(img), 16, 16); + } break; + default: + break; + } + } + } + setCursor(cursor); +} + void TabletCanvas::resizeEvent(QResizeEvent *) { initPixmap(); diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h index 06090a9052..a7335dbaf0 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.h +++ b/examples/widgets/widgets/tablet/tabletcanvas.h @@ -80,8 +80,8 @@ public: { myColor = color; } QColor color() const { return myColor; } - void setTabletDevice(QTabletEvent::TabletDevice device) - { myTabletDevice = device; } + void setTabletDevice(QTabletEvent *event) + { myTabletDevice = event->device(); updateCursor(event); } int maximum(int a, int b) { return a > b ? a : b; } @@ -94,7 +94,8 @@ private: void initPixmap(); void paintPixmap(QPainter &painter, QTabletEvent *event); Qt::BrushStyle brushPattern(qreal value); - void updateBrush(QTabletEvent *event); + void updateBrush(const QTabletEvent *event); + void updateCursor(const QTabletEvent *event); AlphaChannelType alphaChannelType; ColorSaturationType colorSaturationType; |