-
Notifications
You must be signed in to change notification settings - Fork 1
/
qpushlabel.cpp
60 lines (51 loc) · 1.3 KB
/
qpushlabel.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
#include "qpushlabel.h"
#include <QMouseEvent>
QPushLabel::QPushLabel(QWidget *parent) :
QLabel(parent),
emitClicked(false),
pressed(false)
{
QSize s(360, 164);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
setAlignment(Qt::AlignHCenter | Qt::AlignTop);
setMargin(16);
setMinimumSize(s);
setMaximumSize(s);
}
void QPushLabel::mousePressEvent(QMouseEvent *ev)
{
if (ev->buttons() == Qt::LeftButton)
{
setStyleSheet("border-image: url(/etc/hildon/theme/images/320IconHighlight.png);");
pressed = emitClicked = true;
}
QLabel::mousePressEvent(ev);
}
void QPushLabel::mouseMoveEvent(QMouseEvent *ev)
{
if (pressed)
{
if (emitClicked && !rect().contains(ev->pos()))
{
setStyleSheet("");
emitClicked = false;
}
else if (!emitClicked && rect().contains(ev->pos()))
{
setStyleSheet("border-image: url(/etc/hildon/theme/images/320IconHighlight.png);");
emitClicked = true;
}
}
QLabel::mouseMoveEvent(ev);
}
void QPushLabel::mouseReleaseEvent(QMouseEvent *ev)
{
QLabel::mouseReleaseEvent(ev);
pressed = false;
if (emitClicked)
{
setStyleSheet("");
emitClicked = false;
Q_EMIT clicked();
}
}