kalarm/lib

pushbutton.cpp
1/*
2 * pushbutton.cpp - push button with read-only option
3 * Program: kalarm
4 * Copyright (c) 2002 by David Jarvie <software@astrojar.org.uk>
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
24PushButton::PushButton(TQWidget* parent, const char* name)
25 : TQPushButton(parent, name),
26 mFocusPolicy(focusPolicy()),
27 mReadOnly(false)
28{ }
29
30PushButton::PushButton(const TQString& text, TQWidget* parent, const char* name)
31 : TQPushButton(text, parent, name),
32 mFocusPolicy(focusPolicy()),
33 mReadOnly(false)
34{ }
35
36PushButton::PushButton(const TQIconSet& icon, const TQString& text, TQWidget* parent, const char* name)
37 : TQPushButton(icon, text, parent, name),
38 mFocusPolicy(focusPolicy()),
39 mReadOnly(false)
40{ }
41
43{
44 if ((int)ro != (int)mReadOnly)
45 {
46 mReadOnly = ro;
47 setFocusPolicy(ro ? TQWidget::NoFocus : mFocusPolicy);
48 if (ro)
49 clearFocus();
50 }
51}
52
53void PushButton::mousePressEvent(TQMouseEvent* e)
54{
55 if (mReadOnly)
56 {
57 // Swallow up the event if it's the left button
58 if (e->button() == TQt::LeftButton)
59 return;
60 }
61 TQPushButton::mousePressEvent(e);
62}
63
64void PushButton::mouseReleaseEvent(TQMouseEvent* e)
65{
66 if (mReadOnly)
67 {
68 // Swallow up the event if it's the left button
69 if (e->button() == TQt::LeftButton)
70 return;
71 }
72 TQPushButton::mouseReleaseEvent(e);
73}
74
75void PushButton::mouseMoveEvent(TQMouseEvent* e)
76{
77 if (!mReadOnly)
78 TQPushButton::mouseMoveEvent(e);
79}
80
81void PushButton::keyPressEvent(TQKeyEvent* e)
82{
83 if (mReadOnly)
84 switch (e->key())
85 {
86 case TQt::Key_Up:
87 case TQt::Key_Left:
88 case TQt::Key_Right:
89 case TQt::Key_Down:
90 // Process keys which shift the focus
91 break;
92 default:
93 return;
94 }
95 TQPushButton::keyPressEvent(e);
96}
97
98void PushButton::keyReleaseEvent(TQKeyEvent* e)
99{
100 if (!mReadOnly)
101 TQPushButton::keyReleaseEvent(e);
102}
virtual void setReadOnly(bool readOnly)
Sets whether the push button is read-only for the user.
Definition: pushbutton.cpp:42
PushButton(TQWidget *parent, const char *name=0)
Constructor.
Definition: pushbutton.cpp:24