1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2018 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QDATETIMEEDIT_P_H |
41 | #define QDATETIMEEDIT_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
55 | #include <QtCore/qcalendar.h> |
56 | #include "QtWidgets/qcalendarwidget.h" |
57 | #include "QtWidgets/qspinbox.h" |
58 | #include "QtWidgets/qtoolbutton.h" |
59 | #include "QtWidgets/qmenu.h" |
60 | #include "QtWidgets/qdatetimeedit.h" |
61 | #include "private/qabstractspinbox_p.h" |
62 | #include "private/qdatetimeparser_p.h" |
63 | |
64 | #include "qdebug.h" |
65 | |
66 | QT_BEGIN_NAMESPACE |
67 | |
68 | class QCalendarPopup; |
69 | class Q_AUTOTEST_EXPORT QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, public QDateTimeParser |
70 | { |
71 | Q_DECLARE_PUBLIC(QDateTimeEdit) |
72 | public: |
73 | QDateTimeEditPrivate(); |
74 | |
75 | void init(const QVariant &var); |
76 | void readLocaleSettings(); |
77 | |
78 | QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state, |
79 | bool fixup = false) const; |
80 | void clearSection(int index); |
81 | |
82 | // Override QAbstractSpinBoxPrivate: |
83 | void emitSignals(EmitPolicy ep, const QVariant &old) override; |
84 | QString textFromValue(const QVariant &f) const override; |
85 | QVariant valueFromText(const QString &f) const override; |
86 | void _q_editorCursorPositionChanged(int oldpos, int newpos) override; |
87 | void interpret(EmitPolicy ep) override; |
88 | void clearCache() const override; |
89 | QStyle::SubControl newHoverControl(const QPoint &pos) override; |
90 | void updateEditFieldGeometry() override; |
91 | QVariant getZeroVariant() const override; |
92 | void setRange(const QVariant &min, const QVariant &max) override; |
93 | void updateEdit() override; |
94 | |
95 | // Override QDateTimeParser: |
96 | QString displayText() const override { return edit->text(); } |
97 | QDateTime getMinimum() const override |
98 | { |
99 | if (keyboardTracking) |
100 | return minimum.toDateTime(); |
101 | if (spec != Qt::LocalTime) |
102 | return QDateTime(QDATETIMEEDIT_DATE_MIN.startOfDay(spec)); |
103 | return QDateTimeParser::getMinimum(); |
104 | } |
105 | QDateTime getMaximum() const override |
106 | { |
107 | if (keyboardTracking) |
108 | return maximum.toDateTime(); |
109 | if (spec != Qt::LocalTime) |
110 | return QDateTime(QDATETIMEEDIT_DATE_MAX.endOfDay(spec)); |
111 | return QDateTimeParser::getMaximum(); |
112 | } |
113 | QLocale locale() const override { return q_func()->locale(); } |
114 | QString getAmPmText(AmPm ap, Case cs) const override; |
115 | int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; } |
116 | |
117 | int absoluteIndex(QDateTimeEdit::Section s, int index) const; |
118 | int absoluteIndex(const SectionNode &s) const; |
119 | QDateTime stepBy(int index, int steps, bool test = false) const; |
120 | int sectionAt(int pos) const; |
121 | int closestSection(int index, bool forward) const; |
122 | int nextPrevSection(int index, bool forward) const; |
123 | void setSelected(int index, bool forward = false); |
124 | |
125 | void updateCache(const QVariant &val, const QString &str) const; |
126 | |
127 | void updateTimeSpec(); |
128 | QString valueToText(const QVariant &var) const { return textFromValue(f: var); } |
129 | |
130 | void _q_resetButton(); |
131 | void updateArrow(QStyle::StateFlag state); |
132 | bool () const; |
133 | void syncCalendarWidget(); |
134 | |
135 | bool isSeparatorKey(const QKeyEvent *k) const; |
136 | |
137 | static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s); |
138 | static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s); |
139 | |
140 | void (QCalendarWidget *cw = nullptr); |
141 | void (); |
142 | |
143 | QDateTimeEdit::Sections sections; |
144 | mutable bool cacheGuard; |
145 | |
146 | QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat; |
147 | mutable QVariant conflictGuard; |
148 | bool hasHadFocus, formatExplicitlySet, ; |
149 | QStyle::StateFlag arrowState; |
150 | QCalendarPopup *monthCalendar; |
151 | |
152 | #ifdef QT_KEYPAD_NAVIGATION |
153 | bool focusOnButton; |
154 | #endif |
155 | |
156 | Qt::TimeSpec spec = Qt::LocalTime; |
157 | }; |
158 | |
159 | |
160 | class : public QWidget |
161 | { |
162 | Q_OBJECT |
163 | public: |
164 | explicit (QWidget *parent = nullptr, QCalendarWidget *cw = nullptr, |
165 | QCalendar ca = QCalendar()); |
166 | QDate () { return verifyCalendarInstance()->selectedDate(); } |
167 | void (QDate date); |
168 | void (QDate min, QDate max); |
169 | void (Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); } |
170 | QCalendarWidget *() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); } |
171 | void (QCalendarWidget *cw); |
172 | Q_SIGNALS: |
173 | void (QDate date); |
174 | void (QDate newDate); |
175 | void (QDate oldDate); |
176 | void (); |
177 | |
178 | private Q_SLOTS: |
179 | void (QDate date); |
180 | void (); |
181 | |
182 | protected: |
183 | void (QHideEvent *) override; |
184 | void (QMouseEvent *e) override; |
185 | void (QMouseEvent *) override; |
186 | bool (QEvent *e) override; |
187 | |
188 | private: |
189 | QCalendarWidget *(); |
190 | |
191 | QPointer<QCalendarWidget> ; |
192 | QDate ; |
193 | bool ; |
194 | QCalendar ; |
195 | }; |
196 | |
197 | QT_END_NAMESPACE |
198 | |
199 | #endif // QDATETIMEEDIT_P_H |
200 | |