-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvigilbutton.cpp
170 lines (136 loc) · 3.88 KB
/
vigilbutton.cpp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "vigilbutton.h"
VigilButton::VigilButton(QWidget *parent) : QAbstractButton(parent), fontSize(12), _counter(0)
{
setText("default");
setFixedSize(50,50);
setColor(GRAY);
setShape(DEFAULT);
bp.setCurrentColorGroup(QPalette::Inactive);
//drop shadow effect
setGraphicsEffect(&bodyShadow);
bodyShadow.setColor(QColor(0, 0, 0, 200));
bodyShadow.setBlurRadius(20.0);
bodyShadow.setDistance(6.0);
timesFont.setFamily("Myriad Pro");
timesFont.setPointSize(fontSize);
timesFont.setBold(true);
}
VigilButton::VigilButton(const QString &text,int w, int h, VigilColor FlatButtonColor, Shape shape, QWidget *parent) :
QAbstractButton(parent), fontSize(20)
{
setText(text);
setFixedSize(w,h);
setColor(FlatButtonColor);
setShape(shape);
bp.setCurrentColorGroup(QPalette::Inactive);
//drop shadow effect
setGraphicsEffect(&bodyShadow);
bodyShadow.setColor(QColor(0, 0, 0, 200));
bodyShadow.setBlurRadius(20.0);
bodyShadow.setDistance(6.0);
timesFont.setFamily("Myriad Pro");
timesFont.setPointSize(fontSize);
timesFont.setBold(true);
}
void VigilButton::mousePressEvent(QMouseEvent * e)
{
QAbstractButton::mousePressEvent(e);
bodyShadow.setDistance(3.0);
timesFont.setPointSizeF(fontSize-1);
double time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
//incrementation du compteur LCD
_counter++;
_lcdnb->display(_counter);
_model->increment(_id,time);
}
void VigilButton::mouseReleaseEvent(QMouseEvent * e)
{
QAbstractButton::mouseReleaseEvent(e);
bodyShadow.setDistance(6.0);
timesFont.setPointSizeF(fontSize);
}
void VigilButton::paintEvent(QPaintEvent* e)
{
QPainter p(this);
p.save();
if(!isEnabled()) bp.setCurrentColorGroup(QPalette::Disabled);
else if(!isDown()&&!isChecked())bp.setCurrentColorGroup(QPalette::Inactive);
else bp.setCurrentColorGroup(QPalette::Active);
p.setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.addRoundedRect(e->rect(),xRadius, yRadius, Qt::RelativeSize);
QRadialGradient gradient(size().width()/2,size().rheight()/2, size().width()/2);
gradient.setColorAt(0.0, bp.midlight().color());
gradient.setColorAt(0.8, VigilButtonPalette::interPoleRgb(bp.midlight().color(),bp.dark().color()));
gradient.setColorAt(1.0, bp.dark().color());
p.setBrush(gradient);
p.fillPath(path,p.brush());
QPainterPath textPath;
textPath.addText(size().rwidth()/2, size().rheight()/2, timesFont, text());
textPath.translate(-textPath.boundingRect().width()/2,textPath.boundingRect().height()/2);
p.fillPath(textPath,bp.buttonText().color());
p.restore();
}
void VigilButton::setShape(Shape s)
{
switch (s) {
case FACTORY:
xRadius = 20;
yRadius = 100;
break;
case ROUND:
xRadius = 100;
yRadius = 100;
break;
default:
xRadius = 20;
yRadius = 20;
break;
}
update();
}
void VigilButton::setColor(VigilColor c)
{
switch (c) {
case BLUE:
bp.setHSV(210,0.63);
break;
case RED:
bp.setHSV(0,0.80);
break;
case ORANGE:
bp.setHSV(12,0.80);
break;
case GREEN:
bp.setHSV(105,0.63);
break;
case GRAY:
bp.setHSV(30,0.17);
break;
case LIGHT_GREEN:
bp.setHSV(85,0.40);
break;
case LIGHT_BLUE:
bp.setHSV(180,0.30);
break;
default:
bp.setHSV(110,0.17);
break;
}
update();
}
void VigilButton::setFontSize(int size)
{
fontSize = size;
timesFont.setPointSize(size);
update();
}
void VigilButton::setid(int id){
_id =id;
}
void VigilButton::setmodel(Model* model){
_model = model;
}
void VigilButton::setLcdNb(QLCDNumber* nb){
_lcdnb = nb;
}