-
Notifications
You must be signed in to change notification settings - Fork 12
/
testwidget.cpp
60 lines (54 loc) · 1.38 KB
/
testwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "testwidget.h"
#include "ui_testwidget.h"
TestWidget::TestWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::TestWidget)
{
ui->setupUi(this);
type = TEST_IDLE;
this->setAttribute(Qt::WA_NoBackground);
this->setAttribute(Qt::WA_NoSystemBackground);
duck.load(":/pixmaps/duck.png", "PNG");
}
TestWidget::~TestWidget()
{
delete ui;
}
void TestWidget::paintEvent(QPaintEvent *) {
QPainter painter;
painter.begin(this);
int w = this->width();
int h = this->height();
int s = 60;
QColor color = randomColor();
painter.setPen(color);
painter.setBrush(QBrush(color));
painter.setFont(QFont("Arial",16,QFont::Bold));
switch (type) {
case TEST_LINES:
painter.drawLine(qrand() % w, qrand() % h, qrand() % w, qrand() % h);
break;
case TEST_CIRCLES:
painter.drawEllipse(qrand() % w, qrand() % h, qrand() % s, qrand() % s);
break;
case TEST_TEXT:
painter.drawText(qrand() % w, qrand() % h, "Future is open. ");
break;
case TEST_PIXMAP:
painter.drawPixmap(qrand() % w, qrand() % h, duck);
break;
case TEST_IDLE:
painter.setBrush(QBrush(Qt::white));
painter.drawRect(0,0,w,h);
}
painter.end();
}
QColor TestWidget::randomColor()
{
return QColor(qrand() % 255, qrand() % 255, qrand() % 255);
}
void TestWidget::setType(TestType newtype) {
type = TEST_IDLE;
repaint();
type = newtype;
}