• 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
checkbox.cpp
Go to the documentation of this file.
1 /*
2  * checkbox.cpp - check box with read-only option
3  * Program: kalarm
4  * Copyright © 2002,2003,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 "checkbox.moc"
22 #include <QMouseEvent>
23 #include <QKeyEvent>
24 
25 
26 CheckBox::CheckBox(QWidget* parent)
27  : QCheckBox(parent),
28  mFocusPolicy(focusPolicy()),
29  mFocusWidget(0),
30  mReadOnly(false)
31 { }
32 
33 CheckBox::CheckBox(const QString& text, QWidget* parent)
34  : QCheckBox(text, parent),
35  mFocusPolicy(focusPolicy()),
36  mFocusWidget(0),
37  mReadOnly(false)
38 { }
39 
40 /******************************************************************************
41 * Set the read-only status. If read-only, the checkbox can be toggled by the
42 * application, but not by the user.
43 */
44 void CheckBox::setReadOnly(bool ro)
45 {
46  if ((int)ro != (int)mReadOnly)
47  {
48  mReadOnly = ro;
49  setFocusPolicy(ro ? Qt::NoFocus : mFocusPolicy);
50  if (ro)
51  clearFocus();
52  }
53 }
54 
55 /******************************************************************************
56 * Specify a widget to receive focus when the checkbox is clicked on.
57 */
58 void CheckBox::setFocusWidget(QWidget* w, bool enable)
59 {
60  mFocusWidget = w;
61  mFocusWidgetEnable = enable;
62  if (w)
63  connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
64  else
65  disconnect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
66 }
67 
68 /******************************************************************************
69 * Called when the checkbox is clicked.
70 * If it is now checked, focus is transferred to any specified focus widget.
71 */
72 void CheckBox::slotClicked()
73 {
74  if (mFocusWidget && isChecked())
75  {
76  if (mFocusWidgetEnable)
77  mFocusWidget->setEnabled(true);
78  mFocusWidget->setFocus();
79  }
80 }
81 
82 /******************************************************************************
83 * Event handlers to intercept events if in read-only mode.
84 * Any events which could change the checkbox state are discarded.
85 */
86 void CheckBox::mousePressEvent(QMouseEvent* e)
87 {
88  if (mReadOnly)
89  {
90  // Swallow up the event if it's the left button
91  if (e->button() == Qt::LeftButton)
92  return;
93  }
94  QCheckBox::mousePressEvent(e);
95 }
96 
97 void CheckBox::mouseReleaseEvent(QMouseEvent* e)
98 {
99  if (mReadOnly)
100  {
101  // Swallow up the event if it's the left button
102  if (e->button() == Qt::LeftButton)
103  return;
104  }
105  QCheckBox::mouseReleaseEvent(e);
106 }
107 
108 void CheckBox::mouseMoveEvent(QMouseEvent* e)
109 {
110  if (!mReadOnly)
111  QCheckBox::mouseMoveEvent(e);
112 }
113 
114 void CheckBox::keyPressEvent(QKeyEvent* e)
115 {
116  if (mReadOnly)
117  {
118  switch (e->key())
119  {
120  case Qt::Key_Up:
121  case Qt::Key_Left:
122  case Qt::Key_Right:
123  case Qt::Key_Down:
124  // Process keys which shift the focus
125  break;
126  default:
127  return;
128  }
129  }
130  QCheckBox::keyPressEvent(e);
131 }
132 
133 void CheckBox::keyReleaseEvent(QKeyEvent* e)
134 {
135  if (!mReadOnly)
136  QCheckBox::keyReleaseEvent(e);
137 }
138 
139 // vim: et sw=4:
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
Sets whether the check box is read-only for the user.
Definition: checkbox.cpp:44
CheckBox::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: checkbox.cpp:114
text
virtual QByteArray text(quint32 serialNumber) const =0
CheckBox::setFocusWidget
void setFocusWidget(QWidget *widget, bool enable=true)
Specifies a widget to receive focus when the user selects the check box by clicking on it...
Definition: checkbox.cpp:58
QWidget
CheckBox::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: checkbox.cpp:108
CheckBox::slotClicked
void slotClicked()
Definition: checkbox.cpp:72
CheckBox::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *)
Definition: checkbox.cpp:133
CheckBox::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: checkbox.cpp:97
QCheckBox
CheckBox::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: checkbox.cpp:86
CheckBox::CheckBox
CheckBox(QWidget *parent)
Constructor.
Definition: checkbox.cpp:26
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