kalarm/lib

spinbox.h
1 /*
2  * spinbox.h - spin box with shift-click step value and read-only option
3  * Program: kalarm
4  * Copyright © 2002-2006,2008 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 #ifndef SPINBOX_H
22 #define SPINBOX_H
23 
24 #include <tqspinbox.h>
25 
26 
42 class SpinBox : public TQSpinBox
43 {
44  TQ_OBJECT
45 
46  public:
51  explicit SpinBox(TQWidget* parent = 0, const char* name = 0);
59  SpinBox(int minValue, int maxValue, int step = 1, TQWidget* parent = 0, const char* name = 0);
61  bool isReadOnly() const { return mReadOnly; }
65  virtual void setReadOnly(bool readOnly);
67  bool selectOnStep() const { return mSelectOnStep; }
69  void setSelectOnStep(bool sel) { mSelectOnStep = sel; }
71  void addValue(int change) { addValue(change, false); }
73  int minValue() const { return mMinValue; }
75  int maxValue() const { return mMaxValue; }
77  void setMinValue(int val);
79  void setMaxValue(int val);
83  int bound(int val) const;
87  int lineStep() const { return mLineStep; }
91  void setLineStep(int step);
95  int lineShiftStep() const { return mLineShiftStep; }
99  void setLineShiftStep(int step);
100  public slots:
102  virtual void stepUp();
104  virtual void stepDown();
105  signals:
110  void stepped(int step);
111 
112  protected:
114  virtual void valueChange();
125  virtual int shiftStepAdjustment(int oldValue, int shiftStep);
127  virtual bool eventFilter(TQObject*, TQEvent*);
131  virtual void updateDisplay();
132 
133  private slots:
134  void textEdited();
135  private:
136  void init();
137  void addValue(int change, bool current);
138  int whichButton(const TQPoint&);
139  bool setShiftStepping(bool, int currentButton);
140 
141  enum { NO_BUTTON, UP, DOWN };
142 
143  int mMinValue;
144  int mMaxValue;
145  int mLineStep; // step when spin arrows are pressed
146  int mLineShiftStep; // step when spin arrows are pressed with shift key
147  int mCurrentButton; // current spin widget button
148  bool mShiftMouse; // true while left button is being held down with shift key
149  bool mShiftMinBound; // true if a temporary minimum bound has been set during shift stepping
150  bool mShiftMaxBound; // true if a temporary maximum bound has been set during shift stepping
151  bool mSelectOnStep; // select the editor text whenever spin buttons are clicked (default)
152  bool mReadOnly; // value cannot be changed
153  bool mSuppressSignals;
154  bool mEdited; // text field has been edited
155 };
156 
157 #endif // SPINBOX_H
Spin box with accelerated shift key stepping and read-only option.
Definition: spinbox.h:43
virtual bool eventFilter(TQObject *, TQEvent *)
Receives events destined for the spin widget or for the edit field.
Definition: spinbox.cpp:202
virtual void valueChange()
A virtual method called whenever the value of the spin box has changed.
Definition: spinbox.cpp:158
void stepped(int step)
Signal emitted when the spin box's value is stepped (by the shifted or unshifted increment).
void setLineShiftStep(int step)
Sets the shifted step increment, i.e.
Definition: spinbox.cpp:109
int maxValue() const
Returns the maximum value of the spin box.
Definition: spinbox.h:75
int lineStep() const
Returns the unshifted step increment, i.e.
Definition: spinbox.h:87
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
Definition: spinbox.h:69
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
Definition: spinbox.cpp:72
void setMinValue(int val)
Sets the minimum value of the spin box.
Definition: spinbox.cpp:88
int minValue() const
Returns the minimum value of the spin box.
Definition: spinbox.h:73
virtual void stepUp()
Increments the value of the spin box by the unshifted step increment.
Definition: spinbox.cpp:116
SpinBox(TQWidget *parent=0, const char *name=0)
Constructor.
Definition: spinbox.cpp:27
bool selectOnStep() const
Returns whether the spin box value text is selected when its value is stepped.
Definition: spinbox.h:67
void setRange(int minValue, int maxValue)
Sets the minimum and maximum values of the spin box.
Definition: spinbox.h:81
void setLineStep(int step)
Sets the unshifted step increment, i.e.
Definition: spinbox.cpp:102
virtual int shiftStepAdjustment(int oldValue, int shiftStep)
Returns the initial adjustment to the value for a shift step up or down.
Definition: spinbox.cpp:445
int bound(int val) const
Returns the specified value clamped to the range of the spin box.
Definition: spinbox.cpp:83
void addValue(int change)
Adds a value to the current value of the spin box.
Definition: spinbox.h:71
bool isReadOnly() const
Returns true if the widget is read only.
Definition: spinbox.h:61
virtual void stepDown()
Decrements the value of the spin box by the unshifted step increment.
Definition: spinbox.cpp:123
void setMaxValue(int val)
Sets the maximum value of the spin box.
Definition: spinbox.cpp:95
int lineShiftStep() const
Returns the shifted step increment, i.e.
Definition: spinbox.h:95
virtual void updateDisplay()
Updates the contents of the embedded TQLineEdit to reflect the current value using mapValueToText().
Definition: spinbox.cpp:193