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

kalarm/lib

  • sources
  • kde-4.12
  • kdepim
  • kalarm
  • lib
label.cpp
Go to the documentation of this file.
1 /*
2  * label.cpp - label with radiobutton buddy option
3  * Program: kalarm
4  * Copyright © 2004,2005 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "label.moc"
23 #include <QRadioButton>
24 
25 
26 Label::Label(QWidget* parent, Qt::WindowFlags f)
27  : QLabel(parent, f),
28  mRadioButton(0),
29  mFocusWidget(0)
30 { }
31 
32 Label::Label(const QString& text, QWidget* parent, Qt::WindowFlags f)
33  : QLabel(text, parent, f),
34  mRadioButton(0),
35  mFocusWidget(0)
36 { }
37 
38 Label::Label(QWidget* buddy, const QString& text, QWidget* parent, Qt::WindowFlags f)
39  : QLabel(text, parent, f),
40  mRadioButton(0),
41  mFocusWidget(0)
42 {
43  setBuddy(buddy);
44 }
45 
46 /******************************************************************************
47 * Set a buddy widget.
48 * If it (or its focus proxy) is a radio button, create a focus widget.
49 * When the accelerator key is pressed, the focus widget then receives focus.
50 * That event triggers the selection of the radio button.
51 */
52 void Label::setBuddy(QWidget* bud)
53 {
54  if (mRadioButton)
55  disconnect(mRadioButton, SIGNAL(destroyed()), this, SLOT(buddyDead()));
56  QWidget* w = bud;
57  if (w)
58  {
59  while (w->focusProxy())
60  w = w->focusProxy();
61  if (!qobject_cast<QRadioButton*>(w))
62  w = 0;
63  }
64  if (!w)
65  {
66  // The buddy widget isn't a radio button
67  QLabel::setBuddy(bud);
68  delete mFocusWidget;
69  mFocusWidget = 0;
70  mRadioButton = 0;
71  }
72  else
73  {
74  // The buddy widget is a radio button, so set a different buddy
75  if (!mFocusWidget)
76  mFocusWidget = new LabelFocusWidget(this);
77  QLabel::setBuddy(mFocusWidget);
78  mRadioButton = (QRadioButton*)bud;
79  connect(mRadioButton, SIGNAL(destroyed()), this, SLOT(buddyDead()));
80  }
81 }
82 
83 void Label::buddyDead()
84 {
85  delete mFocusWidget;
86  mFocusWidget = 0;
87  mRadioButton = 0;
88 }
89 
90 /******************************************************************************
91 * Called when focus is transferred to the label's special focus widget.
92 * Transfer focus to the radio button and select it.
93 */
94 void Label::activated()
95 {
96  if (mFocusWidget && mRadioButton)
97  {
98  mRadioButton->setFocus();
99  mRadioButton->setChecked(true);
100  }
101 }
102 
103 
104 /*=============================================================================
105 * Class: LabelFocusWidget
106 =============================================================================*/
107 
108 LabelFocusWidget::LabelFocusWidget(QWidget* parent)
109  : QWidget(parent)
110 {
111  setFocusPolicy(Qt::ClickFocus);
112  setFixedSize(QSize(1,1));
113 }
114 
115 void LabelFocusWidget::focusInEvent(QFocusEvent*)
116 {
117  Label* parent = (Label*)parentWidget();
118  parent->activated();
119 
120 }
121 
122 // vim: et sw=4:
Label::setBuddy
virtual void setBuddy(QWidget *buddy)
Sets the label's buddy widget which receives the keyboard focus when the label's accelerator key is p...
Definition: label.cpp:52
text
virtual QByteArray text(quint32 serialNumber) const =0
QWidget
Label::Label
Label(QWidget *parent, Qt::WindowFlags f=0)
Constructs an empty label.
Definition: label.cpp:26
QRadioButton
Label
A QLabel with option for a buddy radio button.
Definition: label.h:42
Label::LabelFocusWidget
friend class LabelFocusWidget
Definition: label.h:45
QLabel
LabelFocusWidget::LabelFocusWidget
LabelFocusWidget(QWidget *parent)
Definition: label.cpp:108
LabelFocusWidget::focusInEvent
virtual void focusInEvent(QFocusEvent *)
Definition: label.cpp:115
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal