summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro4
-rw-r--r--libopie/oclickablelabel.cpp88
-rw-r--r--libopie/oclickablelabel.h30
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 @@
TEMPLATE = lib
CONFIG += qte warn_on release
-HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h
-SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp
+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
+SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp
TARGET = opie
INCLUDEPATH += $(OPIEDIR)/include
DESTDIR = $(QTDIR)/lib$(PROJMAK)
#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 @@
+#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);
+}
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 @@
+#ifndef CLICKABLELABEL
+#define CLICKABLELABEL
+
+#include <qlabel.h>
+
+class OClickableLabel: public QLabel
+{
+ Q_OBJECT
+public:
+ OClickableLabel(QWidget* parent = 0, const char* name = 0,
+ WFlags fl = 0);
+ void setToggleButton(bool t);
+ protected:
+ void mousePressEvent( QMouseEvent *e );
+ void mouseReleaseEvent( QMouseEvent *e );
+ void mouseMoveEvent( QMouseEvent *e );
+ public slots:
+ void setOn(bool on);
+ signals:
+ void clicked();
+ void toggled(bool on);
+ private:
+ bool isToggle;
+ bool isDown;
+ void showState(bool on);
+ bool textInverted;
+ void setInverted(bool on);
+};
+
+#endif