kalarm/lib

spinbox.h

00001 /*
00002  *  spinbox.h  -  spin box with shift-click step value and read-only option
00003  *  Program:  kalarm
00004  *  Copyright (C) 2002 - 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef SPINBOX_H
00022 #define SPINBOX_H
00023 
00024 #include <qspinbox.h>
00025 
00026 
00042 class SpinBox : public QSpinBox
00043 {
00044         Q_OBJECT
00045     public:
00050         SpinBox(QWidget* parent = 0, const char* name = 0);
00058         SpinBox(int minValue, int maxValue, int step = 1, QWidget* parent = 0, const char* name = 0);
00060         bool         isReadOnly() const                    { return mReadOnly; }
00064         virtual void setReadOnly(bool readOnly);
00066         bool         selectOnStep() const                  { return mSelectOnStep; }
00068         void         setSelectOnStep(bool sel)             { mSelectOnStep = sel; }
00070         void         addValue(int change)                  { addValue(change, false); }
00072         int          minValue() const                      { return mMinValue; }
00074         int          maxValue() const                      { return mMaxValue; }
00076         void         setMinValue(int val);
00078         void         setMaxValue(int val);
00080         void         setRange(int minValue, int maxValue)  { setMinValue(minValue);  setMaxValue(maxValue); }
00082         int          bound(int val) const;
00086         int          lineStep() const                      { return mLineStep; }
00090         void         setLineStep(int step);
00094         int          lineShiftStep() const                 { return mLineShiftStep; }
00098         void         setLineShiftStep(int step);
00099     public slots:
00101         virtual void stepUp();
00103         virtual void stepDown();
00104     signals:
00109         void         stepped(int step);
00110 
00111     protected:
00113         virtual void valueChange();
00124         virtual int  shiftStepAdjustment(int oldValue, int shiftStep);
00126         virtual bool eventFilter(QObject*, QEvent*);
00130         virtual void updateDisplay();
00131 
00132     private slots:
00133         void         textEdited();
00134     private:
00135         void         init();
00136         void         addValue(int change, bool current);
00137         int          whichButton(const QPoint&);
00138         bool         setShiftStepping(bool);
00139 
00140         enum { NO_BUTTON, UP, DOWN };
00141 
00142         int          mMinValue;
00143         int          mMaxValue;
00144         int          mLineStep;         // step when spin arrows are pressed
00145         int          mLineShiftStep;    // step when spin arrows are pressed with shift key
00146         int          mCurrentButton;    // current spin widget button
00147         bool         mShiftMouse;       // true while left button is being held down with shift key
00148         bool         mShiftMinBound;    // true if a temporary minimum bound has been set during shift stepping
00149         bool         mShiftMaxBound;    // true if a temporary maximum bound has been set during shift stepping
00150         bool         mSelectOnStep;     // select the editor text whenever spin buttons are clicked (default)
00151         bool         mReadOnly;         // value cannot be changed
00152         bool         mSuppressSignals;
00153         bool         mEdited;           // text field has been edited
00154 };
00155 
00156 #endif // SPINBOX_H
KDE Home | KDE Accessibility Home | Description of Access Keys