kalarm/lib
spinbox.h
Go to the documentation of this file.00001 /* 00002 * spinbox.h - spin box with shift-click step value and read-only option 00003 * Program: kalarm 00004 * Copyright © 2002-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 SPINBOX_H 00022 #define SPINBOX_H 00023 00024 #include <QSpinBox> 00025 class QEvent; 00026 class QStyleOptionSpinBox; 00027 00028 00044 class SpinBox : public QSpinBox 00045 { 00046 Q_OBJECT 00047 public: 00051 explicit SpinBox(QWidget* parent = 0); 00057 SpinBox(int minValue, int maxValue, QWidget* parent = 0); 00059 bool isReadOnly() const { return mReadOnly; } 00063 virtual void setReadOnly(bool readOnly); 00065 bool selectOnStep() const { return mSelectOnStep; } 00067 void setSelectOnStep(bool sel) { mSelectOnStep = sel; } 00069 void addValue(int change) { addValue(change, false); } 00071 int minimum() const { return mMinValue; } 00073 int maximum() const { return mMaxValue; } 00075 void setMinimum(int val); 00077 void setMaximum(int val); 00079 void setRange(int minValue, int maxValue) { setMinimum(minValue); setMaximum(maxValue); } 00081 int bound(int val) const; 00085 virtual void stepBy(int steps); 00089 int singleStep() const { return mLineStep; } 00093 void setSingleStep(int step); 00097 int singleShiftStep() const { return mLineShiftStep; } 00101 void setSingleShiftStep(int step); 00103 QRect upRect() const; 00105 QRect downRect() const; 00107 QRect upDownRect() const; 00109 void setUpDownOnly(bool only) { mUpDownOnly = only; } 00111 void initStyleOption(QStyleOptionSpinBox&) const; 00112 00113 signals: 00118 void stepped(int step); 00119 00120 protected: 00131 virtual int shiftStepAdjustment(int oldValue, int shiftStep); 00133 virtual bool eventFilter(QObject*, QEvent*); 00134 00135 virtual void paintEvent(QPaintEvent*); 00136 virtual void focusOutEvent(QFocusEvent*); 00137 virtual void mousePressEvent(QMouseEvent*); 00138 virtual void mouseDoubleClickEvent(QMouseEvent*); 00139 virtual void mouseReleaseEvent(QMouseEvent*); 00140 virtual void mouseMoveEvent(QMouseEvent*); 00141 virtual void keyPressEvent(QKeyEvent*); 00142 virtual void keyReleaseEvent(QKeyEvent*); 00143 00144 private slots: 00145 void textEdited(); 00146 void valueChange(); 00147 private: 00148 void init(); 00149 void addValue(int change, bool current); 00150 int whichButton(const QPoint&); 00151 bool setShiftStepping(bool); 00152 bool clickEvent(QMouseEvent*); 00153 bool keyEvent(QKeyEvent*); 00154 00155 enum { NO_BUTTON, UP, DOWN }; 00156 00157 int mMinValue; 00158 int mMaxValue; 00159 int mLineStep; // step when spin arrows are pressed 00160 int mLineShiftStep; // step when spin arrows are pressed with shift key 00161 int mCurrentButton; // current spin widget button 00162 bool mShiftMouse; // true while left button is being held down with shift key 00163 bool mShiftMinBound; // true if a temporary minimum bound has been set during shift stepping 00164 bool mShiftMaxBound; // true if a temporary maximum bound has been set during shift stepping 00165 bool mSelectOnStep; // select the editor text whenever spin buttons are clicked (default) 00166 bool mUpDownOnly; // true if edit field isn't displayed 00167 bool mReadOnly; // value cannot be changed 00168 bool mSuppressSignals; 00169 bool mEdited; // text field has been edited 00170 }; 00171 00172 #endif // SPINBOX_H
KDE 4.2 API Reference