1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QDATETIMEEDIT_P_H |
5 | #define QDATETIMEEDIT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include <QtCore/qcalendar.h> |
20 | #include <QtCore/qdatetime.h> |
21 | #include <QtCore/qtimezone.h> |
22 | #include "QtWidgets/qcalendarwidget.h" |
23 | #include "QtWidgets/qspinbox.h" |
24 | #include "QtWidgets/qtoolbutton.h" |
25 | #include "QtWidgets/qmenu.h" |
26 | #include "QtWidgets/qdatetimeedit.h" |
27 | #include "private/qabstractspinbox_p.h" |
28 | #include "private/qdatetimeparser_p.h" |
29 | |
30 | #include "qdebug.h" |
31 | |
32 | QT_BEGIN_NAMESPACE |
33 | |
34 | class QCalendarPopup; |
35 | class Q_AUTOTEST_EXPORT QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, public QDateTimeParser |
36 | { |
37 | Q_DECLARE_PUBLIC(QDateTimeEdit) |
38 | public: |
39 | QDateTimeEditPrivate(const QTimeZone &zone = QTimeZone::LocalTime); |
40 | |
41 | void init(const QVariant &var); |
42 | void readLocaleSettings(); |
43 | |
44 | QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state, |
45 | bool fixup = false) const; |
46 | void clearSection(int index); |
47 | |
48 | // Override QAbstractSpinBoxPrivate: |
49 | void emitSignals(EmitPolicy ep, const QVariant &old) override; |
50 | QString textFromValue(const QVariant &f) const override; |
51 | QVariant valueFromText(const QString &f) const override; |
52 | void _q_editorCursorPositionChanged(int oldpos, int newpos) override; |
53 | void interpret(EmitPolicy ep) override; |
54 | void clearCache() const override; |
55 | QStyle::SubControl newHoverControl(const QPoint &pos) override; |
56 | void updateEditFieldGeometry() override; |
57 | QVariant getZeroVariant() const override; |
58 | void setRange(const QVariant &min, const QVariant &max) override; |
59 | void updateEdit() override; |
60 | |
61 | // Override QDateTimeParser: |
62 | QString displayText() const override { return edit->text(); } |
63 | QDateTime getMinimum() const override; |
64 | QDateTime getMaximum() const override; |
65 | QLocale locale() const override { return q_func()->locale(); } |
66 | int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; } |
67 | |
68 | int absoluteIndex(QDateTimeEdit::Section s, int index) const; |
69 | int absoluteIndex(const SectionNode &s) const; |
70 | QDateTime stepBy(int index, int steps, bool test = false) const; |
71 | int sectionAt(int pos) const; |
72 | int closestSection(int index, bool forward) const; |
73 | int nextPrevSection(int index, bool forward) const; |
74 | void setSelected(int index, bool forward = false); |
75 | |
76 | void updateCache(const QVariant &val, const QString &str) const; |
77 | |
78 | QDateTime convertTimeZone(const QDateTime &datetime); |
79 | void updateTimeZone(); |
80 | QString valueToText(const QVariant &var) const { return textFromValue(f: var); } |
81 | QDateTime dateTimeValue(QDate date, QTime time) const; |
82 | |
83 | void _q_resetButton(); |
84 | void updateArrow(QStyle::StateFlag state); |
85 | bool () const; |
86 | void syncCalendarWidget(); |
87 | |
88 | bool isSeparatorKey(const QKeyEvent *k) const; |
89 | |
90 | static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s); |
91 | static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s); |
92 | |
93 | void (QCalendarWidget *cw = nullptr); |
94 | void (); |
95 | |
96 | QDateTimeEdit::Sections sections = {}; |
97 | mutable bool cacheGuard = false; |
98 | |
99 | QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat; |
100 | mutable QVariant conflictGuard; |
101 | bool hasHadFocus = false, formatExplicitlySet = false, = false; |
102 | QStyle::StateFlag arrowState = QStyle::State_None; |
103 | QCalendarPopup *monthCalendar = nullptr; |
104 | |
105 | #ifdef QT_KEYPAD_NAVIGATION |
106 | bool focusOnButton = false; |
107 | #endif |
108 | |
109 | QTimeZone timeZone; |
110 | }; |
111 | |
112 | |
113 | class : public QWidget |
114 | { |
115 | Q_OBJECT |
116 | public: |
117 | explicit (QWidget *parent = nullptr, QCalendarWidget *cw = nullptr, |
118 | QCalendar ca = QCalendar()); |
119 | QDate () { return verifyCalendarInstance()->selectedDate(); } |
120 | void (QDate date); |
121 | void (QDate min, QDate max); |
122 | void (Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); } |
123 | QCalendarWidget *() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); } |
124 | void (QCalendarWidget *cw); |
125 | Q_SIGNALS: |
126 | void (QDate date); |
127 | void (QDate newDate); |
128 | void (QDate oldDate); |
129 | void (); |
130 | |
131 | private Q_SLOTS: |
132 | void (QDate date); |
133 | void (); |
134 | |
135 | protected: |
136 | void (QHideEvent *) override; |
137 | void (QMouseEvent *e) override; |
138 | void (QMouseEvent *) override; |
139 | bool (QEvent *e) override; |
140 | |
141 | private: |
142 | QCalendarWidget *(); |
143 | |
144 | QPointer<QCalendarWidget> ; |
145 | QDate ; |
146 | bool ; |
147 | QCalendar ; |
148 | }; |
149 | |
150 | QT_END_NAMESPACE |
151 | |
152 | #endif // QDATETIMEEDIT_P_H |
153 | |