summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/oclickablelabel.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/oclickablelabel.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/oclickablelabel.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/oclickablelabel.cpp b/noncore/unsupported/libopie/oclickablelabel.cpp
new file mode 100644
index 0000000..bc7037b
--- a/dev/null
+++ b/noncore/unsupported/libopie/oclickablelabel.cpp
@@ -0,0 +1,117 @@
1#include "oclickablelabel.h"
2#include <stdio.h>
3
4/**
5 * This constructs the clickable ButtonLabel
6 *
7 * @param parent The parent of this label
8 * @param name A name of this label @see QObject
9 * @param fl The windowing flags
10 */
11OClickableLabel::OClickableLabel(QWidget* parent,
12 const char* name,
13 WFlags fl) :
14 QLabel(parent,name,fl)
15{
16 textInverted=false;
17 isToggle=false;
18 isDown=false;
19 showState(false);
20 setFrameShadow(Sunken);
21}
22
23/**
24 * This method makes the label behave as a toggle button
25 *
26 * @param t Whether or not to behave like a toggle button
27 */
28void OClickableLabel::setToggleButton(bool t) {
29 isToggle=t;
30}
31
32/**
33 * @internal
34 */
35void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ ) {
36 if (isToggle && isDown) {
37 showState(false);
38 } else {
39 showState(true);
40 }
41}
42
43/**
44 * @internal
45 */
46void OClickableLabel::mouseReleaseEvent( QMouseEvent *e ) {
47 if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
48
49 if (isToggle && isDown) {
50 showState(true);
51 } else {
52 showState(false);
53 }
54
55 if (rect().contains(e->pos())) {
56 if (isToggle) {
57 emit toggled(isDown);
58 }
59 emit clicked();
60 }
61}
62
63/**
64 * @internal
65 */
66void OClickableLabel::mouseMoveEvent( QMouseEvent *e ) {
67 if (rect().contains(e->pos())) {
68 if (isToggle && isDown) {
69 showState(false);
70 } else {
71 showState(true);
72 }
73 } else {
74 if (isToggle && isDown) {
75 showState(true);
76 } else {
77 showState(false);
78 }
79 }
80}
81
82/**
83 * this toggles the label and inverts the color of
84 * the label
85 * @param on
86 */
87void OClickableLabel::showState(bool on) {
88 if (on) {
89 //setFrameShape(Panel);
90 setInverted(true);
91 setBackgroundMode(PaletteHighlight);
92 } else {
93 //setFrameShape(NoFrame);
94 setInverted(false);
95 setBackgroundMode(PaletteBackground);
96 }
97 repaint();
98}
99
100void OClickableLabel::setInverted(bool on) {
101 if ( (!textInverted && on) || (textInverted && !on) ) {
102 QPalette pal=palette();
103 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
104 col.setRgb(255-col.red(),255-col.green(),255-col.blue());
105 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
106 setPalette(pal);
107 textInverted=!textInverted;
108 }
109}
110
111/**
112 * @param on if the Label is down or up
113 */
114void OClickableLabel::setOn(bool on) {
115 isDown=on;
116 showState(isDown);
117}