From 799c350d0fe0a29c146c7a32a509b71ea6bb7f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 10 Mar 2010 13:59:54 +0100 Subject: Add QWidget::update() test. Test that QWidget::update sends minimal updates, both for the rect and region version. --- tests/manual/repaint/shared/shared.h | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/manual/repaint/shared/shared.h b/tests/manual/repaint/shared/shared.h index 3cea95f..6524d48 100644 --- a/tests/manual/repaint/shared/shared.h +++ b/tests/manual/repaint/shared/shared.h @@ -46,19 +46,65 @@ class StaticWidget : public QWidget Q_OBJECT public: int hue; + bool pressed; StaticWidget(QWidget *parent = 0) :QWidget(parent) { setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_OpaquePaintEvent); hue = 200; + pressed = false; } + // Update 4 rects in a checkerboard pattern, using either + // a QRegion or separate rects (see the useRegion switch) + void updatePattern(QPoint pos) + { + const int rectSize = 10; + QRect rect(pos.x() - rectSize, pos.y() - rectSize, rectSize *2, rectSize * 2); + + QVector updateRects; + updateRects.append(rect.translated(rectSize * 2, rectSize * 2)); + updateRects.append(rect.translated(rectSize * 2, -rectSize * 2)); + updateRects.append(rect.translated(-rectSize * 2, rectSize * 2)); + updateRects.append(rect.translated(-rectSize * 2, -rectSize * 2)); + + + bool useRegion = false; + if (useRegion) { + QRegion region; + region.setRects(updateRects.data(), 4); + update(region); + } else { + foreach (QRect rect, updateRects) + update(rect); + } + } + + void resizeEvent(QResizeEvent *) { // qDebug() << "static widget resize from" << e->oldSize() << "to" << e->size(); } + void mousePressEvent(QMouseEvent *event) + { +// qDebug() << "mousePress at" << event->pos(); + pressed = true; + updatePattern(event->pos()); + } + + void mouseReleaseEvent(QMouseEvent *) + { + pressed = false; + } + + void mouseMoveEvent(QMouseEvent *event) + { + if (pressed) + updatePattern(event->pos()); + } + void paintEvent(QPaintEvent *e) { QPainter p(this); @@ -66,7 +112,10 @@ public: color = (color + 41) % 205 + 50; // color = ((color + 45) %150) + 100; qDebug() << "static widget repaint" << e->rect(); - p.fillRect(e->rect(), QColor::fromHsv(hue, 255, color)); + if (pressed) + p.fillRect(e->rect(), QColor::fromHsv(100, 255, color)); + else + p.fillRect(e->rect(), QColor::fromHsv(hue, 255, color)); p.setPen(QPen(QColor(Qt::white))); for (int y = e->rect().top(); y <= e->rect().bottom() + 1; ++y) { -- cgit v0.12