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 #include <qlineedit.h>
00026
00027 class SpinMirror;
00028 class ExtraSpinBox;
00029 #include "spinbox.h"
00030
00031
00056 class SpinBox2 : public QFrame
00057 {
00058 Q_OBJECT
00059 public:
00064 explicit SpinBox2(QWidget* parent = 0, const char* name = 0);
00073 SpinBox2(int minValue, int maxValue, int step = 1, int step2 = 1,
00074 QWidget* parent = 0, const char* name = 0);
00078 virtual void setReadOnly(bool readOnly);
00080 bool isReadOnly() const { return mSpinbox->isReadOnly(); }
00082 void setSelectOnStep(bool sel) { mSpinbox->setSelectOnStep(sel); }
00086 void setReverseWithLayout(bool reverse);
00088 bool reverseButtons() const { return mReverseLayout && !mReverseWithLayout; }
00089
00091 QString text() const { return mSpinbox->text(); }
00093 virtual QString prefix() const { return mSpinbox->prefix(); }
00095 virtual QString suffix() const { return mSpinbox->suffix(); }
00097 virtual QString cleanText() const { return mSpinbox->cleanText(); }
00098
00102 virtual void setSpecialValueText(const QString& text) { mSpinbox->setSpecialValueText(text); }
00106 QString specialValueText() const { return mSpinbox->specialValueText(); }
00107
00111 virtual void setWrapping(bool on);
00115 bool wrapping() const { return mSpinbox->wrapping(); }
00116
00118 void setAlignment(int a) { mSpinbox->setAlignment(a); }
00120 virtual void setButtonSymbols(QSpinBox::ButtonSymbols);
00122 QSpinBox::ButtonSymbols buttonSymbols() const { return mSpinbox->buttonSymbols(); }
00123
00127 virtual void setValidator(const QValidator* v) { mSpinbox->setValidator(v); }
00131 const QValidator* validator() const { return mSpinbox->validator(); }
00132
00133 virtual QSize sizeHint() const;
00134 virtual QSize minimumSizeHint() const;
00135
00137 int minValue() const { return mMinValue; }
00139 int maxValue() const { return mMaxValue; }
00141 virtual void setMinValue(int val);
00143 virtual void setMaxValue(int val);
00145 void setRange(int minValue, int maxValue) { setMinValue(minValue); setMaxValue(maxValue); }
00147 int value() const { return mSpinbox->value(); }
00149 int bound(int val) const;
00150
00152 QRect upRect() const { return mSpinbox->upRect(); }
00154 QRect downRect() const { return mSpinbox->downRect(); }
00156 QRect up2Rect() const;
00158 QRect down2Rect() const;
00159
00164 int lineStep() const { return mLineStep; }
00169 int lineShiftStep() const { return mLineShiftStep; }
00174 int pageStep() const { return mPageStep; }
00179 int pageShiftStep() const { return mPageShiftStep; }
00184 void setLineStep(int step);
00191 void setSteps(int line, int page);
00198 void setShiftSteps(int line, int page);
00199
00203 void addPage() { addValue(mPageStep); }
00207 void subtractPage() { addValue(-mPageStep); }
00211 void addLine() { addValue(mLineStep); }
00215 void subtractLine() { addValue(-mLineStep); }
00217 void addValue(int change) { mSpinbox->addValue(change); }
00218
00219 public slots:
00221 virtual void setValue(int val) { mSpinbox->setValue(val); }
00223 virtual void setPrefix(const QString& text) { mSpinbox->setPrefix(text); }
00225 virtual void setSuffix(const QString& text) { mSpinbox->setSuffix(text); }
00229 virtual void stepUp() { addValue(mLineStep); }
00233 virtual void stepDown() { addValue(-mLineStep); }
00237 virtual void pageUp() { addValue(mPageStep); }
00241 virtual void pageDown() { addValue(-mPageStep); }
00243 virtual void selectAll() { mSpinbox->selectAll(); }
00245 virtual void setEnabled(bool enabled);
00246
00247 signals:
00249 void valueChanged(int value);
00251 void valueChanged(const QString& valueText);
00252
00253 protected:
00254 virtual QString mapValueToText(int v) { return mSpinbox->mapValToText(v); }
00255 virtual int mapTextToValue(bool* ok) { return mSpinbox->mapTextToVal(ok); }
00256 virtual void resizeEvent(QResizeEvent*) { arrange(); }
00257 virtual void showEvent(QShowEvent*);
00258 virtual void styleChange(QStyle&);
00259 virtual void getMetrics() const;
00260
00261 mutable int wUpdown2;
00262 mutable int xUpdown2;
00263 mutable int xSpinbox;
00264 mutable int wGap;
00265
00266 protected slots:
00267 virtual void valueChange();
00268 virtual void stepPage(int);
00269
00270 private slots:
00271 void updateMirror();
00272
00273 private:
00274 void init();
00275 void arrange();
00276 int whichButton(QObject* spinWidget, const QPoint&);
00277 void setShiftStepping(bool on);
00278
00279
00280
00281 class MainSpinBox : public SpinBox
00282 {
00283 public:
00284 MainSpinBox(SpinBox2* sb2, QWidget* parent, const char* name = 0)
00285 : SpinBox(parent, name), owner(sb2) { }
00286 MainSpinBox(int minValue, int maxValue, int step, SpinBox2* sb2, QWidget* parent, const char* name = 0)
00287 : SpinBox(minValue, maxValue, step, parent, name), owner(sb2) { }
00288 void setAlignment(int a) { editor()->setAlignment(a); }
00289 virtual QString mapValueToText(int v) { return owner->mapValueToText(v); }
00290 virtual int mapTextToValue(bool* ok) { return owner->mapTextToValue(ok); }
00291 QString mapValToText(int v) { return SpinBox::mapValueToText(v); }
00292 int mapTextToVal(bool* ok) { return SpinBox::mapTextToValue(ok); }
00293 virtual int shiftStepAdjustment(int oldValue, int shiftStep);
00294 private:
00295 SpinBox2* owner;
00296 };
00297
00298 enum { NO_BUTTON = -1, UP, DOWN, UP2, DOWN2 };
00299
00300 static int mReverseLayout;
00301 QFrame* mUpdown2Frame;
00302 QFrame* mSpinboxFrame;
00303 ExtraSpinBox* mUpdown2;
00304 MainSpinBox* mSpinbox;
00305 SpinMirror* mSpinMirror;
00306 int mMinValue;
00307 int mMaxValue;
00308 int mLineStep;
00309 int mLineShiftStep;
00310 int mPageStep;
00311 int mPageShiftStep;
00312 bool mReverseWithLayout;
00313
00314 friend class MainSpinBox;
00315 };
00316
00317 #endif // SPINBOX2_H
|