Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oclickablelabel.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include <opie2/oclickablelabel.h>
00031 
00032 using namespace Opie::Ui;
00033 
00041 OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl)
00042                 :QLabel(parent,name,fl)
00043 {
00044     textInverted=false;
00045     isToggle=false;
00046     isDown=false;
00047     showState(false);
00048     setFrameShadow(Sunken);
00049 }
00050 
00056 void OClickableLabel::setToggleButton(bool t)
00057 {
00058     isToggle=t;
00059 }
00060 
00064 void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ )
00065 {
00066     if (isToggle && isDown)
00067     {
00068         showState(false);
00069     }
00070     else
00071     {
00072         showState(true);
00073     }
00074 }
00075 
00079 void OClickableLabel::mouseReleaseEvent( QMouseEvent *e )
00080 {
00081     if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
00082 
00083     if (isToggle && isDown)
00084     {
00085         showState(true);
00086     }
00087     else
00088     {
00089         showState(false);
00090     }
00091 
00092     if (rect().contains(e->pos()))
00093     {
00094         if (isToggle)
00095         {
00096             emit toggled(isDown);
00097         }
00098         emit clicked();
00099     }
00100 }
00101 
00105 void OClickableLabel::mouseMoveEvent( QMouseEvent *e )
00106 {
00107     if (rect().contains(e->pos()))
00108     {
00109         if (isToggle && isDown)
00110         {
00111             showState(false);
00112         }
00113         else
00114         {
00115             showState(true);
00116         }
00117     }
00118     else
00119     {
00120         if (isToggle && isDown)
00121         {
00122             showState(true);
00123         }
00124         else
00125         {
00126             showState(false);
00127         }
00128     }
00129 }
00130 
00136 void OClickableLabel::showState(bool on)
00137 {
00138     if (on)
00139     {
00140         //setFrameShape(Panel);
00141         setInverted(true);
00142         setBackgroundMode(PaletteHighlight);
00143     }
00144     else
00145     {
00146         //setFrameShape(NoFrame);
00147         setInverted(false);
00148         setBackgroundMode(PaletteBackground);
00149     }
00150     repaint();
00151 }
00152 
00153 void OClickableLabel::setInverted(bool on)
00154 {
00155     if ( (!textInverted && on) || (textInverted && !on) )
00156     {
00157         QPalette pal=palette();
00158         QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
00159         col.setRgb(255-col.red(),255-col.green(),255-col.blue());
00160         pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
00161         setPalette(pal);
00162         textInverted=!textInverted;
00163     }
00164 }
00165 
00169 void OClickableLabel::setOn(bool on)
00170 {
00171     isDown=on;
00172     showState(isDown);
00173 }

Generated on Sat Nov 5 16:16:25 2005 for OPIE by  doxygen 1.4.2