• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kalarm/lib

pushbutton.cpp

Go to the documentation of this file.
00001 /*
00002  *  pushbutton.cpp  -  push button with read-only option
00003  *  Program:  kalarm
00004  *  Copyright (c) 2002, 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <QMouseEvent>
00022 #include <QKeyEvent>
00023 
00024 #include "pushbutton.moc"
00025 
00026 
00027 PushButton::PushButton(QWidget* parent)
00028     : QPushButton(parent),
00029       mFocusPolicy(focusPolicy()),
00030       mReadOnly(false)
00031 { }
00032 
00033 PushButton::PushButton(const QString& text, QWidget* parent)
00034     : QPushButton(text, parent),
00035       mFocusPolicy(focusPolicy()),
00036       mReadOnly(false)
00037 { }
00038 
00039 PushButton::PushButton(const QIcon& icon, const QString& text, QWidget* parent)
00040     : QPushButton(icon, text, parent),
00041       mFocusPolicy(focusPolicy()),
00042       mReadOnly(false)
00043 { }
00044 
00045 void PushButton::setReadOnly(bool ro)
00046 {
00047     if ((int)ro != (int)mReadOnly)
00048     {
00049         mReadOnly = ro;
00050         setFocusPolicy(ro ? Qt::NoFocus : mFocusPolicy);
00051         if (ro)
00052             clearFocus();
00053     }
00054 }
00055 
00056 void PushButton::mousePressEvent(QMouseEvent* e)
00057 {
00058     if (mReadOnly)
00059     {
00060         // Swallow up the event if it's the left button
00061         if (e->button() == Qt::LeftButton)
00062             return;
00063     }
00064     QPushButton::mousePressEvent(e);
00065 }
00066 
00067 void PushButton::mouseReleaseEvent(QMouseEvent* e)
00068 {
00069     if (mReadOnly)
00070     {
00071         // Swallow up the event if it's the left button
00072         if (e->button() == Qt::LeftButton)
00073             return;
00074     }
00075     QPushButton::mouseReleaseEvent(e);
00076 }
00077 
00078 void PushButton::mouseMoveEvent(QMouseEvent* e)
00079 {
00080     if (!mReadOnly)
00081         QPushButton::mouseMoveEvent(e);
00082 }
00083 
00084 void PushButton::keyPressEvent(QKeyEvent* e)
00085 {
00086     if (mReadOnly)
00087         switch (e->key())
00088         {
00089             case Qt::Key_Up:
00090             case Qt::Key_Left:
00091             case Qt::Key_Right:
00092             case Qt::Key_Down:
00093                 // Process keys which shift the focus
00094                 break;
00095             default:
00096                 return;
00097         }
00098     QPushButton::keyPressEvent(e);
00099 }
00100 
00101 void PushButton::keyReleaseEvent(QKeyEvent* e)
00102 {
00103     if (!mReadOnly)
00104         QPushButton::keyReleaseEvent(e);
00105 }

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal