kalarm/lib

spinbox2.h

00001 /*
00002  *  spinbox2.h  -  spin box with extra pair of spin buttons (for Qt 3)
00003  *  Program:  kalarm
00004  *  Copyright (c) 2001 - 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 SPINBOX2_H
00022 #define SPINBOX2_H
00023 
00024 #include <qglobal.h>
00025 
00026 class SpinMirror;
00027 class ExtraSpinBox;
00028 #include "spinbox.h"
00029 
00030 
00055 class SpinBox2 : public QFrame
00056 {
00057         Q_OBJECT
00058     public:
00063         SpinBox2(QWidget* parent = 0, const char* name = 0);
00072         SpinBox2(int minValue, int maxValue, int step = 1, int step2 = 1,
00073                  QWidget* parent = 0, const char* name = 0);
00077         virtual void        setReadOnly(bool readOnly);
00079         bool                isReadOnly() const          { return mSpinbox->isReadOnly(); }
00081         void                setSelectOnStep(bool sel)   { mSpinbox->setSelectOnStep(sel); }
00085         void                setReverseWithLayout(bool reverse);
00087         bool                reverseButtons() const      { return mReverseLayout  &&  !mReverseWithLayout; }
00088 
00090         QString             text() const                { return mSpinbox->text(); }
00092         virtual QString     prefix() const              { return mSpinbox->prefix(); }
00094         virtual QString     suffix() const              { return mSpinbox->suffix(); }
00096         virtual QString     cleanText() const           { return mSpinbox->cleanText(); }
00097 
00101         virtual void        setSpecialValueText(const QString& text)  { mSpinbox->setSpecialValueText(text); }
00105         QString             specialValueText() const    { return mSpinbox->specialValueText(); }
00106 
00110         virtual void        setWrapping(bool on);
00114         bool                wrapping() const            { return mSpinbox->wrapping(); }
00115 
00117         virtual void        setButtonSymbols(QSpinBox::ButtonSymbols);
00119         QSpinBox::ButtonSymbols buttonSymbols() const   { return mSpinbox->buttonSymbols(); }
00120 
00124         virtual void        setValidator(const QValidator* v)  { mSpinbox->setValidator(v); }
00128         const QValidator*   validator() const           { return mSpinbox->validator(); }
00129 
00130         virtual QSize       sizeHint() const;
00131         virtual QSize       minimumSizeHint() const;
00132 
00134         int                 minValue() const            { return mMinValue; }
00136         int                 maxValue() const            { return mMaxValue; }
00138         void                setMinValue(int val);
00140         void                setMaxValue(int val);
00142         void                setRange(int minValue, int maxValue)   { setMinValue(minValue);  setMaxValue(maxValue); }
00144         int                 value() const               { return mSpinbox->value(); }
00146         int                 bound(int val) const;
00147 
00149         QRect               upRect() const              { return mSpinbox->upRect(); }
00151         QRect               downRect() const            { return mSpinbox->downRect(); }
00153         QRect               up2Rect() const;
00155         QRect               down2Rect() const;
00156 
00161         int                 lineStep() const            { return mLineStep; }
00166         int                 lineShiftStep() const       { return mLineShiftStep; }
00171         int                 pageStep() const            { return mPageStep; }
00176         int                 pageShiftStep() const       { return mPageShiftStep; }
00181         void                setLineStep(int step);
00188         void                setSteps(int line, int page);
00195         void                setShiftSteps(int line, int page);
00196 
00200         void                addPage()                   { addValue(mPageStep); }
00204         void                subtractPage()              { addValue(-mPageStep); }
00208         void                addLine()                   { addValue(mLineStep); }
00212         void                subtractLine()              { addValue(-mLineStep); }
00214         void                addValue(int change)        { mSpinbox->addValue(change); }
00215 
00216     public slots:
00218         virtual void        setValue(int val)           { mSpinbox->setValue(val); }
00220         virtual void        setPrefix(const QString& text)  { mSpinbox->setPrefix(text); }
00222         virtual void        setSuffix(const QString& text)  { mSpinbox->setSuffix(text); }
00226         virtual void        stepUp()                    { addValue(mLineStep); }
00230         virtual void        stepDown()                  { addValue(-mLineStep); }
00234         virtual void        pageUp()                    { addValue(mPageStep); }
00238         virtual void        pageDown()                  { addValue(-mPageStep); }
00240         virtual void        selectAll()                 { mSpinbox->selectAll(); }
00242         virtual void        setEnabled(bool enabled);
00243 
00244     signals:
00246         void                valueChanged(int value);
00248         void                valueChanged(const QString& valueText);
00249 
00250     protected:
00251         virtual QString     mapValueToText(int v)         { return mSpinbox->mapValToText(v); }
00252         virtual int         mapTextToValue(bool* ok)      { return mSpinbox->mapTextToVal(ok); }
00253         virtual void        resizeEvent(QResizeEvent*)    { arrange(); }
00254         virtual void        showEvent(QShowEvent*);
00255         virtual void        styleChange(QStyle&);
00256         virtual void        getMetrics() const;
00257 
00258         mutable int      wUpdown2;        // width of second spin widget
00259         mutable int      xUpdown2;        // x offset of visible area in 'mUpdown2'
00260         mutable int      xSpinbox;        // x offset of visible area in 'mSpinbox'
00261         mutable int      wGap;            // gap between mUpdown2Frame and mSpinboxFrame
00262 
00263     protected slots:
00264         virtual void        valueChange();
00265         virtual void        stepPage(int);
00266 
00267     private slots:
00268         void                updateMirror();
00269 
00270     private:
00271         void                init();
00272         void                arrange();
00273         int                 whichButton(QObject* spinWidget, const QPoint&);
00274         void                setShiftStepping(bool on);
00275 
00276         // Visible spin box class.
00277         // Declared here to allow use of mSpinBox in inline methods.
00278         class MainSpinBox : public SpinBox
00279         {
00280             public:
00281                 MainSpinBox(SpinBox2* sb2, QWidget* parent, const char* name = 0)
00282                                 : SpinBox(parent, name), owner(sb2) { }
00283                 MainSpinBox(int minValue, int maxValue, int step, SpinBox2* sb2, QWidget* parent, const char* name = 0)
00284                                 : SpinBox(minValue, maxValue, step, parent, name), owner(sb2) { }
00285                 virtual QString mapValueToText(int v)     { return owner->mapValueToText(v); }
00286                 virtual int     mapTextToValue(bool* ok)  { return owner->mapTextToValue(ok); }
00287                 QString         mapValToText(int v)       { return SpinBox::mapValueToText(v); }
00288                 int             mapTextToVal(bool* ok)    { return SpinBox::mapTextToValue(ok); }
00289                 virtual int     shiftStepAdjustment(int oldValue, int shiftStep);
00290             private:
00291                 SpinBox2* owner;   // owner SpinBox2
00292         };
00293 
00294         enum { NO_BUTTON = -1, UP, DOWN, UP2, DOWN2 };
00295 
00296         static int       mReverseLayout;  // widgets are mirrored right to left
00297         QFrame*          mUpdown2Frame;   // contains visible part of the extra pair of spin buttons
00298         QFrame*          mSpinboxFrame;   // contains the main spin box
00299         ExtraSpinBox*    mUpdown2;        // the extra pair of spin buttons
00300         MainSpinBox*     mSpinbox;        // the visible spin box
00301         SpinMirror*      mSpinMirror;     // image of the extra pair of spin buttons
00302         int              mMinValue;
00303         int              mMaxValue;
00304         int              mLineStep;           // right button increment
00305         int              mLineShiftStep;      // right button increment with shift pressed
00306         int              mPageStep;           // left button increment
00307         int              mPageShiftStep;      // left button increment with shift pressed
00308         bool             mReverseWithLayout;  // reverse button positions if reverse layout (default = true)
00309 
00310     friend class MainSpinBox;
00311 };
00312 
00313 #endif // SPINBOX2_H
KDE Home | KDE Accessibility Home | Description of Access Keys