-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtprogressarcstatic.cpp
More file actions
117 lines (97 loc) · 2.84 KB
/
tprogressarcstatic.cpp
File metadata and controls
117 lines (97 loc) · 2.84 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
#include "tprogressarcstatic.h"
#include <QtPlugin>
#include <QResizeEvent>
#include <QPainter>
#include <QDebug>
TProgressArcStatic::TProgressArcStatic(QWidget *parent)
: QProgressBar(parent), m_backgroundColor(Qt::darkGray),
m_progressColor(QColor::fromRgb(0, 86, 255)), m_penWidth(5), m_angle(270), m_flat(true)
{
setValue(0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setMinimumSize(50, 50);
}
QColor TProgressArcStatic::backgroundColor() const {
return m_backgroundColor;
}
void TProgressArcStatic::setBackgroundColor(const QColor &color) {
if(m_backgroundColor != color) {
m_backgroundColor = color;
update();
emit backgroundColorChanged();
}
}
QColor TProgressArcStatic::progressColor() const {
return m_progressColor;
}
void TProgressArcStatic::setProgressColor(const QColor &color){
if(m_progressColor != color) {
m_progressColor = color;
update();
emit progressColorChanged();
}
}
int TProgressArcStatic::penWidth() const {
return m_penWidth;
}
void TProgressArcStatic::setPenWidth(int width) {
if(m_penWidth != width) {
m_penWidth = width;
update();
emit penWidthChanged();
}
}
int TProgressArcStatic::angle() const {
return m_angle;
}
void TProgressArcStatic::setAngle(int value){
if(m_angle != value) {
m_angle = value;
update();
emit angleChanged();
}
}
bool TProgressArcStatic::flat() const {
return m_flat;
}
void TProgressArcStatic::setFlat(bool value) {
if (m_flat != value) {
m_flat = value;
update();
emit flatChanged();
}
}
void TProgressArcStatic::paintEvent(QPaintEvent *) {
int progress = this->value();
int progressInDegrees = (progress * 360) / 100;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen backgroundPen;
backgroundPen.setColor(m_backgroundColor);
backgroundPen.setWidth(m_penWidth);
if (m_flat) {
backgroundPen.setCapStyle(Qt::FlatCap);
} else {
backgroundPen.setCapStyle(Qt::RoundCap);
}
QPen pen;
pen.setColor(m_progressColor);
pen.setWidth(m_penWidth);
if (m_flat) {
pen.setCapStyle(Qt::FlatCap);
} else {
pen.setCapStyle(Qt::RoundCap);
}
painter.setPen(backgroundPen);
painter.drawArc(10, 10, this->width()-20, this->height()-20, 16 * m_angle, -16 * (maximum() * 3.6));
painter.setPen(pen);
painter.drawArc(10, 10, this->width()-20, this->height()-20, 16 * m_angle, -16 * progressInDegrees);
}
void TProgressArcStatic::resizeEvent(QResizeEvent *event) {
QProgressBar::resizeEvent(event);
if (parentWidget()) {
int shortSide = qMin(parentWidget()->width(), parentWidget()->height());
setFixedSize(shortSide, shortSide);
//resize(shortSide, shortSide);
}
}