-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.cpp
More file actions
141 lines (120 loc) · 2.67 KB
/
Copy pathprogressbar.cpp
File metadata and controls
141 lines (120 loc) · 2.67 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "progressbar.h"
ProgressBar::ProgressBar(qreal width,qreal height,QPointF position, qreal border_width, QObject *parent)
: QObject{parent},m_progress(0),m_position(position),m_borderWidth(border_width)
{
QPointF rb(position.x()+width,position.y()+height);
m_rect=QRectF(position,rb);
m_internalColor=QColor(0,0,0);
m_internalColor=QColor(0,0,0);
}
void ProgressBar::setProgress(qreal x)
{
if(x<0) x=0;
if(x>=1)
{
emit complete();
x=1;
}
m_progress=x;
}
qreal ProgressBar::progress()
{
return m_progress;
}
void ProgressBar::setBorderColor(QColor c)
{
m_borderColor=c;
}
void ProgressBar::setInternalColor(QColor c)
{
m_internalColor=c;
}
QColor ProgressBar::borderColor()
{
return m_borderColor;
}
QColor ProgressBar::internalColor()
{
return m_internalColor;
}
void ProgressBar::setRect(QRectF rect)
{
m_rect=rect;
m_position=rect.topLeft();
}
QRectF ProgressBar::rect()
{
return m_rect;
}
void ProgressBar::setWidth(qreal w)
{
QRectF newRect=rect();
newRect.setRect(rect().x(),rect().y(),w,rect().height());
setRect(newRect);
}
void ProgressBar::setHeight(qreal h)
{
QRectF newRect=rect();
newRect.setRect(rect().x(),rect().y(),rect().width(),h);
setRect(newRect);
}
qreal ProgressBar::width()
{
return m_rect.width();
}
qreal ProgressBar::height()
{
return m_rect.height();
}
void ProgressBar::setPosition(QPointF p)
{
m_position=p;
QRectF newRect(p,QPointF(p.x()+width(),p.y()+height()));
m_rect=newRect;
}
QPointF ProgressBar::position()
{
return m_position;
}
void ProgressBar::center(QRect rect)
{
qreal x=rect.center().x()-width()/2;
qreal y=rect.center().y()-height()/2;
setPosition(QPointF(x,y));
}
void ProgressBar::centerLower(QRect rect)
{
qreal x=rect.center().x()-width()/2;
qreal y=rect.center().y();
setPosition(QPointF(x,y));
}
void ProgressBar::setBorderWidth(qreal w)
{
m_borderWidth=w;
}
qreal ProgressBar::borderWidth()
{
return m_borderWidth;
}
void ProgressBar::paint(QPainter &painter)
{
QPen oldPen=painter.pen();
QBrush oldBrush=painter.brush();
//内部
painter.setBrush(m_internalColor);
painter.setPen(Qt::NoPen);
qreal x=width()-borderWidth();
qreal y=height()-borderWidth();
QPointF lt(m_position.x()+m_borderWidth/2,m_position.y()+m_borderWidth/2);
QPointF rb(x*progress()+lt.x(),y+lt.y());
painter.drawRect(QRectF(lt,rb));
//外部
QPen pen(m_borderColor);
pen.setWidth(m_borderWidth);
painter.setBrush(Qt::NoBrush);
painter.setPen(pen);
painter.drawRect(rect());
//复原
painter.setBrush(oldBrush);
painter.setPen(oldPen);
}