kalarm/lib

spinbox2.h
1/*
2 * spinbox2.h - spin box with extra pair of spin buttons (for TQt 3)
3 * Program: kalarm
4 * Copyright © 2001-2007 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#ifndef SPINBOX2_H
22#define SPINBOX2_H
23
24#include <tqglobal.h>
25#include <tqlineedit.h>
26
27class SpinMirror;
28class ExtraSpinBox;
29#include "spinbox.h"
30
31
56class SpinBox2 : public TQFrame
57{
58 TQ_OBJECT
59
60 public:
65 explicit SpinBox2(TQWidget* parent = 0, const char* name = 0);
74 SpinBox2(int minValue, int maxValue, int step = 1, int step2 = 1,
75 TQWidget* parent = 0, const char* name = 0);
79 virtual void setReadOnly(bool readOnly);
81 bool isReadOnly() const { return mSpinbox->isReadOnly(); }
83 void setSelectOnStep(bool sel) { mSpinbox->setSelectOnStep(sel); }
87 void setReverseWithLayout(bool reverse);
89 bool reverseButtons() const { return mReverseLayout && !mReverseWithLayout; }
90
92 TQString text() const { return mSpinbox->text(); }
94 virtual TQString prefix() const { return mSpinbox->prefix(); }
96 virtual TQString suffix() const { return mSpinbox->suffix(); }
98 virtual TQString cleanText() const { return mSpinbox->cleanText(); }
99
103 virtual void setSpecialValueText(const TQString& text) { mSpinbox->setSpecialValueText(text); }
107 TQString specialValueText() const { return mSpinbox->specialValueText(); }
108
112 virtual void setWrapping(bool on);
116 bool wrapping() const { return mSpinbox->wrapping(); }
117
119 void setAlignment(int a) { mSpinbox->setAlignment(a); }
121 virtual void setButtonSymbols(TQSpinBox::ButtonSymbols);
123 TQSpinBox::ButtonSymbols buttonSymbols() const { return mSpinbox->buttonSymbols(); }
124
128 virtual void setValidator(const TQValidator* v) { mSpinbox->setValidator(v); }
132 const TQValidator* validator() const { return mSpinbox->validator(); }
133
134 virtual TQSize sizeHint() const;
135 virtual TQSize minimumSizeHint() const;
136
138 int minValue() const { return mMinValue; }
140 int maxValue() const { return mMaxValue; }
142 virtual void setMinValue(int val);
144 virtual void setMaxValue(int val);
148 int value() const { return mSpinbox->value(); }
150 int bound(int val) const;
151
153 TQRect upRect() const { return mSpinbox->upRect(); }
155 TQRect downRect() const { return mSpinbox->downRect(); }
157 TQRect up2Rect() const;
159 TQRect down2Rect() const;
160
165 int lineStep() const { return mLineStep; }
170 int lineShiftStep() const { return mLineShiftStep; }
175 int pageStep() const { return mPageStep; }
180 int pageShiftStep() const { return mPageShiftStep; }
185 void setLineStep(int step);
192 void setSteps(int line, int page);
199 void setShiftSteps(int line, int page);
200
204 void addPage() { addValue(mPageStep); }
208 void subtractPage() { addValue(-mPageStep); }
212 void addLine() { addValue(mLineStep); }
216 void subtractLine() { addValue(-mLineStep); }
218 void addValue(int change) { mSpinbox->addValue(change); }
219
220 public slots:
222 virtual void setValue(int val) { mSpinbox->setValue(val); }
224 virtual void setPrefix(const TQString& text) { mSpinbox->setPrefix(text); }
226 virtual void setSuffix(const TQString& text) { mSpinbox->setSuffix(text); }
230 virtual void stepUp() { addValue(mLineStep); }
234 virtual void stepDown() { addValue(-mLineStep); }
238 virtual void pageUp() { addValue(mPageStep); }
242 virtual void pageDown() { addValue(-mPageStep); }
244 virtual void selectAll() { mSpinbox->selectAll(); }
246 virtual void setEnabled(bool enabled);
247
248 signals:
252 void valueChanged(const TQString& valueText);
253
254 protected:
255 virtual TQString mapValueToText(int v) { return mSpinbox->mapValToText(v); }
256 virtual int mapTextToValue(bool* ok) { return mSpinbox->mapTextToVal(ok); }
257 virtual void resizeEvent(TQResizeEvent*) { arrange(); }
258 virtual void showEvent(TQShowEvent*);
259 virtual void styleChange(TQStyle&);
260 virtual void getMetrics() const;
261
262 mutable int wUpdown2; // width of second spin widget
263 mutable int xUpdown2; // x offset of visible area in 'mUpdown2'
264 mutable int xSpinbox; // x offset of visible area in 'mSpinbox'
265 mutable int wGap; // gap between mUpdown2Frame and mSpinboxFrame
266
267 protected slots:
268 virtual void valueChange();
269 virtual void stepPage(int);
270
271 private slots:
272 void updateMirror();
273
274 private:
275 void init();
276 void arrange();
277 int whichButton(TQObject* spinWidget, const TQPoint&);
278 void setShiftStepping(bool on);
279
280 // Visible spin box class.
281 // Declared here to allow use of mSpinBox in inline methods.
282 class MainSpinBox : public SpinBox
283 {
284 public:
285 MainSpinBox(SpinBox2* sb2, TQWidget* parent, const char* name = 0)
286 : SpinBox(parent, name), owner(sb2) { }
287 MainSpinBox(int minValue, int maxValue, int step, SpinBox2* sb2, TQWidget* parent, const char* name = 0)
288 : SpinBox(minValue, maxValue, step, parent, name), owner(sb2) { }
289 void setAlignment(int a) { editor()->setAlignment(a); }
290 virtual TQString mapValueToText(int v) { return owner->mapValueToText(v); }
291 virtual int mapTextToValue(bool* ok) { return owner->mapTextToValue(ok); }
292 TQString mapValToText(int v) { return SpinBox::mapValueToText(v); }
293 int mapTextToVal(bool* ok) { return SpinBox::mapTextToValue(ok); }
294 virtual int shiftStepAdjustment(int oldValue, int shiftStep);
295 private:
296 SpinBox2* owner; // owner SpinBox2
297 };
298
299 enum { NO_BUTTON = -1, UP, DOWN, UP2, DOWN2 };
300
301 static int mReverseLayout; // widgets are mirrored right to left
302 TQFrame* mUpdown2Frame; // contains visible part of the extra pair of spin buttons
303 TQFrame* mSpinboxFrame; // contains the main spin box
304 ExtraSpinBox* mUpdown2; // the extra pair of spin buttons
305 MainSpinBox* mSpinbox; // the visible spin box
306 SpinMirror* mSpinMirror; // image of the extra pair of spin buttons
307 int mMinValue;
308 int mMaxValue;
309 int mLineStep; // right button increment
310 int mLineShiftStep; // right button increment with shift pressed
311 int mPageStep; // left button increment
312 int mPageShiftStep; // left button increment with shift pressed
313 bool mReverseWithLayout; // reverse button positions if reverse layout (default = true)
314
315 friend class MainSpinBox;
316};
317
318#endif // SPINBOX2_H
Spin box with a pair of spin buttons on either side.
Definition: spinbox2.h:57
virtual void setPrefix(const TQString &text)
Sets the prefix which is prepended to the start of the displayed text.
Definition: spinbox2.h:224
TQRect down2Rect() const
Returns the geometry of the left-hand "down" button.
Definition: spinbox2.cpp:136
int pageShiftStep() const
Returns the shifted step increment for the left-hand spin buttons, i.e.
Definition: spinbox2.h:180
void addPage()
Increments the current value by adding the unshifted step increment for the left-hand spin buttons.
Definition: spinbox2.h:204
bool wrapping() const
Returns whether it is possible to step the value from the highest value to the lowest value and vice ...
Definition: spinbox2.h:116
void setAlignment(int a)
Set the text alignment of the widget.
Definition: spinbox2.h:119
int minValue() const
Returns the minimum value of the spin box.
Definition: spinbox2.h:138
virtual void pageDown()
Decrements the current value by subtracting the unshifted step increment for the left-hand spin butto...
Definition: spinbox2.h:242
TQString text() const
Returns the spin box's text, including any prefix() and suffix().
Definition: spinbox2.h:92
void addValue(int change)
Adjusts the current value by adding change.
Definition: spinbox2.h:218
virtual void setValidator(const TQValidator *v)
Sets the validator to v.
Definition: spinbox2.h:128
bool reverseButtons() const
Returns whether the spin button pairs will be reversed for a right-to-left language.
Definition: spinbox2.h:89
void addLine()
Increments the current value by adding the unshifted step increment for the right-hand spin buttons.
Definition: spinbox2.h:212
void valueChanged(int value)
Signal which is emitted whenever the value of the spin box changes.
void setRange(int minValue, int maxValue)
Sets the minimum and maximum values of the spin box.
Definition: spinbox2.h:146
void valueChanged(const TQString &valueText)
Signal which is emitted whenever the value of the spin box changes.
TQSpinBox::ButtonSymbols buttonSymbols() const
Returns the button symbols currently in use (arrows or plus/minus).
Definition: spinbox2.h:123
TQString specialValueText() const
Returns the special-value text which, if non-null, is displayed instead of a numeric value when the c...
Definition: spinbox2.h:107
int bound(int val) const
Returns the specified value clamped to the range of the spin box.
Definition: spinbox2.cpp:190
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
Definition: spinbox2.h:83
virtual TQString suffix() const
Returns the suffix for the spin box's text.
Definition: spinbox2.h:96
TQRect downRect() const
Returns the geometry of the right-hand "down" button.
Definition: spinbox2.h:155
void setSteps(int line, int page)
Sets the unshifted step increments for the two pairs of spin buttons, i.e.
Definition: spinbox2.cpp:150
void setReverseWithLayout(bool reverse)
Sets whether the spin button pairs should be reversed for a right-to-left language.
Definition: spinbox2.cpp:109
int lineStep() const
Returns the unshifted step increment for the right-hand spin buttons, i.e.
Definition: spinbox2.h:165
int maxValue() const
Returns the maximum value of the spin box.
Definition: spinbox2.h:140
void subtractPage()
Decrements the current value by subtracting the unshifted step increment for the left-hand spin butto...
Definition: spinbox2.h:208
bool isReadOnly() const
Returns true if the widget is read only.
Definition: spinbox2.h:81
void setLineStep(int step)
Sets the unshifted step increment for the right-hand spin buttons, i.e.
Definition: spinbox2.cpp:141
virtual void setSpecialValueText(const TQString &text)
Sets the special-value text which, if non-null, is displayed instead of a numeric value when the curr...
Definition: spinbox2.h:103
virtual void setMinValue(int val)
Sets the minimum value of the spin box.
Definition: spinbox2.cpp:195
TQRect up2Rect() const
Returns the geometry of the left-hand "up" button.
Definition: spinbox2.cpp:131
int lineShiftStep() const
Returns the shifted step increment for the right-hand spin buttons, i.e.
Definition: spinbox2.h:170
virtual void setSuffix(const TQString &text)
Sets the suffix which is prepended to the start of the displayed text.
Definition: spinbox2.h:226
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
Definition: spinbox2.cpp:99
virtual void stepDown()
Decrements the current value by subtracting the unshifted step increment for the right-hand spin butt...
Definition: spinbox2.h:234
virtual void pageUp()
Increments the current value by adding the unshifted step increment for the left-hand spin buttons.
Definition: spinbox2.h:238
virtual void setMaxValue(int val)
Sets the maximum value of the spin box.
Definition: spinbox2.cpp:202
virtual TQString cleanText() const
Returns the spin box's text with no prefix(), suffix() or leading or trailing whitespace.
Definition: spinbox2.h:98
const TQValidator * validator() const
Returns the current validator.
Definition: spinbox2.h:132
int pageStep() const
Returns the unshifted step increment for the left-hand spin buttons, i.e.
Definition: spinbox2.h:175
virtual void setWrapping(bool on)
Sets whether it is possible to step the value from the highest value to the lowest value and vice ver...
Definition: spinbox2.cpp:125
SpinBox2(TQWidget *parent=0, const char *name=0)
Constructor.
Definition: spinbox2.cpp:51
TQRect upRect() const
Returns the geometry of the right-hand "up" button.
Definition: spinbox2.h:153
virtual TQString prefix() const
Returns the prefix for the spin box's text.
Definition: spinbox2.h:94
virtual void setButtonSymbols(TQSpinBox::ButtonSymbols)
Sets the button symbols to use (arrows or plus/minus).
Definition: spinbox2.cpp:182
int value() const
Returns the current value of the spin box.
Definition: spinbox2.h:148
virtual void setValue(int val)
Sets the current value to val.
Definition: spinbox2.h:222
virtual void selectAll()
Selects all the text in the spin box's editor.
Definition: spinbox2.h:244
void subtractLine()
Decrements the current value by subtracting the unshifted step increment for the right-hand spin butt...
Definition: spinbox2.h:216
virtual void stepUp()
Increments the current value by adding the unshifted step increment for the right-hand spin buttons.
Definition: spinbox2.h:230
virtual void setEnabled(bool enabled)
Sets whether the widget is enabled.
Definition: spinbox2.cpp:119
void setShiftSteps(int line, int page)
Sets the shifted step increments for the two pairs of spin buttons, i.e.
Definition: spinbox2.cpp:166
Spin box with accelerated shift key stepping and read-only option.
Definition: spinbox.h:43