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

kalarm/lib

radiobutton.cpp

Go to the documentation of this file.
00001 /*
00002  *  radiobutton.cpp  -  radio button with read-only option
00003  *  Program:  kalarm
00004  *  Copyright (c) 2002, 2003, 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 #include "radiobutton.moc"
00024 
00025 
00026 RadioButton::RadioButton(QWidget* parent)
00027     : QRadioButton(parent),
00028       mFocusPolicy(focusPolicy()),
00029       mFocusWidget(0),
00030       mReadOnly(false)
00031 { }
00032 
00033 RadioButton::RadioButton(const QString& text, QWidget* parent)
00034     : QRadioButton(text, parent),
00035       mFocusPolicy(focusPolicy()),
00036       mFocusWidget(0),
00037       mReadOnly(false)
00038 { }
00039 
00040 /******************************************************************************
00041 *  Set the read-only status. If read-only, the button can be toggled by the
00042 *  application, but not by the user.
00043 */
00044 void RadioButton::setReadOnly(bool ro)
00045 {
00046     if ((int)ro != (int)mReadOnly)
00047     {
00048         mReadOnly = ro;
00049         setFocusPolicy(ro ? Qt::NoFocus : mFocusPolicy);
00050         if (ro)
00051             clearFocus();
00052     }
00053 }
00054 
00055 /******************************************************************************
00056 *  Specify a widget to receive focus when the button is clicked on.
00057 */
00058 void RadioButton::setFocusWidget(QWidget* w, bool enable)
00059 {
00060     mFocusWidget = w;
00061     mFocusWidgetEnable = enable;
00062     if (w)
00063         connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
00064     else
00065         disconnect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
00066 }
00067 
00068 /******************************************************************************
00069 *  Called when the button is clicked.
00070 *  If it is now checked, focus is transferred to any specified focus widget.
00071 */
00072 void RadioButton::slotClicked()
00073 {
00074     if (mFocusWidget  &&  isChecked())
00075     {
00076         if (mFocusWidgetEnable)
00077             mFocusWidget->setEnabled(true);
00078         mFocusWidget->setFocus();
00079     }
00080 }
00081 
00082 /******************************************************************************
00083 *  Event handlers to intercept events if in read-only mode.
00084 *  Any events which could change the button state are discarded.
00085 */
00086 void RadioButton::mousePressEvent(QMouseEvent* e)
00087 {
00088     if (mReadOnly)
00089     {
00090         // Swallow up the event if it's the left button
00091         if (e->button() == Qt::LeftButton)
00092             return;
00093     }
00094     QRadioButton::mousePressEvent(e);
00095 }
00096 
00097 void RadioButton::mouseReleaseEvent(QMouseEvent* e)
00098 {
00099     if (mReadOnly)
00100     {
00101         // Swallow up the event if it's the left button
00102         if (e->button() == Qt::LeftButton)
00103             return;
00104     }
00105     QRadioButton::mouseReleaseEvent(e);
00106 }
00107 
00108 void RadioButton::mouseMoveEvent(QMouseEvent* e)
00109 {
00110     if (!mReadOnly)
00111         QRadioButton::mouseMoveEvent(e);
00112 }
00113 
00114 void RadioButton::keyPressEvent(QKeyEvent* e)
00115 {
00116     if (mReadOnly)
00117         switch (e->key())
00118         {
00119             case Qt::Key_Up:
00120             case Qt::Key_Left:
00121             case Qt::Key_Right:
00122             case Qt::Key_Down:
00123                 // Process keys which shift the focus
00124             case Qt::Key_Escape:
00125                 break;
00126             default:
00127                 return;
00128         }
00129     QRadioButton::keyPressEvent(e);
00130 }
00131 
00132 void RadioButton::keyReleaseEvent(QKeyEvent* e)
00133 {
00134     if (!mReadOnly)
00135         QRadioButton::keyReleaseEvent(e);
00136 }

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
  •   doc
  • 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