⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdatetimeedit.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************)**** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <math.h>#include <private/qabstractspinbox_p.h>#include <private/qdatetime_p.h>#include <private/qdatetimeedit_p.h>#include <qabstractspinbox.h>#include <qapplication.h>#include <qdatetimeedit.h>#include <qdesktopwidget.h>#include <qdebug.h>#include <qevent.h>#include <qlineedit.h>#include <private/qlineedit_p.h>#include <qlocale.h>#include <qpainter.h>#include <qlayout.h>#include <qset.h>#include <qstyle.h>#ifndef QT_NO_DATETIMEEDIT//#define QDATETIMEEDIT_QDTEDEBUG#ifdef QDATETIMEEDIT_QDTEDEBUG#  define QDTEDEBUG qDebug() << QString("%1:%2").arg(__FILE__).arg(__LINE__)#  define QDTEDEBUGN qDebug#else#  define QDTEDEBUG if (false) qDebug()#  define QDTEDEBUGN if (false) qDebug#endifclass QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, public QDateTimeParser{    Q_DECLARE_PUBLIC(QDateTimeEdit)public:    QDateTimeEditPrivate();    void init();    void readLocaleSettings();    void emitSignals(EmitPolicy ep, const QVariant &old);    QString textFromValue(const QVariant &f) const;    QVariant valueFromText(const QString &f) const;    virtual void _q_editorCursorPositionChanged(int oldpos, int newpos);    virtual void interpret(EmitPolicy ep);    QVariant validateAndInterpret(QString &input, int &, QValidator::State &state, bool fixup = false) const;    void clearSection(int index);    virtual QString displayText() const { return edit->displayText(); } // this is from QDateTimeParser    int absoluteIndex(QDateTimeEdit::Section s, int index) const;    int absoluteIndex(const SectionNode &s) const;    void updateEdit();    QVariant stepBy(int index, int steps, bool test = false) const;    int sectionAt(int pos) const;    int closestSection(int index, bool forward) const;    int nextPrevSection(int index, bool forward) const;    void setSelected(int index, bool forward = false);    void updateCache(const QVariant &val, const QString &str) const;    QVariant getMinimum() const { return minimum; }    QVariant getMaximum() const { return maximum; }    QString valueToText(const QVariant &var) const { return textFromValue(var); }    QString getAmPmText(AmPm ap, Case cs) const;    int cursorPosition() const { return edit ? edit->cursorPosition() : -1; }    virtual QStyle::SubControl newHoverControl(const QPoint &pos);    virtual void updateEditFieldGeometry();    void _q_resetButton();    void updateArrow(QStyle::StateFlag state);    bool showCalendarPopup() const;    bool isSeparatorKey(const QKeyEvent *k) const;    static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s);    static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s);    void initCalendarPopup();    void positionCalendarPopup();    QDateTimeEdit::Sections sections;    mutable bool cacheGuard;    QString defaultDateFormat, defaultTimeFormat, unreversedFormat;    Qt::LayoutDirection layoutDirection;    mutable QVariant conflictGuard;    bool hasHadFocus, formatExplicitlySet, calendarPopup;    QStyle::StateFlag arrowState;    QCalendarPopup *monthCalendar;#ifdef QT_KEYPAD_NAVIGATION    bool focusOnButton;#endif};// --- QDateTimeEdit ---/*!  \class QDateTimeEdit qdatetimeedit.h  \brief The QDateTimeEdit class provides a widget for editing dates and times.  \ingroup basicwidgets  \mainclass  QDateTimeEdit allows the user to edit dates by using the keyboard or  the arrow keys to increase and decrease date and time values. The  arrow keys can be used to move from section to section within the  QDateTimeEdit box. Dates and times appear in accordance with the  format set; see setDisplayFormat().  \code  QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());  dateEdit->setMinimumDate(QDate::currentDate().addDays(-365));  dateEdit->setMaximumDate(QDate::currentDate().addDays(365));  dateEdit->setDisplayFormat("yyyy.MM.dd");  \endcode  Here we've created a new QDateTimeEdit object initialized with  today's date, and restricted the valid date range to today plus or  minus 365 days. We've set the order to month, day, year.  The minimum value for QDateTimeEdit is 14 September 1752,  and 2 January 4713BC for QDate. You can change this by calling  setMinimumDate(), setMaximumDate(),  setMinimumTime(),  and setMaximumTime().  \table 100%  \row \o \inlineimage windowsxp-datetimeedit.png Screenshot of a Windows XP style date time editing widget       \o A date time editing widget shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.  \row \o \inlineimage macintosh-datetimeedit.png Screenshot of a Macintosh style date time editing widget       \o A date time editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.  \row \o \inlineimage plastique-datetimeedit.png Screenshot of a Plastique style date time editing widget       \o A date time editing widget shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.  \endtable  \sa QDateEdit, QTimeEdit, QDate, QTime*//*!  \enum QDateTimeEdit::Section  \value NoSection  \value AmPmSection  \value MSecSection  \value SecondSection  \value MinuteSection  \value HourSection  \value DaySection  \value MonthSection  \value YearSection  \omitvalue DateSections_Mask  \omitvalue TimeSections_Mask*//*!  \fn void QDateTimeEdit::dateTimeChanged(const QDateTime &datetime)  This signal is emitted whenever the date or time is changed. The  new date and time is passed in \a datetime.*//*!  \fn void QDateTimeEdit::timeChanged(const QTime &time)  This signal is emitted whenever the time is changed. The new time  is passed in \a time.*//*!  \fn void QDateTimeEdit::dateChanged(const QDate &date)  This signal is emitted whenever the date is changed. The new date  is passed in \a date.*//*!  Constructs an empty date time editor with a \a parent.*/QDateTimeEdit::QDateTimeEdit(QWidget *parent)    : QAbstractSpinBox(*new QDateTimeEditPrivate, parent){    Q_D(QDateTimeEdit);    d->value = QVariant(QDateTime(QDATETIMEEDIT_DATE_INITIAL, QDATETIMEEDIT_TIME_MIN));    setDisplayFormat(d->defaultDateFormat + QLatin1String(" ") + d->defaultTimeFormat);    d->init();}/*!  Constructs an empty date time editor with a \a parent. The value  is set to \a datetime.*/QDateTimeEdit::QDateTimeEdit(const QDateTime &datetime, QWidget *parent)    : QAbstractSpinBox(*new QDateTimeEditPrivate, parent){    Q_D(QDateTimeEdit);    d->value = datetime.isValid() ? QVariant(datetime) : QVariant(QDateTime(QDATETIMEEDIT_DATE_INITIAL, QDATETIMEEDIT_TIME_MIN));    setDisplayFormat(d->defaultDateFormat + QLatin1String(" ") + d->defaultTimeFormat);    d->init();}/*!  \fn QDateTimeEdit::QDateTimeEdit(const QDate &date, QWidget *parent)  Constructs an empty date time editor with a \a parent.  The value is set to \a date.*/QDateTimeEdit::QDateTimeEdit(const QDate &date, QWidget *parent)    : QAbstractSpinBox(*new QDateTimeEditPrivate, parent){    Q_D(QDateTimeEdit);    d->value = QVariant(QDateTime(date.isValid() ? date : QDATETIMEEDIT_DATE_INITIAL, QDATETIMEEDIT_TIME_MIN));    setDisplayFormat(d->defaultDateFormat);    d->init();#ifdef QT_KEYPAD_NAVIGATION    if (QApplication::keypadNavigationEnabled())        setCalendarPopup(true);#endif}/*!  \fn QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent)  Constructs an empty date time editor with a \a parent.  The value is set to \a time.*/QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent)    : QAbstractSpinBox(*new QDateTimeEditPrivate, parent){    Q_D(QDateTimeEdit);    d->value = QVariant(QDateTime(QDATETIMEEDIT_DATE_INITIAL, time.isValid() ? time : QDATETIMEEDIT_TIME_MIN));    setDisplayFormat(d->defaultTimeFormat);    if (d->displayFormat.isEmpty()) {        d->defaultDateFormat = QLatin1String("hh:mm:ss");        setDisplayFormat(d->defaultTimeFormat);    }    d->init();}QDateTime QDateTimeEdit::dateTime() const{    Q_D(const QDateTimeEdit);    return d->value.toDateTime();}void QDateTimeEdit::setDateTime(const QDateTime &datetime){    Q_D(QDateTimeEdit);    if (datetime.isValid()) {        d->cachedDay = -1;        d->clearCache();        if (!(d->sections & DateSections_Mask))            setDateRange(datetime.date(), datetime.date());        d->setValue(QVariant(datetime), EmitIfChanged);    }}/*!  \property QDateTimeEdit::date  \brief the QDate that is set in the QDateTimeEdit  \sa time*//*!    \property QDateEdit::date    \brief the QDate that is edited in the QDateEdit*//*!    \property QTimeEdit::time    \brief the QTime that is edited in the QTimeEdit*//*!    Returns the date of the date time edit.*/QDate QDateTimeEdit::date() const{    Q_D(const QDateTimeEdit);    return d->value.toDate();}void QDateTimeEdit::setDate(const QDate &date){    Q_D(QDateTimeEdit);    if (date.isValid()) {        if (!(d->sections & DateSections_Mask))            setDateRange(date, date);        d->cachedDay = -1;        d->clearCache();        d->setValue(QVariant(QDateTime(date, d->value.toTime())), EmitIfChanged);    }}/*!  \property QDateTimeEdit::time  \brief the QTime that is set in the QDateTimeEdit  \sa date*//*!    Returns the time of the date time edit.*/QTime QDateTimeEdit::time() const{    Q_D(const QDateTimeEdit);    return d->value.toTime();}void QDateTimeEdit::setTime(const QTime &time){    Q_D(QDateTimeEdit);    if (time.isValid()) {        d->clearCache();        d->cachedDay = -1;        d->setValue(QVariant(QDateTime(d->value.toDate(), time)), EmitIfChanged);    }}/*!  \property QDateTimeEdit::dateTime  \brief the QDateTime that is set in the QDateTimeEdit  \sa minimumDate, minimumTime, maximumDate, maximumTime*//*!  \property QDateTimeEdit::minimumDate  \brief the minimum date of the date time edit  When setting this property the \l maximumDate is adjusted if  necessary, to ensure that the range remains valid. If the date is  not a valid QDate object, this function does nothing.  \sa minimumTime, maximumTime, setDateRange()*/QDate QDateTimeEdit::minimumDate() const{    Q_D(const QDateTimeEdit);    return d->minimum.toDate();}void QDateTimeEdit::setMinimumDate(const QDate &min){    Q_D(QDateTimeEdit);    if (min.isValid() && min >= QDATETIMEEDIT_DATE_MIN) {        const QVariant m(QDateTime(min, d->minimum.toTime()));        d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m));    }}void QDateTimeEdit::clearMinimumDate(){    setMinimumDate(QDATETIMEEDIT_COMPAT_DATE_MIN);}/*!  \property QDateTimeEdit::maximumDate  \brief the maximum date of the date time edit  When setting this property the \l minimumDate is adjusted if  necessary to ensure that the range remains valid. If the date is  not a valid QDate object, this function does nothing.  \sa minimumDate, minimumTime, maximumTime, setDateRange()*/QDate QDateTimeEdit::maximumDate() const{    Q_D(const QDateTimeEdit);    return d->maximum.toDate();}void QDateTimeEdit::setMaximumDate(const QDate &max){    Q_D(QDateTimeEdit);    if (max.isValid()) {        const QVariant m(QDateTime(max, d->maximum.toTime()));        d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m);    }}void QDateTimeEdit::clearMaximumDate(){    setMaximumDate(QDATETIMEEDIT_DATE_MAX);}/*!  \property QDateTimeEdit::minimumTime  \brief the minimum time of the date time edit  When setting this property the \l maximumTime is adjusted if  necessary, to ensure that the range remains valid. If the time is  not a valid QTime object, this function does nothing.  \sa maximumTime, minimumDate, maximumDate, setTimeRange()*/QTime QDateTimeEdit::minimumTime() const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -