• 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
pushbutton.cpp
Go to the documentation of this file.
1 /*
2  * pushbutton.cpp - push button with read-only option
3  * Program: kalarm
4  * Copyright © 2002,2005,2009 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 "pushbutton.moc"
22 
23 #include <QMouseEvent>
24 #include <QKeyEvent>
25 
26 
27 PushButton::PushButton(QWidget* parent)
28  : KPushButton(parent),
29  mFocusPolicy(focusPolicy()),
30  mReadOnly(false),
31  mNoHighlight(false)
32 { }
33 
34 PushButton::PushButton(const KGuiItem& text, QWidget* parent)
35  : KPushButton(text, parent),
36  mFocusPolicy(focusPolicy()),
37  mReadOnly(false),
38  mNoHighlight(false)
39 { }
40 
41 PushButton::PushButton(const QString& text, QWidget* parent)
42  : KPushButton(text, parent),
43  mFocusPolicy(focusPolicy()),
44  mReadOnly(false),
45  mNoHighlight(false)
46 { }
47 
48 PushButton::PushButton(const KIcon& icon, const QString& text, QWidget* parent)
49  : KPushButton(icon, text, parent),
50  mFocusPolicy(focusPolicy()),
51  mReadOnly(false),
52  mNoHighlight(false)
53 { }
54 
55 void PushButton::setReadOnly(bool ro, bool noHighlight)
56 {
57  mNoHighlight = noHighlight;
58  if ((int)ro != (int)mReadOnly)
59  {
60  mReadOnly = ro;
61  setFocusPolicy(ro ? Qt::NoFocus : mFocusPolicy);
62  if (ro)
63  clearFocus();
64  }
65 }
66 
67 void PushButton::mousePressEvent(QMouseEvent* e)
68 {
69  if (mReadOnly)
70  {
71  // Swallow up the event if it's the left button
72  if (e->button() == Qt::LeftButton)
73  return;
74  }
75  KPushButton::mousePressEvent(e);
76 }
77 
78 void PushButton::mouseReleaseEvent(QMouseEvent* e)
79 {
80  if (mReadOnly)
81  {
82  // Swallow up the event if it's the left button
83  if (e->button() == Qt::LeftButton)
84  return;
85  }
86  KPushButton::mouseReleaseEvent(e);
87 }
88 
89 void PushButton::mouseMoveEvent(QMouseEvent* e)
90 {
91  if (!mReadOnly)
92  KPushButton::mouseMoveEvent(e);
93 }
94 
95 void PushButton::keyPressEvent(QKeyEvent* e)
96 {
97  if (mReadOnly)
98  {
99  switch (e->key())
100  {
101  case Qt::Key_Up:
102  case Qt::Key_Left:
103  case Qt::Key_Right:
104  case Qt::Key_Down:
105  // Process keys which shift the focus
106  break;
107  default:
108  return;
109  }
110  }
111  KPushButton::keyPressEvent(e);
112 }
113 
114 void PushButton::keyReleaseEvent(QKeyEvent* e)
115 {
116  if (!mReadOnly)
117  KPushButton::keyReleaseEvent(e);
118 }
119 
120 bool PushButton::event(QEvent* e)
121 {
122  if (mReadOnly && mNoHighlight)
123  {
124  // Don't highlight the button on mouse hover
125  if (e->type() == QEvent::HoverEnter)
126  return true;
127  }
128  return KPushButton::event(e);
129 }
130 
131 // vim: et sw=4:
KPushButton
text
virtual QByteArray text(quint32 serialNumber) const =0
QWidget
PushButton::setReadOnly
virtual void setReadOnly(bool readOnly, bool noHighlight=false)
Sets whether the push button is read-only for the user.
Definition: pushbutton.cpp:55
PushButton::event
virtual bool event(QEvent *)
Definition: pushbutton.cpp:120
PushButton::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: pushbutton.cpp:78
PushButton::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: pushbutton.cpp:67
PushButton::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: pushbutton.cpp:89
PushButton::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: pushbutton.cpp:95
PushButton::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *)
Definition: pushbutton.cpp:114
PushButton::PushButton
PushButton(QWidget *parent)
Constructor.
Definition: pushbutton.cpp:27
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