-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.cpp
More file actions
106 lines (83 loc) · 2.12 KB
/
progressbar.cpp
File metadata and controls
106 lines (83 loc) · 2.12 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "progressbar.h"
#include "scaler.h"
ProgressBar::ProgressBar(const QRect &pos) :
myMax(100), myVal(0), myDelta(0),
myAutoMax(false),
myRect(pos),
myUpSpeed(0), myUpCount(0), myUpValue(0)
{
setBrush(Qt::blue);
}
void ProgressBar::setMax(double max)
{
if (myMax == max) return;
myMax = max;
if (myVal > myMax)
{
if (myAutoMax)
myMax = myVal;
else
myVal = myMax;
}
}
void ProgressBar::setValue(double value)
{
if (myVal == value) return;
myUpValue = myVal; // myUpValue is the "from" value to slide
myUpCount = value > myVal ? myUpSpeed : 0; // no down slide
myVal = value;
if (myVal > myMax)
{
if (myAutoMax)
myMax = myVal;
else
myVal = myMax;
}
//myDelta = (myVal/myMax) * myRect.height();
}
void ProgressBar::setUpSpeed(int speed)
{
if (myUpSpeed == speed) return;
myUpSpeed = speed;
}
void ProgressBar::paint(QPainter &p)
{
QRect baseRect = DRECT(myRect);
p.setOpacity(0.3);
p.setPen(QPen(Qt::white, 2));
p.setBrush(QColor(0x162d50));
p.drawRoundedRect(baseRect, 5,5);
if (myVal == 0) return;
double val/* = myDelta*/;
if (myUpCount)
{
myUpCount--;
double d = (myVal-myUpValue)/myUpSpeed * (myUpSpeed-myUpCount);
val = (myUpValue+d)/myMax * myRect.height();
} else
val = (myVal/myMax) * myRect.height();
QRect dataRect(baseRect);
dataRect.setTop(baseRect.bottom() - DY(val));
if (myUpCount) {
if (myUpCount > myUpSpeed/2) // dim
p.setOpacity((myUpCount-myUpSpeed/2)*0.4/myUpSpeed + 0.4);
else // sharp
p.setOpacity((myUpSpeed-myUpCount)*0.4/myUpSpeed + 0.4);
}
else
p.setOpacity(0.8);
// p.setPen(Qt::NoPen);
// p.setBrush(myBrush);
//
// p.drawRect(dataRect.adjusted(2,2,-2,-2));
p.drawPixmap(dataRect.adjusted(2,2,-2,-2), myBuffer);
}
void ProgressBar::setBrush(const QBrush &brush)
{
myBrush = brush;
// pre-render background
myBuffer = QPixmap(QSize(DX(myRect.width()),1));
QPainter pnt(&myBuffer);
pnt.fillRect(myBuffer.rect(), myBrush);
pnt.end();
}