spinbox2.h
00001 /* 00002 * spinbox2.h - spin box with extra pair of spin buttons (for TQt 3) 00003 * Program: kalarm 00004 * Copyright © 2001-2007 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 <tqglobal.h> 00025 #include <tqlineedit.h> 00026 00027 class SpinMirror; 00028 class ExtraSpinBox; 00029 #include "spinbox.h" 00030 00031 00056 class SpinBox2 : public TQFrame 00057 { 00058 Q_OBJECT 00059 TQ_OBJECT 00060 public: 00065 explicit SpinBox2(TQWidget* parent = 0, const char* name = 0); 00074 SpinBox2(int minValue, int maxValue, int step = 1, int step2 = 1, 00075 TQWidget* parent = 0, const char* name = 0); 00079 virtual void setReadOnly(bool readOnly); 00081 bool isReadOnly() const { return mSpinbox->isReadOnly(); } 00083 void setSelectOnStep(bool sel) { mSpinbox->setSelectOnStep(sel); } 00087 void setReverseWithLayout(bool reverse); 00089 bool reverseButtons() const { return mReverseLayout && !mReverseWithLayout; } 00090 00092 TQString text() const { return mSpinbox->text(); } 00094 virtual TQString prefix() const { return mSpinbox->prefix(); } 00096 virtual TQString suffix() const { return mSpinbox->suffix(); } 00098 virtual TQString cleanText() const { return mSpinbox->cleanText(); } 00099 00103 virtual void setSpecialValueText(const TQString& text) { mSpinbox->setSpecialValueText(text); } 00107 TQString specialValueText() const { return mSpinbox->specialValueText(); } 00108 00112 virtual void setWrapping(bool on); 00116 bool wrapping() const { return mSpinbox->wrapping(); } 00117 00119 void setAlignment(int a) { mSpinbox->setAlignment(a); } 00121 virtual void setButtonSymbols(TQSpinBox::ButtonSymbols); 00123 TQSpinBox::ButtonSymbols buttonSymbols() const { return mSpinbox->buttonSymbols(); } 00124 00128 virtual void setValidator(const TQValidator* v) { mSpinbox->setValidator(v); } 00132 const TQValidator* validator() const { return mSpinbox->validator(); } 00133 00134 virtual TQSize sizeHint() const; 00135 virtual TQSize minimumSizeHint() const; 00136 00138 int minValue() const { return mMinValue; } 00140 int maxValue() const { return mMaxValue; } 00142 virtual void setMinValue(int val); 00144 virtual void setMaxValue(int val); 00146 void setRange(int minValue, int maxValue) { setMinValue(minValue); setMaxValue(maxValue); } 00148 int value() const { return mSpinbox->value(); } 00150 int bound(int val) const; 00151 00153 TQRect upRect() const { return mSpinbox->upRect(); } 00155 TQRect downRect() const { return mSpinbox->downRect(); } 00157 TQRect up2Rect() const; 00159 TQRect down2Rect() const; 00160 00165 int lineStep() const { return mLineStep; } 00170 int lineShiftStep() const { return mLineShiftStep; } 00175 int pageStep() const { return mPageStep; } 00180 int pageShiftStep() const { return mPageShiftStep; } 00185 void setLineStep(int step); 00192 void setSteps(int line, int page); 00199 void setShiftSteps(int line, int page); 00200 00204 void addPage() { addValue(mPageStep); } 00208 void subtractPage() { addValue(-mPageStep); } 00212 void addLine() { addValue(mLineStep); } 00216 void subtractLine() { addValue(-mLineStep); } 00218 void addValue(int change) { mSpinbox->addValue(change); } 00219 00220 public slots: 00222 virtual void setValue(int val) { mSpinbox->setValue(val); } 00224 virtual void setPrefix(const TQString& text) { mSpinbox->setPrefix(text); } 00226 virtual void setSuffix(const TQString& text) { mSpinbox->setSuffix(text); } 00230 virtual void stepUp() { addValue(mLineStep); } 00234 virtual void stepDown() { addValue(-mLineStep); } 00238 virtual void pageUp() { addValue(mPageStep); } 00242 virtual void pageDown() { addValue(-mPageStep); } 00244 virtual void selectAll() { mSpinbox->selectAll(); } 00246 virtual void setEnabled(bool enabled); 00247 00248 signals: 00250 void valueChanged(int value); 00252 void valueChanged(const TQString& valueText); 00253 00254 protected: 00255 virtual TQString mapValueToText(int v) { return mSpinbox->mapValToText(v); } 00256 virtual int mapTextToValue(bool* ok) { return mSpinbox->mapTextToVal(ok); } 00257 virtual void resizeEvent(TQResizeEvent*) { arrange(); } 00258 virtual void showEvent(TQShowEvent*); 00259 virtual void styleChange(TQStyle&); 00260 virtual void getMetrics() const; 00261 00262 mutable int wUpdown2; // width of second spin widget 00263 mutable int xUpdown2; // x offset of visible area in 'mUpdown2' 00264 mutable int xSpinbox; // x offset of visible area in 'mSpinbox' 00265 mutable int wGap; // gap between mUpdown2Frame and mSpinboxFrame 00266 00267 protected slots: 00268 virtual void valueChange(); 00269 virtual void stepPage(int); 00270 00271 private slots: 00272 void updateMirror(); 00273 00274 private: 00275 void init(); 00276 void arrange(); 00277 int whichButton(TQObject* spinWidget, const TQPoint&); 00278 void setShiftStepping(bool on); 00279 00280 // Visible spin box class. 00281 // Declared here to allow use of mSpinBox in inline methods. 00282 class MainSpinBox : public SpinBox 00283 { 00284 public: 00285 MainSpinBox(SpinBox2* sb2, TQWidget* parent, const char* name = 0) 00286 : SpinBox(parent, name), owner(sb2) { } 00287 MainSpinBox(int minValue, int maxValue, int step, SpinBox2* sb2, TQWidget* parent, const char* name = 0) 00288 : SpinBox(minValue, maxValue, step, parent, name), owner(sb2) { } 00289 void setAlignment(int a) { editor()->setAlignment(a); } 00290 virtual TQString mapValueToText(int v) { return owner->mapValueToText(v); } 00291 virtual int mapTextToValue(bool* ok) { return owner->mapTextToValue(ok); } 00292 TQString mapValToText(int v) { return SpinBox::mapValueToText(v); } 00293 int mapTextToVal(bool* ok) { return SpinBox::mapTextToValue(ok); } 00294 virtual int shiftStepAdjustment(int oldValue, int shiftStep); 00295 private: 00296 SpinBox2* owner; // owner SpinBox2 00297 }; 00298 00299 enum { NO_BUTTON = -1, UP, DOWN, UP2, DOWN2 }; 00300 00301 static int mReverseLayout; // widgets are mirrored right to left 00302 TQFrame* mUpdown2Frame; // contains visible part of the extra pair of spin buttons 00303 TQFrame* mSpinboxFrame; // contains the main spin box 00304 ExtraSpinBox* mUpdown2; // the extra pair of spin buttons 00305 MainSpinBox* mSpinbox; // the visible spin box 00306 SpinMirror* mSpinMirror; // image of the extra pair of spin buttons 00307 int mMinValue; 00308 int mMaxValue; 00309 int mLineStep; // right button increment 00310 int mLineShiftStep; // right button increment with shift pressed 00311 int mPageStep; // left button increment 00312 int mPageShiftStep; // left button increment with shift pressed 00313 bool mReverseWithLayout; // reverse button positions if reverse layout (default = true) 00314 00315 friend class MainSpinBox; 00316 }; 00317 00318 #endif // SPINBOX2_H