qdatetimeedit.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QDATETIMEEDIT_H
00043 #define QDATETIMEEDIT_H
00044 
00045 #include <QtCore/qdatetime.h>
00046 #include <QtCore/qvariant.h>
00047 #include <QtGui/qabstractspinbox.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #ifndef QT_NO_DATETIMEEDIT
00056 
00057 class QDateTimeEditPrivate;
00058 class QStyleOptionSpinBox;
00059 class QCalendarWidget;
00060 
00061 class Q_GUI_EXPORT QDateTimeEdit : public QAbstractSpinBox
00062 {
00063     Q_OBJECT
00064 
00065     Q_ENUMS(Section)
00066     Q_FLAGS(Sections)
00067     Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged USER true)
00068     Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged)
00069     Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged)
00070     Q_PROPERTY(QDateTime maximumDateTime READ maximumDateTime WRITE setMaximumDateTime RESET clearMaximumDateTime)
00071     Q_PROPERTY(QDateTime minimumDateTime READ minimumDateTime WRITE setMinimumDateTime RESET clearMinimumDateTime)
00072     Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate RESET clearMaximumDate)
00073     Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate RESET clearMinimumDate)
00074     Q_PROPERTY(QTime maximumTime READ maximumTime WRITE setMaximumTime RESET clearMaximumTime)
00075     Q_PROPERTY(QTime minimumTime READ minimumTime WRITE setMinimumTime RESET clearMinimumTime)
00076     Q_PROPERTY(Section currentSection READ currentSection WRITE setCurrentSection)
00077     Q_PROPERTY(Sections displayedSections READ displayedSections)
00078     Q_PROPERTY(QString displayFormat READ displayFormat WRITE setDisplayFormat)
00079     Q_PROPERTY(bool calendarPopup READ calendarPopup WRITE setCalendarPopup)
00080     Q_PROPERTY(int currentSectionIndex READ currentSectionIndex WRITE setCurrentSectionIndex)
00081     Q_PROPERTY(int sectionCount READ sectionCount)
00082     Q_PROPERTY(Qt::TimeSpec timeSpec READ timeSpec WRITE setTimeSpec)
00083 public:
00084     enum Section {
00085         NoSection = 0x0000,
00086         AmPmSection = 0x0001,
00087         MSecSection = 0x0002,
00088         SecondSection = 0x0004,
00089         MinuteSection = 0x0008,
00090         HourSection   = 0x0010,
00091         DaySection    = 0x0100,
00092         MonthSection  = 0x0200,
00093         YearSection   = 0x0400,
00094         TimeSections_Mask = AmPmSection|MSecSection|SecondSection|MinuteSection|HourSection,
00095         DateSections_Mask = DaySection|MonthSection|YearSection
00096     };
00097 
00098     Q_DECLARE_FLAGS(Sections, Section)
00099 
00100     explicit QDateTimeEdit(QWidget *parent = 0);
00101     explicit QDateTimeEdit(const QDateTime &dt, QWidget *parent = 0);
00102     explicit QDateTimeEdit(const QDate &d, QWidget *parent = 0);
00103     explicit QDateTimeEdit(const QTime &t, QWidget *parent = 0);
00104 
00105     QDateTime dateTime() const;
00106     QDate date() const;
00107     QTime time() const;
00108 
00109     QDateTime minimumDateTime() const;
00110     void clearMinimumDateTime();
00111     void setMinimumDateTime(const QDateTime &dt);
00112 
00113     QDateTime maximumDateTime() const;
00114     void clearMaximumDateTime();
00115     void setMaximumDateTime(const QDateTime &dt);
00116 
00117     void setDateTimeRange(const QDateTime &min, const QDateTime &max);
00118 
00119     QDate minimumDate() const;
00120     void setMinimumDate(const QDate &min);
00121     void clearMinimumDate();
00122 
00123     QDate maximumDate() const;
00124     void setMaximumDate(const QDate &max);
00125     void clearMaximumDate();
00126 
00127     void setDateRange(const QDate &min, const QDate &max);
00128 
00129     QTime minimumTime() const;
00130     void setMinimumTime(const QTime &min);
00131     void clearMinimumTime();
00132 
00133     QTime maximumTime() const;
00134     void setMaximumTime(const QTime &max);
00135     void clearMaximumTime();
00136 
00137     void setTimeRange(const QTime &min, const QTime &max);
00138 
00139     Sections displayedSections() const;
00140     Section currentSection() const;
00141     Section sectionAt(int index) const;
00142     void setCurrentSection(Section section);
00143 
00144     int currentSectionIndex() const;
00145     void setCurrentSectionIndex(int index);
00146 
00147     QCalendarWidget *calendarWidget() const;
00148     void setCalendarWidget(QCalendarWidget *calendarWidget);
00149 
00150     int sectionCount() const;
00151 
00152     void setSelectedSection(Section section);
00153 
00154     QString sectionText(Section section) const;
00155 
00156     QString displayFormat() const;
00157     void setDisplayFormat(const QString &format);
00158 
00159     bool calendarPopup() const;
00160     void setCalendarPopup(bool enable);
00161 
00162     Qt::TimeSpec timeSpec() const;
00163     void setTimeSpec(Qt::TimeSpec spec);
00164 
00165     QSize sizeHint() const;
00166 
00167     virtual void clear();
00168     virtual void stepBy(int steps);
00169 
00170     bool event(QEvent *event);
00171 Q_SIGNALS:
00172     void dateTimeChanged(const QDateTime &date);
00173     void timeChanged(const QTime &date);
00174     void dateChanged(const QDate &date);
00175 
00176 public Q_SLOTS:
00177     void setDateTime(const QDateTime &dateTime);
00178     void setDate(const QDate &date);
00179     void setTime(const QTime &time);
00180 
00181 protected:
00182     virtual void keyPressEvent(QKeyEvent *event);
00183 #ifndef QT_NO_WHEELEVENT
00184     virtual void wheelEvent(QWheelEvent *event);
00185 #endif
00186     virtual void focusInEvent(QFocusEvent *event);
00187     virtual bool focusNextPrevChild(bool next);
00188     virtual QValidator::State validate(QString &input, int &pos) const;
00189     virtual void fixup(QString &input) const;
00190 
00191     virtual QDateTime dateTimeFromText(const QString &text) const;
00192     virtual QString textFromDateTime(const QDateTime &dt) const;
00193     virtual StepEnabled stepEnabled() const;
00194     virtual void mousePressEvent(QMouseEvent *event);
00195     virtual void paintEvent(QPaintEvent *event);
00196     void initStyleOption(QStyleOptionSpinBox *option) const;
00197 
00198     QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = 0);
00199 private:
00200     Q_DECLARE_PRIVATE(QDateTimeEdit)
00201     Q_DISABLE_COPY(QDateTimeEdit)
00202 
00203     Q_PRIVATE_SLOT(d_func(), void _q_resetButton())
00204 };
00205 
00206 class Q_GUI_EXPORT QTimeEdit : public QDateTimeEdit
00207 {
00208     Q_OBJECT
00209 public:
00210     QTimeEdit(QWidget *parent = 0);
00211     QTimeEdit(const QTime &time, QWidget *parent = 0);
00212 };
00213 
00214 class Q_GUI_EXPORT QDateEdit : public QDateTimeEdit
00215 {
00216     Q_OBJECT
00217 public:
00218     QDateEdit(QWidget *parent = 0);
00219     QDateEdit(const QDate &date, QWidget *parent = 0);
00220 };
00221 
00222 Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeEdit::Sections)
00223 
00224 #endif // QT_NO_DATETIMEEDIT
00225 
00226 QT_END_NAMESPACE
00227 
00228 QT_END_HEADER
00229 
00230 #endif // QDATETIMEEDIT_H