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  Q_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);
81  void setRange(int minValue, int maxValue) { setMinValue(minValue); setMaxValue(maxValue); }
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