author | hakan <hakan> | 2002-05-07 10:43:49 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-05-07 10:43:49 (UTC) |
commit | cfe30703da090180b66bc571e85654c71a7ee8e0 (patch) (side-by-side diff) | |
tree | d6954140f2208becb9a6beb5b8a21529bfd5bceb /libopie/oclickablelabel.cpp | |
parent | c9849cc04b668f1cda7a16d868299c436d1de042 (diff) | |
download | opie-cfe30703da090180b66bc571e85654c71a7ee8e0.zip opie-cfe30703da090180b66bc571e85654c71a7ee8e0.tar.gz opie-cfe30703da090180b66bc571e85654c71a7ee8e0.tar.bz2 |
Moved ClickableLabel to libopie/OClickableLabel
-rw-r--r-- | libopie/oclickablelabel.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
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); +} |