6f96c947a
김태훈
GUI 0.1.4
|
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
61
|
#include "preheattempgauge.h"
#include <QPainter>
#include <QtDebug>
PreheatTempGauge::PreheatTempGauge(QWidget *parent) : QWidget(parent)
{
border.load(":/images/images/auto/graphe_hit_01.png");
indicator.load(":/images/images/auto/graphe_hit_02.png");
body.load(":/images/images/auto/graphe_hit_03.png");
value = 0;
min = 0;
max = 1;
}
void PreheatTempGauge::setValue(int value)
{
this->value = qBound(min, value, max);
update();
}
void PreheatTempGauge::setMinimum(int minimum)
{
min = minimum;
max = qMax(min, max);
value = qBound(min, value, max);
update();
}
void PreheatTempGauge::setMaximum(int maximum)
{
max = maximum;
min = qMin(min, max);
value = qBound(min, value, max);
update();
}
void PreheatTempGauge::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
painter.setBrush(Qt::NoBrush);
painter.setPen(Qt::NoPen);
qreal percentage = (qreal) (value - min) / qMax(max - min, 1);
percentage = qBound((qreal) 0.0, percentage, (qreal) 1.0);
QRect targetRect(
(border.size().width() - body.size().width()) / 2 + indicator.size().width() / 2,
(border.size().height() - body.size().height()) / 2 + indicator.size().height(),
body.size().width() * percentage, body.height());
QRect sourceRect(0, 0, body.size().width() * percentage, body.height());
painter.drawPixmap(targetRect, body, sourceRect);
painter.drawPixmap(indicator.size().width() / 2, indicator.size().height(), border);
painter.drawPixmap(targetRect.right() - indicator.size().width() / 2, 0, indicator);
}
|