kalarm/lib
spinbox2.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
00259 mutable int xUpdown2;
00260 mutable int xSpinbox;
00261 mutable int wGap;
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
00277
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;
00292 };
00293
00294 enum { NO_BUTTON = -1, UP, DOWN, UP2, DOWN2 };
00295
00296 static int mReverseLayout;
00297 QFrame* mUpdown2Frame;
00298 QFrame* mSpinboxFrame;
00299 ExtraSpinBox* mUpdown2;
00300 MainSpinBox* mSpinbox;
00301 SpinMirror* mSpinMirror;
00302 int mMinValue;
00303 int mMaxValue;
00304 int mLineStep;
00305 int mLineShiftStep;
00306 int mPageStep;
00307 int mPageShiftStep;
00308 bool mReverseWithLayout;
00309
00310 friend class MainSpinBox;
00311 };
00312
00313 #endif // SPINBOX2_H
|