summaryrefslogtreecommitdiffstats
path: root/tests/manual/repaint
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/repaint')
-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) {