summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@nokia.com>2010-03-10 12:59:54 (GMT)
committerMorten Johan Sørvig <morten.sorvig@nokia.com>2010-03-10 13:08:28 (GMT)
commit799c350d0fe0a29c146c7a32a509b71ea6bb7f49 (patch)
tree3d8ce10e3f2e6a97c38ca8d41e3b4f804c998cda /tests
parentb07930ae8ed585d9e770d473f789a5b20dac1c5b (diff)
downloadQt-799c350d0fe0a29c146c7a32a509b71ea6bb7f49.zip
Qt-799c350d0fe0a29c146c7a32a509b71ea6bb7f49.tar.gz
Qt-799c350d0fe0a29c146c7a32a509b71ea6bb7f49.tar.bz2
Add QWidget::update() test.
Test that QWidget::update sends minimal updates, both for the rect and region version.
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/repaint/shared/shared.h51
1 files changed, 50 insertions, 1 deletions
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<QRect> 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) {