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

kalarm/lib

label.cpp

Go to the documentation of this file.
00001 /*
00002  *  label.cpp  -  label with radiobutton buddy option
00003  *  Program:  kalarm
00004  *  Copyright (c) 2004, 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 "kalarm.h"
00022 #include <QRadioButton>
00023 #include "label.moc"
00024 
00025 
00026 Label::Label(QWidget* parent, Qt::WFlags f)
00027     : QLabel(parent, f),
00028       mRadioButton(0),
00029       mFocusWidget(0)
00030 { }
00031 
00032 Label::Label(const QString& text, QWidget* parent, Qt::WFlags f)
00033     : QLabel(text, parent, f),
00034       mRadioButton(0),
00035       mFocusWidget(0)
00036 { }
00037 
00038 Label::Label(QWidget* buddy, const QString& text, QWidget* parent, Qt::WFlags f)
00039     : QLabel(text, parent, f),
00040       mRadioButton(0),
00041       mFocusWidget(0)
00042 {
00043     setBuddy(buddy);
00044 }
00045 
00046 /******************************************************************************
00047 * Set a buddy widget.
00048 * If it (or its focus proxy) is a radio button, create a focus widget.
00049 * When the accelerator key is pressed, the focus widget then receives focus.
00050 * That event triggers the selection of the radio button.
00051 */
00052 void Label::setBuddy(QWidget* bud)
00053 {
00054     if (mRadioButton)
00055         disconnect(mRadioButton, SIGNAL(destroyed()), this, SLOT(buddyDead()));
00056     QWidget* w = bud;
00057     if (w)
00058     {
00059         while (w->focusProxy())
00060             w = w->focusProxy();
00061         if (!qobject_cast<QRadioButton*>(w))
00062             w = 0;
00063     }
00064     if (!w)
00065     {
00066         // The buddy widget isn't a radio button
00067         QLabel::setBuddy(bud);
00068         delete mFocusWidget;
00069         mFocusWidget = 0;
00070         mRadioButton = 0;
00071     }
00072     else
00073     {
00074         // The buddy widget is a radio button, so set a different buddy
00075         if (!mFocusWidget)
00076             mFocusWidget = new LabelFocusWidget(this);
00077         QLabel::setBuddy(mFocusWidget);
00078         mRadioButton = (QRadioButton*)bud;
00079         connect(mRadioButton, SIGNAL(destroyed()), this, SLOT(buddyDead()));
00080     }
00081 }
00082 
00083 void Label::buddyDead()
00084 {
00085     delete mFocusWidget;
00086     mFocusWidget = 0;
00087     mRadioButton = 0;
00088 }
00089 
00090 /******************************************************************************
00091 * Called when focus is transferred to the label's special focus widget.
00092 * Transfer focus to the radio button and select it.
00093 */
00094 void Label::activated()
00095 {
00096     if (mFocusWidget  &&  mRadioButton)
00097     {
00098         mRadioButton->setFocus();
00099         mRadioButton->setChecked(true);
00100     }
00101 }
00102 
00103 
00104 /*=============================================================================
00105 * Class: LabelFocusWidget
00106 =============================================================================*/
00107 
00108 LabelFocusWidget::LabelFocusWidget(QWidget* parent)
00109     : QWidget(parent)
00110 {
00111     setFocusPolicy(Qt::ClickFocus);
00112     setFixedSize(QSize(1,1));
00113 }
00114 
00115 void LabelFocusWidget::focusInEvent(QFocusEvent*)
00116 {
00117     Label* parent = (Label*)parentWidget();
00118     parent->activated();
00119 
00120 }

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