-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdmibutton.cpp
More file actions
89 lines (82 loc) · 3.12 KB
/
Copy pathdmibutton.cpp
File metadata and controls
89 lines (82 loc) · 3.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
#include "dmibutton.h"
dmiButton::dmiButton(QWidget *parent) : QWidget(parent)
{
}
void dmiButton::setUsed(bool used){
isUsed = used;
}
void dmiButton::setPixmapEnabled(QPixmap pme, QPixmap pmd){
enabPixmap = pme;
disaPixmap = pmd;
}
void dmiButton::setEnabled(bool en){
enabledd = en;
}
void dmiButton::setBorderThickness(int thickness){
borderThickness = thickness;
}
void dmiButton::mousePressEvent(QMouseEvent *event){
pushed = true;
update();
if(isUsed)
emit clicked(true);
}
void dmiButton::mouseReleaseEvent(QMouseEvent *event){
pushed = false;
update();
}
void dmiButton::paintEvent(QPaintEvent *)
{
if(isUsed){
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int halfHeight = height()/2;
int halfWidth = width()/2;
QRect darkBorder(0, 0, width(), height());
QPoint brightBorder[5];
if(halfWidth > halfHeight){
brightBorder[0] = QPoint( width(), 0);
brightBorder[1] = QPoint( width(), height());
brightBorder[2] = QPoint(0, height());
brightBorder[3] = QPoint(halfHeight, halfHeight);
brightBorder[4] = QPoint( width() - halfHeight, halfHeight);
}
else{
brightBorder[0] = QPoint(width(), 0);
brightBorder[1] = QPoint(width(), height());
brightBorder[2] = QPoint(0 , height());
brightBorder[3] = QPoint(halfWidth, height() - halfWidth);
brightBorder[4] = QPoint(halfWidth, halfWidth);
}
QRect centralArea(borderThickness, borderThickness, width()-2*borderThickness, height()-2*borderThickness);
QRect centralAreaPush(2*borderThickness, 2*borderThickness, width()-4*borderThickness, height()- 4 * borderThickness);
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(era::black);
painter.drawRect(darkBorder);
painter.setBrush(era::shadow);
painter.drawPolygon(brightBorder, 5);
painter.setBrush(era::darkBlue);
painter.drawRect(centralArea);
painter.drawPixmap(centralAreaPush,enabPixmap);
painter.restore();
if(!pushed){
brightBorder[0] = QPoint(brightBorder[0].x() - borderThickness, brightBorder[0].y() + borderThickness);
brightBorder[1] = QPoint(brightBorder[1].x() - borderThickness, brightBorder[1].y() - borderThickness);
brightBorder[2] = QPoint(brightBorder[2].x() + borderThickness, brightBorder[2].y() - borderThickness);
brightBorder[3] = QPoint(brightBorder[3].x() + borderThickness, brightBorder[3].y() - borderThickness);
brightBorder[4] = QPoint(brightBorder[4].x() - borderThickness, brightBorder[4].y() + borderThickness);
darkBorder = QRect(borderThickness,borderThickness,width() - 2 * borderThickness, height() - 2 * borderThickness);
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(era::shadow);
painter.drawRect(darkBorder);
painter.setBrush(era::black);
painter.drawPolygon(brightBorder, 5);
painter.setBrush(era::darkBlue);
painter.drawRect(centralAreaPush);
painter.drawPixmap(centralAreaPush,enabPixmap);
painter.restore();
}
}
}