diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-11-25 14:01:13 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-11-25 16:03:33 (GMT) |
commit | aaae24808654d54bf8aca04f825c6aa786fe342f (patch) | |
tree | 230f47a5ad8640f6e1cdd4849c0e4812ad97dfc9 /examples/widgets | |
parent | dddd3e5fc9658ebbb5f94b343e7c7c0cd27eb7f2 (diff) | |
download | Qt-aaae24808654d54bf8aca04f825c6aa786fe342f.zip Qt-aaae24808654d54bf8aca04f825c6aa786fe342f.tar.gz Qt-aaae24808654d54bf8aca04f825c6aa786fe342f.tar.bz2 |
Use a pixmap instead of an image in the tablet example
The transformations QImage->QPixmap are killing the performance of the
tablet example. This is noticeable because of the number of events sent
by the tablet (painting MUST be fast in tabletEvent()).
Reviewed-by: David Boddie
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/tablet/tabletcanvas.cpp | 30 | ||||
-rw-r--r-- | examples/widgets/tablet/tabletcanvas.h | 8 |
2 files changed, 19 insertions, 19 deletions
diff --git a/examples/widgets/tablet/tabletcanvas.cpp b/examples/widgets/tablet/tabletcanvas.cpp index 130498b..20b0d1e 100644 --- a/examples/widgets/tablet/tabletcanvas.cpp +++ b/examples/widgets/tablet/tabletcanvas.cpp @@ -50,7 +50,7 @@ TabletCanvas::TabletCanvas() resize(500, 500); myBrush = QBrush(); myPen = QPen(); - initImage(); + initPixmap(); setAutoFillBackground(true); deviceDown = false; myColor = Qt::red; @@ -60,29 +60,29 @@ TabletCanvas::TabletCanvas() lineWidthType = LineWidthPressure; } -void TabletCanvas::initImage() +void TabletCanvas::initPixmap() { - QImage newImage = QImage(width(), height(), QImage::Format_ARGB32); - QPainter painter(&newImage); - painter.fillRect(0, 0, newImage.width(), newImage.height(), Qt::white); - if (!image.isNull()) - painter.drawImage(0, 0, image); + QPixmap newPixmap = QPixmap(width(), height()); + newPixmap.fill(Qt::white); + QPainter painter(&newPixmap); + if (!pixmap.isNull()) + painter.drawPixmap(0, 0, pixmap); painter.end(); - image = newImage; + pixmap = newPixmap; } //! [0] //! [1] bool TabletCanvas::saveImage(const QString &file) { - return image.save(file); + return pixmap.save(file); } //! [1] //! [2] bool TabletCanvas::loadImage(const QString &file) { - bool success = image.load(file); + bool success = pixmap.load(file); if (success) { update(); @@ -114,8 +114,8 @@ void TabletCanvas::tabletEvent(QTabletEvent *event) if (deviceDown) { updateBrush(event); - QPainter painter(&image); - paintImage(painter, event); + QPainter painter(&pixmap); + paintPixmap(painter, event); } break; default: @@ -129,12 +129,12 @@ void TabletCanvas::tabletEvent(QTabletEvent *event) void TabletCanvas::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.drawImage(QPoint(0, 0), image); + painter.drawPixmap(0, 0, pixmap); } //! [4] //! [5] -void TabletCanvas::paintImage(QPainter &painter, QTabletEvent *event) +void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event) { QPoint brushAdjust(10, 10); @@ -271,6 +271,6 @@ void TabletCanvas::updateBrush(QTabletEvent *event) void TabletCanvas::resizeEvent(QResizeEvent *) { - initImage(); + initPixmap(); polyLine[0] = polyLine[1] = polyLine[2] = QPoint(); } diff --git a/examples/widgets/tablet/tabletcanvas.h b/examples/widgets/tablet/tabletcanvas.h index 02b8794..5a2fb1d 100644 --- a/examples/widgets/tablet/tabletcanvas.h +++ b/examples/widgets/tablet/tabletcanvas.h @@ -43,7 +43,7 @@ #define TABLETCANVAS_H #include <QWidget> -#include <QImage> +#include <QPixmap> #include <QPoint> #include <QTabletEvent> #include <QColor> @@ -92,8 +92,8 @@ protected: void resizeEvent(QResizeEvent *event); private: - void initImage(); - void paintImage(QPainter &painter, QTabletEvent *event); + void initPixmap(); + void paintPixmap(QPainter &painter, QTabletEvent *event); Qt::BrushStyle brushPattern(qreal value); void updateBrush(QTabletEvent *event); @@ -104,7 +104,7 @@ private: QTabletEvent::TabletDevice myTabletDevice; QColor myColor; - QImage image; + QPixmap pixmap; QBrush myBrush; QPen myPen; bool deviceDown; |