Back to index

kdeartwork  4.3.2
StickyButton.cpp
Go to the documentation of this file.
00001 /*
00002   RISC OS KWin client
00003   
00004   Copyright 2000
00005     Rik Hemsley <rik@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; see the file COPYING.  If not, write to
00019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020   Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "StickyButton.h"
00024 
00025 #include <qtooltip.h>
00026 //Added by qt3to4:
00027 #include <QPixmap>
00028 #include <QMouseEvent>
00029 
00030 namespace RiscOS
00031 {
00032 
00033 /* XPM */
00034 static const char * const unsticky_xpm[] = {
00035 "12 12 3 1",
00036 "      c None",
00037 ".     c #000000",
00038 "+     c #FFFFFF",
00039 "    ...     ",
00040 "   .+++.    ",
00041 "   .+++.    ",
00042 "   .+++.    ",
00043 "   .+++.    ",
00044 "  .+++++.   ",
00045 " .+++++++.  ",
00046 ".+++++++++. ",
00047 ".....+..... ",
00048 "    .+.     ",
00049 "    .+.     ",
00050 "     .      "};
00051 
00052 /* XPM */
00053 static const char * const sticky_xpm[] = {
00054 "12 12 3 1",
00055 "      c None",
00056 ".     c #000000",
00057 "+     c #FFFFFF",
00058 "        .   ",
00059 "       .+.  ",
00060 "      .+++. ",
00061 "     .+++++.",
00062 " ....+++++. ",
00063 "  .++++++.  ",
00064 "   .++++.   ",
00065 "   .+++.    ",
00066 "  .+..+.    ",
00067 " .+.  ..    ",
00068 ".+.    .    ",
00069 "..          "};
00070 
00071 
00072 StickyButton::StickyButton(QWidget *parent)
00073   : Button(parent, i18n("On all desktops")), on_(false)
00074 {
00075    setPixmap(QPixmap((const char **)sticky_xpm));
00076 }
00077 
00078 void StickyButton::setOn(bool on)
00079 {
00080    on_ = on;
00081    setPixmap(on_ ? QPixmap((const char **)unsticky_xpm) :
00082                    QPixmap((const char **)sticky_xpm));
00083    repaint();
00084    QToolTip::remove(this);
00085    this->setToolTip( on_ ? i18n("Not on all desktops")
00086                            : i18n("On all desktops"));
00087 }
00088 
00089 void StickyButton::mouseReleaseEvent(QMouseEvent *e)
00090 {
00091    Button::mouseReleaseEvent(e);
00092 
00093    if (!rect().contains(e->pos()))
00094       return;
00095 
00096    emit(toggleSticky());   
00097 }
00098 
00099 } // End namespace
00100 
00101 // vim:ts=2:sw=2:tw=78
00102 #include "StickyButton.moc"