author | hakan <hakan> | 2002-05-07 10:43:49 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-05-07 10:43:49 (UTC) |
commit | cfe30703da090180b66bc571e85654c71a7ee8e0 (patch) (unidiff) | |
tree | d6954140f2208becb9a6beb5b8a21529bfd5bceb /libopie | |
parent | c9849cc04b668f1cda7a16d868299c436d1de042 (diff) | |
download | opie-cfe30703da090180b66bc571e85654c71a7ee8e0.zip opie-cfe30703da090180b66bc571e85654c71a7ee8e0.tar.gz opie-cfe30703da090180b66bc571e85654c71a7ee8e0.tar.bz2 |
Moved ClickableLabel to libopie/OClickableLabel
-rw-r--r-- | libopie/libopie.pro | 4 | ||||
-rw-r--r-- | libopie/oclickablelabel.cpp | 88 | ||||
-rw-r--r-- | libopie/oclickablelabel.h | 30 |
3 files changed, 120 insertions, 2 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index ba64bda..337206a 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -1,8 +1,8 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h | 3 | HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h |
4 | SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp | 4 | SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp |
5 | TARGET = opie | 5 | TARGET = opie |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
8 | #VERSION = 1.0.0 | 8 | #VERSION = 1.0.0 |
diff --git a/libopie/oclickablelabel.cpp b/libopie/oclickablelabel.cpp new file mode 100644 index 0000000..43a0524 --- a/dev/null +++ b/libopie/oclickablelabel.cpp | |||
@@ -0,0 +1,88 @@ | |||
1 | #include "oclickablelabel.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | OClickableLabel::OClickableLabel(QWidget* parent, | ||
5 | const char* name, | ||
6 | WFlags fl) : | ||
7 | QLabel(parent,name,fl) | ||
8 | { | ||
9 | textInverted=false; | ||
10 | isToggle=false; | ||
11 | isDown=false; | ||
12 | showState(false); | ||
13 | setFrameShadow(Sunken); | ||
14 | } | ||
15 | |||
16 | void OClickableLabel::setToggleButton(bool t) { | ||
17 | isToggle=t; | ||
18 | } | ||
19 | |||
20 | void OClickableLabel::mousePressEvent( QMouseEvent *e ) { | ||
21 | if (isToggle && isDown) { | ||
22 | showState(false); | ||
23 | } else { | ||
24 | showState(true); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | void OClickableLabel::mouseReleaseEvent( QMouseEvent *e ) { | ||
29 | if (rect().contains(e->pos()) && isToggle) isDown=!isDown; | ||
30 | |||
31 | if (isToggle && isDown) { | ||
32 | showState(true); | ||
33 | } else { | ||
34 | showState(false); | ||
35 | } | ||
36 | |||
37 | if (rect().contains(e->pos())) { | ||
38 | if (isToggle) { | ||
39 | emit toggled(isDown); | ||
40 | } | ||
41 | emit clicked(); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | void OClickableLabel::mouseMoveEvent( QMouseEvent *e ) { | ||
46 | if (rect().contains(e->pos())) { | ||
47 | if (isToggle && isDown) { | ||
48 | showState(false); | ||
49 | } else { | ||
50 | showState(true); | ||
51 | } | ||
52 | } else { | ||
53 | if (isToggle && isDown) { | ||
54 | showState(true); | ||
55 | } else { | ||
56 | showState(false); | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | void OClickableLabel::showState(bool on) { | ||
62 | if (on) { | ||
63 | //setFrameShape(Panel); | ||
64 | setInverted(true); | ||
65 | setBackgroundMode(PaletteHighlight); | ||
66 | } else { | ||
67 | //setFrameShape(NoFrame); | ||
68 | setInverted(false); | ||
69 | setBackgroundMode(PaletteBackground); | ||
70 | } | ||
71 | repaint(); | ||
72 | } | ||
73 | |||
74 | void OClickableLabel::setInverted(bool on) { | ||
75 | if ( (!textInverted && on) || (textInverted && !on) ) { | ||
76 | QPalette pal=palette(); | ||
77 | QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground); | ||
78 | col.setRgb(255-col.red(),255-col.green(),255-col.blue()); | ||
79 | pal.setColor(QPalette::Normal, QColorGroup::Foreground, col); | ||
80 | setPalette(pal); | ||
81 | textInverted=!textInverted; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void OClickableLabel::setOn(bool on) { | ||
86 | isDown=on; | ||
87 | showState(isDown); | ||
88 | } | ||
diff --git a/libopie/oclickablelabel.h b/libopie/oclickablelabel.h new file mode 100644 index 0000000..f65c440 --- a/dev/null +++ b/libopie/oclickablelabel.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef CLICKABLELABEL | ||
2 | #define CLICKABLELABEL | ||
3 | |||
4 | #include <qlabel.h> | ||
5 | |||
6 | class OClickableLabel: public QLabel | ||
7 | { | ||
8 | Q_OBJECT | ||
9 | public: | ||
10 | OClickableLabel(QWidget* parent = 0, const char* name = 0, | ||
11 | WFlags fl = 0); | ||
12 | void setToggleButton(bool t); | ||
13 | protected: | ||
14 | void mousePressEvent( QMouseEvent *e ); | ||
15 | void mouseReleaseEvent( QMouseEvent *e ); | ||
16 | void mouseMoveEvent( QMouseEvent *e ); | ||
17 | public slots: | ||
18 | void setOn(bool on); | ||
19 | signals: | ||
20 | void clicked(); | ||
21 | void toggled(bool on); | ||
22 | private: | ||
23 | bool isToggle; | ||
24 | bool isDown; | ||
25 | void showState(bool on); | ||
26 | bool textInverted; | ||
27 | void setInverted(bool on); | ||
28 | }; | ||
29 | |||
30 | #endif | ||