kalarm/lib

slider.cpp
1/*
2 * slider.cpp - slider control with read-only option
3 * Program: kalarm
4 * Copyright (c) 2004 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 "slider.moc"
22
23
24Slider::Slider(TQWidget* parent, const char* name)
25 : TQSlider(parent, name),
26 mReadOnly(false)
27{ }
28
29Slider::Slider(TQt::Orientation o, TQWidget* parent, const char* name)
30 : TQSlider(o, parent, name),
31 mReadOnly(false)
32{ }
33
34Slider::Slider(int minval, int maxval, int pageStep, int value, TQt::Orientation o, TQWidget* parent, const char* name)
35 : TQSlider(minval, maxval, pageStep, value, o, parent, name),
36 mReadOnly(false)
37{ }
38
39/******************************************************************************
40* Set the read-only status. If read-only, the slider can be moved by the
41* application, but not by the user.
42*/
44{
45 mReadOnly = ro;
46}
47
48/******************************************************************************
49* Event handlers to intercept events if in read-only mode.
50* Any events which could change the slider value are discarded.
51*/
52void Slider::mousePressEvent(TQMouseEvent* e)
53{
54 if (mReadOnly)
55 {
56 // Swallow up the event if it's the left button
57 if (e->button() == TQt::LeftButton)
58 return;
59 }
60 TQSlider::mousePressEvent(e);
61}
62
63void Slider::mouseReleaseEvent(TQMouseEvent* e)
64{
65 if (!mReadOnly)
66 TQSlider::mouseReleaseEvent(e);
67}
68
69void Slider::mouseMoveEvent(TQMouseEvent* e)
70{
71 if (!mReadOnly)
72 TQSlider::mouseMoveEvent(e);
73}
74
75void Slider::keyPressEvent(TQKeyEvent* e)
76{
77 if (!mReadOnly || e->key() == TQt::Key_Escape)
78 TQSlider::keyPressEvent(e);
79}
80
81void Slider::keyReleaseEvent(TQKeyEvent* e)
82{
83 if (!mReadOnly)
84 TQSlider::keyReleaseEvent(e);
85}
virtual void setReadOnly(bool readOnly)
Sets whether the slider is read-only for the user.
Definition: slider.cpp:43
Slider(TQWidget *parent=0, const char *name=0)
Constructor.
Definition: slider.cpp:24