-
Notifications
You must be signed in to change notification settings - Fork 0
/
pie.h
98 lines (73 loc) · 1.98 KB
/
pie.h
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
#ifndef PIE_H
#define PIE_H
#include <QPushButton>
#include <QPainter>
#include <QLabel>
#include <QDebug>
class Pie : public QPushButton
{
Q_OBJECT
public:
int siz;
bool overlay = false;
int savedPer;
QColor color = Qt::gray;
Pie(int percent, int size)
{
setStyleSheet("Pie{background:transparent;border:none;}");
setAttribute(Qt::WA_Hover);
setIconSize(QSize(size,size));
siz = size;
setFixedSize(size,size);
setPercent(percent);
}
void setColor(QColor col){
color = col;
setPercent(savedPer);
}
void enterEvent(QEvent*)
{
overlay = true;
int si = siz*4;
float wi = si/18;
QImage img(QSize(si,si),QImage::Format_ARGB32);
img.fill(Qt::transparent);
QPainter painter(&img);
painter.setPen(Qt::NoPen);
painter.setBrush(color);
painter.drawRect(wi*6,wi*6,si-wi*12,si-wi*12);
painter.setBrush(Qt::NoBrush);
QPen pen(color);
pen.setWidth(wi);
painter.setPen(pen);
painter.drawEllipse(wi,wi,si-wi*2,si-wi*2);
setIcon(QIcon(QPixmap::fromImage(img)));
}
void leaveEvent(QEvent*)
{
overlay = false;
setPercent(savedPer);
}
public slots:
void setPercent(int per)
{
if(overlay)return;
int si = siz*5;
float wi = si/18;
float grade = ((float)360/(float)100)*(float)per;
savedPer = per;
QImage img(QSize(si,si),QImage::Format_ARGB32);
img.fill(Qt::transparent);
QPainter painter(&img);
painter.setPen(Qt::NoPen);
painter.setBrush(color);
painter.drawPie(QRect(wi,wi,si-wi*2,si-wi*2),90*16,-(grade*16));
painter.setBrush(Qt::NoBrush);
QPen pen(color);
pen.setWidth(wi);
painter.setPen(pen);
painter.drawEllipse(wi,wi,si-wi*2,si-wi*2);
setIcon(QIcon(QPixmap::fromImage(img)));
}
};
#endif // PIE_H