blob: 43a052465b41a4084ade633240470f40d6abe291 (
plain)
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
|
#include "oclickablelabel.h"
#include <stdio.h>
OClickableLabel::OClickableLabel(QWidget* parent,
const char* name,
WFlags fl) :
QLabel(parent,name,fl)
{
textInverted=false;
isToggle=false;
isDown=false;
showState(false);
setFrameShadow(Sunken);
}
void OClickableLabel::setToggleButton(bool t) {
isToggle=t;
}
void OClickableLabel::mousePressEvent( QMouseEvent *e ) {
if (isToggle && isDown) {
showState(false);
} else {
showState(true);
}
}
void OClickableLabel::mouseReleaseEvent( QMouseEvent *e ) {
if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
if (isToggle && isDown) {
showState(true);
} else {
showState(false);
}
if (rect().contains(e->pos())) {
if (isToggle) {
emit toggled(isDown);
}
emit clicked();
}
}
void OClickableLabel::mouseMoveEvent( QMouseEvent *e ) {
if (rect().contains(e->pos())) {
if (isToggle && isDown) {
showState(false);
} else {
showState(true);
}
} else {
if (isToggle && isDown) {
showState(true);
} else {
showState(false);
}
}
}
void OClickableLabel::showState(bool on) {
if (on) {
//setFrameShape(Panel);
setInverted(true);
setBackgroundMode(PaletteHighlight);
} else {
//setFrameShape(NoFrame);
setInverted(false);
setBackgroundMode(PaletteBackground);
}
repaint();
}
void OClickableLabel::setInverted(bool on) {
if ( (!textInverted && on) || (textInverted && !on) ) {
QPalette pal=palette();
QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
col.setRgb(255-col.red(),255-col.green(),255-col.blue());
pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
setPalette(pal);
textInverted=!textInverted;
}
}
void OClickableLabel::setOn(bool on) {
isDown=on;
showState(isDown);
}
|