kalarm/lib

timespinbox.h

00001 /*
00002  *  timespinbox.h  -  time spinbox widget
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 TIMESPINBOX_H
00022 #define TIMESPINBOX_H
00023 
00024 #include <qdatetime.h>
00025 #include "spinbox2.h"
00026 
00027 
00045 class TimeSpinBox : public SpinBox2
00046 {
00047         Q_OBJECT
00048     public:
00055         explicit TimeSpinBox(bool use24hour, QWidget* parent = 0, const char* name = 0);
00062         TimeSpinBox(int minMinute, int maxMinute, QWidget* parent = 0, const char* name = 0);
00066         bool            isValid() const;
00071         void            setValid(bool);
00075         QTime           time() const;
00079         void            setMaxValue(int minutes)     { SpinBox2::setMaxValue(minutes); }
00081         void            setMaxValue(const QTime& t)  { SpinBox2::setMaxValue(t.hour()*60 + t.minute()); }
00083         QTime           maxTime() const              { int mv = maxValue();  return QTime(mv/60, mv%60); }
00087         static QString  shiftWhatsThis();
00088 
00089         virtual QSize   sizeHint() const;
00090         virtual QSize   minimumSizeHint() const;
00091 
00092     public slots:
00096         virtual void    setValue(int minutes);
00098         void            setValue(const QTime& t)     { setValue(t.hour()*60 + t.minute()); }
00102         virtual void    stepUp();
00106         virtual void    stepDown();
00107 
00108     protected:
00109         virtual QString mapValueToText(int v);
00110         virtual int     mapTextToValue(bool* ok);
00111     private slots:
00112         void            slotValueChanged(int value);
00113     private:
00114         class TimeValidator;
00115         TimeValidator*  mValidator;
00116         int             mMinimumValue;
00117         bool            m12Hour;             // use 12-hour clock
00118         bool            mPm;                 // use PM for manually entered values (with 12-hour clock)
00119         bool            mInvalid;            // value is currently invalid (asterisks)
00120         bool            mEnteredSetValue;    // to prevent infinite recursion in setValue()
00121 };
00122 
00123 #endif // TIMESPINBOX_H
KDE Home | KDE Accessibility Home | Description of Access Keys