timespinbox.h
00001 /* 00002 * timespinbox.h - time spinbox widget 00003 * Program: kalarm 00004 * Copyright © 2001-2008 by David Jarvie <djarvie@kde.org> 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 TIMESPINBOX_H 00022 #define TIMESPINBOX_H 00023 00024 #include <tqdatetime.h> 00025 #include "spinbox2.h" 00026 00027 00045 class TimeSpinBox : public SpinBox2 00046 { 00047 Q_OBJECT 00048 00049 public: 00056 explicit TimeSpinBox(bool use24hour, TQWidget* parent = 0, const char* name = 0); 00063 TimeSpinBox(int minMinute, int maxMinute, TQWidget* parent = 0, const char* name = 0); 00067 bool isValid() const; 00072 void setValid(bool); 00076 TQTime time() const; 00080 virtual void setMinValue(int minutes); 00084 virtual void setMaxValue(int minutes) { SpinBox2::setMaxValue(minutes); } 00086 void setMaxValue(const TQTime& t) { SpinBox2::setMaxValue(t.hour()*60 + t.minute()); } 00088 TQTime maxTime() const { int mv = maxValue(); return TQTime(mv/60, mv%60); } 00092 static TQString shiftWhatsThis(); 00093 00094 virtual TQSize sizeHint() const; 00095 virtual TQSize minimumSizeHint() const; 00096 00097 public slots: 00101 virtual void setValue(int minutes); 00103 void setValue(const TQTime& t) { setValue(t.hour()*60 + t.minute()); } 00107 virtual void stepUp(); 00111 virtual void stepDown(); 00112 00113 protected: 00114 virtual TQString mapValueToText(int v); 00115 virtual int mapTextToValue(bool* ok); 00116 private slots: 00117 void slotValueChanged(int value); 00118 private: 00119 class TimeValidator; 00120 TimeValidator* mValidator; 00121 int mMinimumValue; // real minimum value, excluding special value for "**:**" 00122 bool m12Hour; // use 12-hour clock 00123 bool mPm; // use PM for manually entered values (with 12-hour clock) 00124 bool mInvalid; // value is currently invalid (asterisks) 00125 bool mEnteredSetValue; // to prevent infinite recursion in setValue() 00126 }; 00127 00128 #endif // TIMESPINBOX_H