Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qcalendarwidget.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qcalendarwidget.h" | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | #ifndef QT_NO_CALENDARWIDGET | - | ||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
38 | #include <qabstractitemmodel.h> | - | ||||||||||||||||||||||||
39 | #include <qitemdelegate.h> | - | ||||||||||||||||||||||||
40 | #include <qdatetime.h> | - | ||||||||||||||||||||||||
41 | #include <qtableview.h> | - | ||||||||||||||||||||||||
42 | #include <qlayout.h> | - | ||||||||||||||||||||||||
43 | #include <qevent.h> | - | ||||||||||||||||||||||||
44 | #include <qtextformat.h> | - | ||||||||||||||||||||||||
45 | #include <qheaderview.h> | - | ||||||||||||||||||||||||
46 | #include <private/qwidget_p.h> | - | ||||||||||||||||||||||||
47 | #include <qpushbutton.h> | - | ||||||||||||||||||||||||
48 | #include <qtoolbutton.h> | - | ||||||||||||||||||||||||
49 | #include <qlabel.h> | - | ||||||||||||||||||||||||
50 | #include <qspinbox.h> | - | ||||||||||||||||||||||||
51 | #include <qmenu.h> | - | ||||||||||||||||||||||||
52 | #include <qapplication.h> | - | ||||||||||||||||||||||||
53 | #include <qbasictimer.h> | - | ||||||||||||||||||||||||
54 | #include <qstylepainter.h> | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | enum { | - | ||||||||||||||||||||||||
59 | RowCount = 6, | - | ||||||||||||||||||||||||
60 | ColumnCount = 7, | - | ||||||||||||||||||||||||
61 | HeaderColumn = 0, | - | ||||||||||||||||||||||||
62 | HeaderRow = 0, | - | ||||||||||||||||||||||||
63 | MinimumDayOffset = 1 | - | ||||||||||||||||||||||||
64 | }; | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | namespace { | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | static QString formatNumber(int number, int fieldWidth) | - | ||||||||||||||||||||||||
69 | { | - | ||||||||||||||||||||||||
70 | return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0')); never executed: return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0')); | 0 | ||||||||||||||||||||||||
71 | } | - | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | class QCalendarDateSectionValidator | - | ||||||||||||||||||||||||
74 | { | - | ||||||||||||||||||||||||
75 | public: | - | ||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | enum Section { | - | ||||||||||||||||||||||||
78 | NextSection, | - | ||||||||||||||||||||||||
79 | ThisSection, | - | ||||||||||||||||||||||||
80 | PrevSection | - | ||||||||||||||||||||||||
81 | }; | - | ||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||
83 | QCalendarDateSectionValidator() {} | - | ||||||||||||||||||||||||
84 | virtual ~QCalendarDateSectionValidator() {} | - | ||||||||||||||||||||||||
85 | virtual Section handleKey(int key) = 0; | - | ||||||||||||||||||||||||
86 | virtual QDate applyToDate(const QDate &date) const = 0; | - | ||||||||||||||||||||||||
87 | virtual void setDate(const QDate &date) = 0; | - | ||||||||||||||||||||||||
88 | virtual QString text() const = 0; | - | ||||||||||||||||||||||||
89 | virtual QString text(const QDate &date, int repeat) const = 0; | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | QLocale m_locale; | - | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | protected: | - | ||||||||||||||||||||||||
94 | static QString highlightString(const QString &str, int pos); | - | ||||||||||||||||||||||||
95 | private: | - | ||||||||||||||||||||||||
96 | }; | - | ||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | QString QCalendarDateSectionValidator::highlightString(const QString &str, int pos) | - | ||||||||||||||||||||||||
99 | { | - | ||||||||||||||||||||||||
100 | if (pos == 0)
| 0 | ||||||||||||||||||||||||
101 | return QLatin1String("<b>") + str + QLatin1String("</b>"); never executed: return QLatin1String("<b>") + str + QLatin1String("</b>"); | 0 | ||||||||||||||||||||||||
102 | int startPos = str.length() - pos; | - | ||||||||||||||||||||||||
103 | return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>"); never executed: return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>"); | 0 | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | } | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | class QCalendarDayValidator : public QCalendarDateSectionValidator | - | ||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | public: | - | ||||||||||||||||||||||||
111 | QCalendarDayValidator(); | - | ||||||||||||||||||||||||
112 | virtual Section handleKey(int key) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
113 | virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
114 | virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
115 | virtual QString text() const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
116 | virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
117 | private: | - | ||||||||||||||||||||||||
118 | int m_pos; | - | ||||||||||||||||||||||||
119 | int m_day; | - | ||||||||||||||||||||||||
120 | int m_oldDay; | - | ||||||||||||||||||||||||
121 | }; | - | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | QCalendarDayValidator::QCalendarDayValidator() | - | ||||||||||||||||||||||||
124 | : QCalendarDateSectionValidator(), m_pos(0), m_day(1), m_oldDay(1) | - | ||||||||||||||||||||||||
125 | { | - | ||||||||||||||||||||||||
126 | } never executed: end of block | 0 | ||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||
128 | QCalendarDateSectionValidator::Section QCalendarDayValidator::handleKey(int key) | - | ||||||||||||||||||||||||
129 | { | - | ||||||||||||||||||||||||
130 | if (key == Qt::Key_Right || key == Qt::Key_Left) {
| 0 | ||||||||||||||||||||||||
131 | m_pos = 0; | - | ||||||||||||||||||||||||
132 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
133 | } else if (key == Qt::Key_Up) {
| 0 | ||||||||||||||||||||||||
134 | m_pos = 0; | - | ||||||||||||||||||||||||
135 | ++m_day; | - | ||||||||||||||||||||||||
136 | if (m_day > 31)
| 0 | ||||||||||||||||||||||||
137 | m_day = 1; never executed: m_day = 1; | 0 | ||||||||||||||||||||||||
138 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
139 | } else if (key == Qt::Key_Down) {
| 0 | ||||||||||||||||||||||||
140 | m_pos = 0; | - | ||||||||||||||||||||||||
141 | --m_day; | - | ||||||||||||||||||||||||
142 | if (m_day < 1)
| 0 | ||||||||||||||||||||||||
143 | m_day = 31; never executed: m_day = 31; | 0 | ||||||||||||||||||||||||
144 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
145 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
| 0 | ||||||||||||||||||||||||
146 | --m_pos; | - | ||||||||||||||||||||||||
147 | if (m_pos < 0)
| 0 | ||||||||||||||||||||||||
148 | m_pos = 1; never executed: m_pos = 1; | 0 | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
151 | m_day = m_oldDay; never executed: m_day = m_oldDay; | 0 | ||||||||||||||||||||||||
152 | else | - | ||||||||||||||||||||||||
153 | m_day = m_day / 10; never executed: m_day = m_day / 10; | 0 | ||||||||||||||||||||||||
154 | //m_day = m_oldDay / 10 * 10 + m_day / 10; | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
157 | return QCalendarDateSectionValidator::PrevSection; never executed: return QCalendarDateSectionValidator::PrevSection; | 0 | ||||||||||||||||||||||||
158 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
159 | } | - | ||||||||||||||||||||||||
160 | if (key < Qt::Key_0 || key > Qt::Key_9)
| 0 | ||||||||||||||||||||||||
161 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
162 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||||||||||||||
163 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
164 | m_day = pressedKey; never executed: m_day = pressedKey; | 0 | ||||||||||||||||||||||||
165 | else | - | ||||||||||||||||||||||||
166 | m_day = m_day % 10 * 10 + pressedKey; never executed: m_day = m_day % 10 * 10 + pressedKey; | 0 | ||||||||||||||||||||||||
167 | if (m_day > 31)
| 0 | ||||||||||||||||||||||||
168 | m_day = 31; never executed: m_day = 31; | 0 | ||||||||||||||||||||||||
169 | ++m_pos; | - | ||||||||||||||||||||||||
170 | if (m_pos > 1) {
| 0 | ||||||||||||||||||||||||
171 | m_pos = 0; | - | ||||||||||||||||||||||||
172 | return QCalendarDateSectionValidator::NextSection; never executed: return QCalendarDateSectionValidator::NextSection; | 0 | ||||||||||||||||||||||||
173 | } | - | ||||||||||||||||||||||||
174 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
175 | } | - | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | QDate QCalendarDayValidator::applyToDate(const QDate &date) const | - | ||||||||||||||||||||||||
178 | { | - | ||||||||||||||||||||||||
179 | int day = m_day; | - | ||||||||||||||||||||||||
180 | if (day < 1)
| 0 | ||||||||||||||||||||||||
181 | day = 1; never executed: day = 1; | 0 | ||||||||||||||||||||||||
182 | else if (day > 31)
| 0 | ||||||||||||||||||||||||
183 | day = 31; never executed: day = 31; | 0 | ||||||||||||||||||||||||
184 | if (day > date.daysInMonth())
| 0 | ||||||||||||||||||||||||
185 | day = date.daysInMonth(); never executed: day = date.daysInMonth(); | 0 | ||||||||||||||||||||||||
186 | return QDate(date.year(), date.month(), day); never executed: return QDate(date.year(), date.month(), day); | 0 | ||||||||||||||||||||||||
187 | } | - | ||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||
189 | void QCalendarDayValidator::setDate(const QDate &date) | - | ||||||||||||||||||||||||
190 | { | - | ||||||||||||||||||||||||
191 | m_day = m_oldDay = date.day(); | - | ||||||||||||||||||||||||
192 | m_pos = 0; | - | ||||||||||||||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | QString QCalendarDayValidator::text() const | - | ||||||||||||||||||||||||
196 | { | - | ||||||||||||||||||||||||
197 | return highlightString(formatNumber(m_day, 2), m_pos); never executed: return highlightString(formatNumber(m_day, 2), m_pos); | 0 | ||||||||||||||||||||||||
198 | } | - | ||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||
200 | QString QCalendarDayValidator::text(const QDate &date, int repeat) const | - | ||||||||||||||||||||||||
201 | { | - | ||||||||||||||||||||||||
202 | if (repeat <= 1) {
| 0 | ||||||||||||||||||||||||
203 | return QString::number(date.day()); never executed: return QString::number(date.day()); | 0 | ||||||||||||||||||||||||
204 | } else if (repeat == 2) {
| 0 | ||||||||||||||||||||||||
205 | return formatNumber(date.day(), 2); never executed: return formatNumber(date.day(), 2); | 0 | ||||||||||||||||||||||||
206 | } else if (repeat == 3) {
| 0 | ||||||||||||||||||||||||
207 | return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat); never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||
208 | } else /* repeat >= 4 */ { | - | ||||||||||||||||||||||||
209 | return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat); never executed: return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat); | 0 | ||||||||||||||||||||||||
210 | } | - | ||||||||||||||||||||||||
211 | } | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | ////////////////////////////////// | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | class QCalendarMonthValidator : public QCalendarDateSectionValidator | - | ||||||||||||||||||||||||
216 | { | - | ||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | public: | - | ||||||||||||||||||||||||
219 | QCalendarMonthValidator(); | - | ||||||||||||||||||||||||
220 | virtual Section handleKey(int key) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
221 | virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
222 | virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
223 | virtual QString text() const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
224 | virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
225 | private: | - | ||||||||||||||||||||||||
226 | int m_pos; | - | ||||||||||||||||||||||||
227 | int m_month; | - | ||||||||||||||||||||||||
228 | int m_oldMonth; | - | ||||||||||||||||||||||||
229 | }; | - | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | QCalendarMonthValidator::QCalendarMonthValidator() | - | ||||||||||||||||||||||||
232 | : QCalendarDateSectionValidator(), m_pos(0), m_month(1), m_oldMonth(1) | - | ||||||||||||||||||||||||
233 | { | - | ||||||||||||||||||||||||
234 | } never executed: end of block | 0 | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | QCalendarDateSectionValidator::Section QCalendarMonthValidator::handleKey(int key) | - | ||||||||||||||||||||||||
237 | { | - | ||||||||||||||||||||||||
238 | if (key == Qt::Key_Right || key == Qt::Key_Left) {
| 0 | ||||||||||||||||||||||||
239 | m_pos = 0; | - | ||||||||||||||||||||||||
240 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
241 | } else if (key == Qt::Key_Up) {
| 0 | ||||||||||||||||||||||||
242 | m_pos = 0; | - | ||||||||||||||||||||||||
243 | ++m_month; | - | ||||||||||||||||||||||||
244 | if (m_month > 12)
| 0 | ||||||||||||||||||||||||
245 | m_month = 1; never executed: m_month = 1; | 0 | ||||||||||||||||||||||||
246 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
247 | } else if (key == Qt::Key_Down) {
| 0 | ||||||||||||||||||||||||
248 | m_pos = 0; | - | ||||||||||||||||||||||||
249 | --m_month; | - | ||||||||||||||||||||||||
250 | if (m_month < 1)
| 0 | ||||||||||||||||||||||||
251 | m_month = 12; never executed: m_month = 12; | 0 | ||||||||||||||||||||||||
252 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
253 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
| 0 | ||||||||||||||||||||||||
254 | --m_pos; | - | ||||||||||||||||||||||||
255 | if (m_pos < 0)
| 0 | ||||||||||||||||||||||||
256 | m_pos = 1; never executed: m_pos = 1; | 0 | ||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||
258 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
259 | m_month = m_oldMonth; never executed: m_month = m_oldMonth; | 0 | ||||||||||||||||||||||||
260 | else | - | ||||||||||||||||||||||||
261 | m_month = m_month / 10; never executed: m_month = m_month / 10; | 0 | ||||||||||||||||||||||||
262 | //m_month = m_oldMonth / 10 * 10 + m_month / 10; | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
265 | return QCalendarDateSectionValidator::PrevSection; never executed: return QCalendarDateSectionValidator::PrevSection; | 0 | ||||||||||||||||||||||||
266 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
267 | } | - | ||||||||||||||||||||||||
268 | if (key < Qt::Key_0 || key > Qt::Key_9)
| 0 | ||||||||||||||||||||||||
269 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
270 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||||||||||||||
271 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
272 | m_month = pressedKey; never executed: m_month = pressedKey; | 0 | ||||||||||||||||||||||||
273 | else | - | ||||||||||||||||||||||||
274 | m_month = m_month % 10 * 10 + pressedKey; never executed: m_month = m_month % 10 * 10 + pressedKey; | 0 | ||||||||||||||||||||||||
275 | if (m_month > 12)
| 0 | ||||||||||||||||||||||||
276 | m_month = 12; never executed: m_month = 12; | 0 | ||||||||||||||||||||||||
277 | ++m_pos; | - | ||||||||||||||||||||||||
278 | if (m_pos > 1) {
| 0 | ||||||||||||||||||||||||
279 | m_pos = 0; | - | ||||||||||||||||||||||||
280 | return QCalendarDateSectionValidator::NextSection; never executed: return QCalendarDateSectionValidator::NextSection; | 0 | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
282 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
283 | } | - | ||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||
285 | QDate QCalendarMonthValidator::applyToDate(const QDate &date) const | - | ||||||||||||||||||||||||
286 | { | - | ||||||||||||||||||||||||
287 | int month = m_month; | - | ||||||||||||||||||||||||
288 | if (month < 1)
| 0 | ||||||||||||||||||||||||
289 | month = 1; never executed: month = 1; | 0 | ||||||||||||||||||||||||
290 | else if (month > 12)
| 0 | ||||||||||||||||||||||||
291 | month = 12; never executed: month = 12; | 0 | ||||||||||||||||||||||||
292 | QDate newDate(date.year(), m_month, 1); | - | ||||||||||||||||||||||||
293 | int day = date.day(); | - | ||||||||||||||||||||||||
294 | if (day > newDate.daysInMonth())
| 0 | ||||||||||||||||||||||||
295 | day = newDate.daysInMonth(); never executed: day = newDate.daysInMonth(); | 0 | ||||||||||||||||||||||||
296 | return QDate(date.year(), month, day); never executed: return QDate(date.year(), month, day); | 0 | ||||||||||||||||||||||||
297 | } | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | void QCalendarMonthValidator::setDate(const QDate &date) | - | ||||||||||||||||||||||||
300 | { | - | ||||||||||||||||||||||||
301 | m_month = m_oldMonth = date.month(); | - | ||||||||||||||||||||||||
302 | m_pos = 0; | - | ||||||||||||||||||||||||
303 | } never executed: end of block | 0 | ||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||
305 | QString QCalendarMonthValidator::text() const | - | ||||||||||||||||||||||||
306 | { | - | ||||||||||||||||||||||||
307 | return highlightString(formatNumber(m_month, 2), m_pos); never executed: return highlightString(formatNumber(m_month, 2), m_pos); | 0 | ||||||||||||||||||||||||
308 | } | - | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | QString QCalendarMonthValidator::text(const QDate &date, int repeat) const | - | ||||||||||||||||||||||||
311 | { | - | ||||||||||||||||||||||||
312 | if (repeat <= 1) {
| 0 | ||||||||||||||||||||||||
313 | return QString::number(date.month()); never executed: return QString::number(date.month()); | 0 | ||||||||||||||||||||||||
314 | } else if (repeat == 2) {
| 0 | ||||||||||||||||||||||||
315 | return formatNumber(date.month(), 2); never executed: return formatNumber(date.month(), 2); | 0 | ||||||||||||||||||||||||
316 | } else if (repeat == 3) {
| 0 | ||||||||||||||||||||||||
317 | return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat); never executed: return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||
318 | } else /*if (repeat >= 4)*/ { | - | ||||||||||||||||||||||||
319 | return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat); never executed: return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat); | 0 | ||||||||||||||||||||||||
320 | } | - | ||||||||||||||||||||||||
321 | } | - | ||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||
323 | ////////////////////////////////// | - | ||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||
325 | class QCalendarYearValidator : public QCalendarDateSectionValidator | - | ||||||||||||||||||||||||
326 | { | - | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | public: | - | ||||||||||||||||||||||||
329 | QCalendarYearValidator(); | - | ||||||||||||||||||||||||
330 | virtual Section handleKey(int key) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
331 | virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
332 | virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
333 | virtual QString text() const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
334 | virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
335 | private: | - | ||||||||||||||||||||||||
336 | int pow10(int n); | - | ||||||||||||||||||||||||
337 | int m_pos; | - | ||||||||||||||||||||||||
338 | int m_year; | - | ||||||||||||||||||||||||
339 | int m_oldYear; | - | ||||||||||||||||||||||||
340 | }; | - | ||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||
342 | QCalendarYearValidator::QCalendarYearValidator() | - | ||||||||||||||||||||||||
343 | : QCalendarDateSectionValidator(), m_pos(0), m_year(2000), m_oldYear(2000) | - | ||||||||||||||||||||||||
344 | { | - | ||||||||||||||||||||||||
345 | } never executed: end of block | 0 | ||||||||||||||||||||||||
346 | - | |||||||||||||||||||||||||
347 | int QCalendarYearValidator::pow10(int n) | - | ||||||||||||||||||||||||
348 | { | - | ||||||||||||||||||||||||
349 | int power = 1; | - | ||||||||||||||||||||||||
350 | for (int i = 0; i < n; i++)
| 0 | ||||||||||||||||||||||||
351 | power *= 10; never executed: power *= 10; | 0 | ||||||||||||||||||||||||
352 | return power; never executed: return power; | 0 | ||||||||||||||||||||||||
353 | } | - | ||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||
355 | QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey(int key) | - | ||||||||||||||||||||||||
356 | { | - | ||||||||||||||||||||||||
357 | if (key == Qt::Key_Right || key == Qt::Key_Left) {
| 0 | ||||||||||||||||||||||||
358 | m_pos = 0; | - | ||||||||||||||||||||||||
359 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
360 | } else if (key == Qt::Key_Up) {
| 0 | ||||||||||||||||||||||||
361 | m_pos = 0; | - | ||||||||||||||||||||||||
362 | ++m_year; | - | ||||||||||||||||||||||||
363 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
364 | } else if (key == Qt::Key_Down) {
| 0 | ||||||||||||||||||||||||
365 | m_pos = 0; | - | ||||||||||||||||||||||||
366 | --m_year; | - | ||||||||||||||||||||||||
367 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
368 | } else if (key == Qt::Key_Back || key == Qt::Key_Backspace) {
| 0 | ||||||||||||||||||||||||
369 | --m_pos; | - | ||||||||||||||||||||||||
370 | if (m_pos < 0)
| 0 | ||||||||||||||||||||||||
371 | m_pos = 3; never executed: m_pos = 3; | 0 | ||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||
373 | int pow = pow10(m_pos); | - | ||||||||||||||||||||||||
374 | m_year = m_oldYear / pow * pow + m_year % (pow * 10) / 10; | - | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | if (m_pos == 0)
| 0 | ||||||||||||||||||||||||
377 | return QCalendarDateSectionValidator::PrevSection; never executed: return QCalendarDateSectionValidator::PrevSection; | 0 | ||||||||||||||||||||||||
378 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
379 | } | - | ||||||||||||||||||||||||
380 | if (key < Qt::Key_0 || key > Qt::Key_9)
| 0 | ||||||||||||||||||||||||
381 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
382 | int pressedKey = key - Qt::Key_0; | - | ||||||||||||||||||||||||
383 | int pow = pow10(m_pos); | - | ||||||||||||||||||||||||
384 | m_year = m_year / (pow * 10) * (pow * 10) + m_year % pow * 10 + pressedKey; | - | ||||||||||||||||||||||||
385 | ++m_pos; | - | ||||||||||||||||||||||||
386 | if (m_pos > 3) {
| 0 | ||||||||||||||||||||||||
387 | m_pos = 0; | - | ||||||||||||||||||||||||
388 | return QCalendarDateSectionValidator::NextSection; never executed: return QCalendarDateSectionValidator::NextSection; | 0 | ||||||||||||||||||||||||
389 | } | - | ||||||||||||||||||||||||
390 | return QCalendarDateSectionValidator::ThisSection; never executed: return QCalendarDateSectionValidator::ThisSection; | 0 | ||||||||||||||||||||||||
391 | } | - | ||||||||||||||||||||||||
392 | - | |||||||||||||||||||||||||
393 | QDate QCalendarYearValidator::applyToDate(const QDate &date) const | - | ||||||||||||||||||||||||
394 | { | - | ||||||||||||||||||||||||
395 | int year = m_year; | - | ||||||||||||||||||||||||
396 | if (year < 1)
| 0 | ||||||||||||||||||||||||
397 | year = 1; never executed: year = 1; | 0 | ||||||||||||||||||||||||
398 | QDate newDate(year, date.month(), 1); | - | ||||||||||||||||||||||||
399 | int day = date.day(); | - | ||||||||||||||||||||||||
400 | if (day > newDate.daysInMonth())
| 0 | ||||||||||||||||||||||||
401 | day = newDate.daysInMonth(); never executed: day = newDate.daysInMonth(); | 0 | ||||||||||||||||||||||||
402 | return QDate(year, date.month(), day); never executed: return QDate(year, date.month(), day); | 0 | ||||||||||||||||||||||||
403 | } | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | void QCalendarYearValidator::setDate(const QDate &date) | - | ||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||
407 | m_year = m_oldYear = date.year(); | - | ||||||||||||||||||||||||
408 | m_pos = 0; | - | ||||||||||||||||||||||||
409 | } never executed: end of block | 0 | ||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | QString QCalendarYearValidator::text() const | - | ||||||||||||||||||||||||
412 | { | - | ||||||||||||||||||||||||
413 | return highlightString(formatNumber(m_year, 4), m_pos); never executed: return highlightString(formatNumber(m_year, 4), m_pos); | 0 | ||||||||||||||||||||||||
414 | } | - | ||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||
416 | QString QCalendarYearValidator::text(const QDate &date, int repeat) const | - | ||||||||||||||||||||||||
417 | { | - | ||||||||||||||||||||||||
418 | if (repeat < 4)
| 0 | ||||||||||||||||||||||||
419 | return formatNumber(date.year() % 100, 2); never executed: return formatNumber(date.year() % 100, 2); | 0 | ||||||||||||||||||||||||
420 | return QString::number(date.year()); never executed: return QString::number(date.year()); | 0 | ||||||||||||||||||||||||
421 | } | - | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | /////////////////////////////////// | - | ||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||
425 | class QCalendarDateValidator | - | ||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||
427 | public: | - | ||||||||||||||||||||||||
428 | QCalendarDateValidator(); | - | ||||||||||||||||||||||||
429 | ~QCalendarDateValidator(); | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | void handleKeyEvent(QKeyEvent *keyEvent); | - | ||||||||||||||||||||||||
432 | QString currentText() const; | - | ||||||||||||||||||||||||
433 | QDate currentDate() const { return m_currentDate; } never executed: return m_currentDate; | 0 | ||||||||||||||||||||||||
434 | void setFormat(const QString &format); | - | ||||||||||||||||||||||||
435 | void setInitialDate(const QDate &date); | - | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | void setLocale(const QLocale &locale); | - | ||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||
439 | private: | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | struct SectionToken { | - | ||||||||||||||||||||||||
442 | SectionToken(QCalendarDateSectionValidator *val, int rep) : validator(val), repeat(rep) {} never executed: end of block | 0 | ||||||||||||||||||||||||
443 | QCalendarDateSectionValidator *validator; | - | ||||||||||||||||||||||||
444 | int repeat; | - | ||||||||||||||||||||||||
445 | }; | - | ||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||
447 | void toNextToken(); | - | ||||||||||||||||||||||||
448 | void toPreviousToken(); | - | ||||||||||||||||||||||||
449 | void applyToDate(); | - | ||||||||||||||||||||||||
450 | - | |||||||||||||||||||||||||
451 | int countRepeat(const QString &str, int index) const; | - | ||||||||||||||||||||||||
452 | void clear(); | - | ||||||||||||||||||||||||
453 | - | |||||||||||||||||||||||||
454 | QStringList m_separators; | - | ||||||||||||||||||||||||
455 | QList<SectionToken *> m_tokens; | - | ||||||||||||||||||||||||
456 | QCalendarYearValidator m_yearValidator; | - | ||||||||||||||||||||||||
457 | QCalendarMonthValidator m_monthValidator; | - | ||||||||||||||||||||||||
458 | QCalendarDayValidator m_dayValidator; | - | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | SectionToken *m_currentToken; | - | ||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||
462 | QDate m_initialDate; | - | ||||||||||||||||||||||||
463 | QDate m_currentDate; | - | ||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||
465 | QCalendarDateSectionValidator::Section m_lastSectionMove; | - | ||||||||||||||||||||||||
466 | }; | - | ||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||
468 | QCalendarDateValidator::QCalendarDateValidator() | - | ||||||||||||||||||||||||
469 | : m_currentToken(Q_NULLPTR), | - | ||||||||||||||||||||||||
470 | m_initialDate(QDate::currentDate()), | - | ||||||||||||||||||||||||
471 | m_currentDate(m_initialDate), | - | ||||||||||||||||||||||||
472 | m_lastSectionMove(QCalendarDateSectionValidator::ThisSection) | - | ||||||||||||||||||||||||
473 | { | - | ||||||||||||||||||||||||
474 | } never executed: end of block | 0 | ||||||||||||||||||||||||
475 | - | |||||||||||||||||||||||||
476 | void QCalendarDateValidator::setLocale(const QLocale &locale) | - | ||||||||||||||||||||||||
477 | { | - | ||||||||||||||||||||||||
478 | m_yearValidator.m_locale = locale; | - | ||||||||||||||||||||||||
479 | m_monthValidator.m_locale = locale; | - | ||||||||||||||||||||||||
480 | m_dayValidator.m_locale = locale; | - | ||||||||||||||||||||||||
481 | } never executed: end of block | 0 | ||||||||||||||||||||||||
482 | - | |||||||||||||||||||||||||
483 | QCalendarDateValidator::~QCalendarDateValidator() | - | ||||||||||||||||||||||||
484 | { | - | ||||||||||||||||||||||||
485 | clear(); | - | ||||||||||||||||||||||||
486 | } never executed: end of block | 0 | ||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||
488 | // from qdatetime.cpp | - | ||||||||||||||||||||||||
489 | int QCalendarDateValidator::countRepeat(const QString &str, int index) const | - | ||||||||||||||||||||||||
490 | { | - | ||||||||||||||||||||||||
491 | Q_ASSERT(index >= 0 && index < str.size()); | - | ||||||||||||||||||||||||
492 | int count = 1; | - | ||||||||||||||||||||||||
493 | const QChar ch = str.at(index); | - | ||||||||||||||||||||||||
494 | while (index + count < str.size() && str.at(index + count) == ch)
| 0 | ||||||||||||||||||||||||
495 | ++count; never executed: ++count; | 0 | ||||||||||||||||||||||||
496 | return count; never executed: return count; | 0 | ||||||||||||||||||||||||
497 | } | - | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | void QCalendarDateValidator::setInitialDate(const QDate &date) | - | ||||||||||||||||||||||||
500 | { | - | ||||||||||||||||||||||||
501 | m_yearValidator.setDate(date); | - | ||||||||||||||||||||||||
502 | m_monthValidator.setDate(date); | - | ||||||||||||||||||||||||
503 | m_dayValidator.setDate(date); | - | ||||||||||||||||||||||||
504 | m_initialDate = date; | - | ||||||||||||||||||||||||
505 | m_currentDate = date; | - | ||||||||||||||||||||||||
506 | m_lastSectionMove = QCalendarDateSectionValidator::ThisSection; | - | ||||||||||||||||||||||||
507 | } never executed: end of block | 0 | ||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | QString QCalendarDateValidator::currentText() const | - | ||||||||||||||||||||||||
510 | { | - | ||||||||||||||||||||||||
511 | QString str; | - | ||||||||||||||||||||||||
512 | QStringListIterator itSep(m_separators); | - | ||||||||||||||||||||||||
513 | QListIterator<SectionToken *> itTok(m_tokens); | - | ||||||||||||||||||||||||
514 | while (itSep.hasNext()) {
| 0 | ||||||||||||||||||||||||
515 | str += itSep.next(); | - | ||||||||||||||||||||||||
516 | if (itTok.hasNext()) {
| 0 | ||||||||||||||||||||||||
517 | SectionToken *token = itTok.next(); | - | ||||||||||||||||||||||||
518 | QCalendarDateSectionValidator *validator = token->validator; | - | ||||||||||||||||||||||||
519 | if (m_currentToken == token)
| 0 | ||||||||||||||||||||||||
520 | str += validator->text(); never executed: str += validator->text(); | 0 | ||||||||||||||||||||||||
521 | else | - | ||||||||||||||||||||||||
522 | str += validator->text(m_currentDate, token->repeat); never executed: str += validator->text(m_currentDate, token->repeat); | 0 | ||||||||||||||||||||||||
523 | } | - | ||||||||||||||||||||||||
524 | } never executed: end of block | 0 | ||||||||||||||||||||||||
525 | return str; never executed: return str; | 0 | ||||||||||||||||||||||||
526 | } | - | ||||||||||||||||||||||||
527 | - | |||||||||||||||||||||||||
528 | void QCalendarDateValidator::clear() | - | ||||||||||||||||||||||||
529 | { | - | ||||||||||||||||||||||||
530 | QListIterator<SectionToken *> it(m_tokens); | - | ||||||||||||||||||||||||
531 | while (it.hasNext())
| 0 | ||||||||||||||||||||||||
532 | delete it.next(); never executed: delete it.next(); | 0 | ||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||
534 | m_tokens.clear(); | - | ||||||||||||||||||||||||
535 | m_separators.clear(); | - | ||||||||||||||||||||||||
536 | - | |||||||||||||||||||||||||
537 | m_currentToken = 0; | - | ||||||||||||||||||||||||
538 | } never executed: end of block | 0 | ||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||
540 | void QCalendarDateValidator::setFormat(const QString &format) | - | ||||||||||||||||||||||||
541 | { | - | ||||||||||||||||||||||||
542 | clear(); | - | ||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||
544 | int pos = 0; | - | ||||||||||||||||||||||||
545 | const QLatin1Char quote('\''); | - | ||||||||||||||||||||||||
546 | bool quoting = false; | - | ||||||||||||||||||||||||
547 | QString separator; | - | ||||||||||||||||||||||||
548 | while (pos < format.size()) {
| 0 | ||||||||||||||||||||||||
549 | QString mid = format.mid(pos); | - | ||||||||||||||||||||||||
550 | int offset = 1; | - | ||||||||||||||||||||||||
551 | - | |||||||||||||||||||||||||
552 | if (mid.startsWith(quote)) {
| 0 | ||||||||||||||||||||||||
553 | quoting = !quoting; | - | ||||||||||||||||||||||||
554 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
555 | const QChar nextChar = format.at(pos); | - | ||||||||||||||||||||||||
556 | if (quoting) {
| 0 | ||||||||||||||||||||||||
557 | separator += nextChar; | - | ||||||||||||||||||||||||
558 | quoting = false; | - | ||||||||||||||||||||||||
559 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
560 | SectionToken *token = 0; | - | ||||||||||||||||||||||||
561 | if (nextChar == QLatin1Char('d')) {
| 0 | ||||||||||||||||||||||||
562 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||||||||||||||
563 | token = new SectionToken(&m_dayValidator, offset); | - | ||||||||||||||||||||||||
564 | } else if (nextChar == QLatin1Char('M')) { never executed: end of block
| 0 | ||||||||||||||||||||||||
565 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||||||||||||||
566 | token = new SectionToken(&m_monthValidator, offset); | - | ||||||||||||||||||||||||
567 | } else if (nextChar == QLatin1Char('y')) { never executed: end of block
| 0 | ||||||||||||||||||||||||
568 | offset = qMin(4, countRepeat(format, pos)); | - | ||||||||||||||||||||||||
569 | token = new SectionToken(&m_yearValidator, offset); | - | ||||||||||||||||||||||||
570 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
571 | separator += nextChar; | - | ||||||||||||||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||||||||||||||
573 | if (token) {
| 0 | ||||||||||||||||||||||||
574 | m_tokens.append(token); | - | ||||||||||||||||||||||||
575 | m_separators.append(separator); | - | ||||||||||||||||||||||||
576 | separator = QString(); | - | ||||||||||||||||||||||||
577 | if (!m_currentToken)
| 0 | ||||||||||||||||||||||||
578 | m_currentToken = token; never executed: m_currentToken = token; | 0 | ||||||||||||||||||||||||
579 | - | |||||||||||||||||||||||||
580 | } never executed: end of block | 0 | ||||||||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||||||||
582 | } | - | ||||||||||||||||||||||||
583 | pos += offset; | - | ||||||||||||||||||||||||
584 | } never executed: end of block | 0 | ||||||||||||||||||||||||
585 | m_separators += separator; | - | ||||||||||||||||||||||||
586 | } never executed: end of block | 0 | ||||||||||||||||||||||||
587 | - | |||||||||||||||||||||||||
588 | void QCalendarDateValidator::applyToDate() | - | ||||||||||||||||||||||||
589 | { | - | ||||||||||||||||||||||||
590 | m_currentDate = m_yearValidator.applyToDate(m_currentDate); | - | ||||||||||||||||||||||||
591 | m_currentDate = m_monthValidator.applyToDate(m_currentDate); | - | ||||||||||||||||||||||||
592 | m_currentDate = m_dayValidator.applyToDate(m_currentDate); | - | ||||||||||||||||||||||||
593 | } never executed: end of block | 0 | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | void QCalendarDateValidator::toNextToken() | - | ||||||||||||||||||||||||
596 | { | - | ||||||||||||||||||||||||
597 | const int idx = m_tokens.indexOf(m_currentToken); | - | ||||||||||||||||||||||||
598 | if (idx == -1)
| 0 | ||||||||||||||||||||||||
599 | return; never executed: return; | 0 | ||||||||||||||||||||||||
600 | if (idx + 1 >= m_tokens.count())
| 0 | ||||||||||||||||||||||||
601 | m_currentToken = m_tokens.first(); never executed: m_currentToken = m_tokens.first(); | 0 | ||||||||||||||||||||||||
602 | else | - | ||||||||||||||||||||||||
603 | m_currentToken = m_tokens.at(idx + 1); never executed: m_currentToken = m_tokens.at(idx + 1); | 0 | ||||||||||||||||||||||||
604 | } | - | ||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||
606 | void QCalendarDateValidator::toPreviousToken() | - | ||||||||||||||||||||||||
607 | { | - | ||||||||||||||||||||||||
608 | const int idx = m_tokens.indexOf(m_currentToken); | - | ||||||||||||||||||||||||
609 | if (idx == -1)
| 0 | ||||||||||||||||||||||||
610 | return; never executed: return; | 0 | ||||||||||||||||||||||||
611 | if (idx - 1 < 0)
| 0 | ||||||||||||||||||||||||
612 | m_currentToken = m_tokens.last(); never executed: m_currentToken = m_tokens.last(); | 0 | ||||||||||||||||||||||||
613 | else | - | ||||||||||||||||||||||||
614 | m_currentToken = m_tokens.at(idx - 1); never executed: m_currentToken = m_tokens.at(idx - 1); | 0 | ||||||||||||||||||||||||
615 | } | - | ||||||||||||||||||||||||
616 | - | |||||||||||||||||||||||||
617 | void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent) | - | ||||||||||||||||||||||||
618 | { | - | ||||||||||||||||||||||||
619 | if (!m_currentToken)
| 0 | ||||||||||||||||||||||||
620 | return; never executed: return; | 0 | ||||||||||||||||||||||||
621 | - | |||||||||||||||||||||||||
622 | int key = keyEvent->key(); | - | ||||||||||||||||||||||||
623 | if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection) {
| 0 | ||||||||||||||||||||||||
624 | if (key == Qt::Key_Back || key == Qt::Key_Backspace)
| 0 | ||||||||||||||||||||||||
625 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||||||||||||||
626 | } never executed: end of block | 0 | ||||||||||||||||||||||||
627 | if (key == Qt::Key_Right)
| 0 | ||||||||||||||||||||||||
628 | toNextToken(); never executed: toNextToken(); | 0 | ||||||||||||||||||||||||
629 | else if (key == Qt::Key_Left)
| 0 | ||||||||||||||||||||||||
630 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||||||||||||||
631 | - | |||||||||||||||||||||||||
632 | m_lastSectionMove = m_currentToken->validator->handleKey(key); | - | ||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | applyToDate(); | - | ||||||||||||||||||||||||
635 | if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection)
| 0 | ||||||||||||||||||||||||
636 | toNextToken(); never executed: toNextToken(); | 0 | ||||||||||||||||||||||||
637 | else if (m_lastSectionMove == QCalendarDateSectionValidator::PrevSection)
| 0 | ||||||||||||||||||||||||
638 | toPreviousToken(); never executed: toPreviousToken(); | 0 | ||||||||||||||||||||||||
639 | } never executed: end of block | 0 | ||||||||||||||||||||||||
640 | - | |||||||||||||||||||||||||
641 | ////////////////////////////////// | - | ||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||
643 | class QCalendarTextNavigator: public QObject | - | ||||||||||||||||||||||||
644 | { | - | ||||||||||||||||||||||||
645 | Q_OBJECT | - | ||||||||||||||||||||||||
646 | public: | - | ||||||||||||||||||||||||
647 | QCalendarTextNavigator(QObject *parent = 0) | - | ||||||||||||||||||||||||
648 | : QObject(parent), m_dateText(0), m_dateFrame(0), m_dateValidator(0), m_widget(0), m_editDelay(1500), m_date(QDate::currentDate()) { } never executed: end of block | 0 | ||||||||||||||||||||||||
649 | - | |||||||||||||||||||||||||
650 | QWidget *widget() const; | - | ||||||||||||||||||||||||
651 | void setWidget(QWidget *widget); | - | ||||||||||||||||||||||||
652 | - | |||||||||||||||||||||||||
653 | int dateEditAcceptDelay() const; | - | ||||||||||||||||||||||||
654 | void setDateEditAcceptDelay(int delay); | - | ||||||||||||||||||||||||
655 | - | |||||||||||||||||||||||||
656 | void setDate(const QDate &date); | - | ||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||
658 | bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
659 | void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | signals: | - | ||||||||||||||||||||||||
662 | void dateChanged(const QDate &date); | - | ||||||||||||||||||||||||
663 | void editingFinished(); | - | ||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||
665 | private: | - | ||||||||||||||||||||||||
666 | void applyDate(); | - | ||||||||||||||||||||||||
667 | void updateDateLabel(); | - | ||||||||||||||||||||||||
668 | void createDateLabel(); | - | ||||||||||||||||||||||||
669 | void removeDateLabel(); | - | ||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||
671 | QLabel *m_dateText; | - | ||||||||||||||||||||||||
672 | QFrame *m_dateFrame; | - | ||||||||||||||||||||||||
673 | QBasicTimer m_acceptTimer; | - | ||||||||||||||||||||||||
674 | QCalendarDateValidator *m_dateValidator; | - | ||||||||||||||||||||||||
675 | QWidget *m_widget; | - | ||||||||||||||||||||||||
676 | int m_editDelay; | - | ||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||
678 | QDate m_date; | - | ||||||||||||||||||||||||
679 | }; | - | ||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||
681 | QWidget *QCalendarTextNavigator::widget() const | - | ||||||||||||||||||||||||
682 | { | - | ||||||||||||||||||||||||
683 | return m_widget; never executed: return m_widget; | 0 | ||||||||||||||||||||||||
684 | } | - | ||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||
686 | void QCalendarTextNavigator::setWidget(QWidget *widget) | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | m_widget = widget; | - | ||||||||||||||||||||||||
689 | } never executed: end of block | 0 | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | void QCalendarTextNavigator::setDate(const QDate &date) | - | ||||||||||||||||||||||||
692 | { | - | ||||||||||||||||||||||||
693 | m_date = date; | - | ||||||||||||||||||||||||
694 | } never executed: end of block | 0 | ||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||
696 | void QCalendarTextNavigator::updateDateLabel() | - | ||||||||||||||||||||||||
697 | { | - | ||||||||||||||||||||||||
698 | if (!m_widget)
| 0 | ||||||||||||||||||||||||
699 | return; never executed: return; | 0 | ||||||||||||||||||||||||
700 | - | |||||||||||||||||||||||||
701 | m_acceptTimer.start(m_editDelay, this); | - | ||||||||||||||||||||||||
702 | - | |||||||||||||||||||||||||
703 | m_dateText->setText(m_dateValidator->currentText()); | - | ||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||
705 | QSize s = m_dateFrame->sizeHint(); | - | ||||||||||||||||||||||||
706 | QRect r = m_widget->geometry(); // later, just the table section | - | ||||||||||||||||||||||||
707 | QRect newRect((r.width() - s.width()) / 2, (r.height() - s.height()) / 2, s.width(), s.height()); | - | ||||||||||||||||||||||||
708 | m_dateFrame->setGeometry(newRect); | - | ||||||||||||||||||||||||
709 | // need to set palette after geometry update as phonestyle sets transparency | - | ||||||||||||||||||||||||
710 | // effect in move event. | - | ||||||||||||||||||||||||
711 | QPalette p = m_dateFrame->palette(); | - | ||||||||||||||||||||||||
712 | p.setBrush(QPalette::Window, m_dateFrame->window()->palette().brush(QPalette::Window)); | - | ||||||||||||||||||||||||
713 | m_dateFrame->setPalette(p); | - | ||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||
715 | m_dateFrame->raise(); | - | ||||||||||||||||||||||||
716 | m_dateFrame->show(); | - | ||||||||||||||||||||||||
717 | } never executed: end of block | 0 | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | void QCalendarTextNavigator::applyDate() | - | ||||||||||||||||||||||||
720 | { | - | ||||||||||||||||||||||||
721 | QDate date = m_dateValidator->currentDate(); | - | ||||||||||||||||||||||||
722 | if (m_date == date)
| 0 | ||||||||||||||||||||||||
723 | return; never executed: return; | 0 | ||||||||||||||||||||||||
724 | - | |||||||||||||||||||||||||
725 | m_date = date; | - | ||||||||||||||||||||||||
726 | emit dateChanged(date); | - | ||||||||||||||||||||||||
727 | } never executed: end of block | 0 | ||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||
729 | void QCalendarTextNavigator::createDateLabel() | - | ||||||||||||||||||||||||
730 | { | - | ||||||||||||||||||||||||
731 | if (m_dateFrame)
| 0 | ||||||||||||||||||||||||
732 | return; never executed: return; | 0 | ||||||||||||||||||||||||
733 | m_dateFrame = new QFrame(m_widget); | - | ||||||||||||||||||||||||
734 | QVBoxLayout *vl = new QVBoxLayout; | - | ||||||||||||||||||||||||
735 | m_dateText = new QLabel; | - | ||||||||||||||||||||||||
736 | vl->addWidget(m_dateText); | - | ||||||||||||||||||||||||
737 | m_dateFrame->setLayout(vl); | - | ||||||||||||||||||||||||
738 | m_dateFrame->setFrameShadow(QFrame::Plain); | - | ||||||||||||||||||||||||
739 | m_dateFrame->setFrameShape(QFrame::Box); | - | ||||||||||||||||||||||||
740 | m_dateValidator = new QCalendarDateValidator(); | - | ||||||||||||||||||||||||
741 | m_dateValidator->setLocale(m_widget->locale()); | - | ||||||||||||||||||||||||
742 | m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat)); | - | ||||||||||||||||||||||||
743 | m_dateValidator->setInitialDate(m_date); | - | ||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||
745 | m_dateFrame->setAutoFillBackground(true); | - | ||||||||||||||||||||||||
746 | m_dateFrame->setBackgroundRole(QPalette::Window); | - | ||||||||||||||||||||||||
747 | } never executed: end of block | 0 | ||||||||||||||||||||||||
748 | - | |||||||||||||||||||||||||
749 | void QCalendarTextNavigator::removeDateLabel() | - | ||||||||||||||||||||||||
750 | { | - | ||||||||||||||||||||||||
751 | if (!m_dateFrame)
| 0 | ||||||||||||||||||||||||
752 | return; never executed: return; | 0 | ||||||||||||||||||||||||
753 | m_acceptTimer.stop(); | - | ||||||||||||||||||||||||
754 | m_dateFrame->hide(); | - | ||||||||||||||||||||||||
755 | m_dateFrame->deleteLater(); | - | ||||||||||||||||||||||||
756 | delete m_dateValidator; | - | ||||||||||||||||||||||||
757 | m_dateFrame = 0; | - | ||||||||||||||||||||||||
758 | m_dateText = 0; | - | ||||||||||||||||||||||||
759 | m_dateValidator = 0; | - | ||||||||||||||||||||||||
760 | } never executed: end of block | 0 | ||||||||||||||||||||||||
761 | - | |||||||||||||||||||||||||
762 | bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||||||||
763 | { | - | ||||||||||||||||||||||||
764 | if (m_widget) {
| 0 | ||||||||||||||||||||||||
765 | if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
| 0 | ||||||||||||||||||||||||
766 | QKeyEvent* ke = (QKeyEvent*)e; | - | ||||||||||||||||||||||||
767 | if ((ke->text().length() > 0 && ke->text()[0].isPrint()) || m_dateFrame) {
| 0 | ||||||||||||||||||||||||
768 | if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Select) {
| 0 | ||||||||||||||||||||||||
769 | applyDate(); | - | ||||||||||||||||||||||||
770 | emit editingFinished(); | - | ||||||||||||||||||||||||
771 | removeDateLabel(); | - | ||||||||||||||||||||||||
772 | } else if (ke->matches(QKeySequence::Cancel)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
773 | removeDateLabel(); | - | ||||||||||||||||||||||||
774 | } else if (e->type() == QEvent::KeyPress) { never executed: end of block
| 0 | ||||||||||||||||||||||||
775 | createDateLabel(); | - | ||||||||||||||||||||||||
776 | m_dateValidator->handleKeyEvent(ke); | - | ||||||||||||||||||||||||
777 | updateDateLabel(); | - | ||||||||||||||||||||||||
778 | } never executed: end of block | 0 | ||||||||||||||||||||||||
779 | ke->accept(); | - | ||||||||||||||||||||||||
780 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
781 | } | - | ||||||||||||||||||||||||
782 | // If we are navigating let the user finish his date in old locate. | - | ||||||||||||||||||||||||
783 | // If we change our mind and want it to update immediately simply uncomment below | - | ||||||||||||||||||||||||
784 | /* | - | ||||||||||||||||||||||||
785 | } else if (e->type() == QEvent::LocaleChange) { | - | ||||||||||||||||||||||||
786 | if (m_dateValidator) { | - | ||||||||||||||||||||||||
787 | m_dateValidator->setLocale(m_widget->locale()); | - | ||||||||||||||||||||||||
788 | m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat)); | - | ||||||||||||||||||||||||
789 | updateDateLabel(); | - | ||||||||||||||||||||||||
790 | } | - | ||||||||||||||||||||||||
791 | */ | - | ||||||||||||||||||||||||
792 | } never executed: end of block | 0 | ||||||||||||||||||||||||
793 | } never executed: end of block | 0 | ||||||||||||||||||||||||
794 | return QObject::eventFilter(o,e); never executed: return QObject::eventFilter(o,e); | 0 | ||||||||||||||||||||||||
795 | } | - | ||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||
797 | void QCalendarTextNavigator::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||
798 | { | - | ||||||||||||||||||||||||
799 | if (e->timerId() == m_acceptTimer.timerId()) {
| 0 | ||||||||||||||||||||||||
800 | applyDate(); | - | ||||||||||||||||||||||||
801 | removeDateLabel(); | - | ||||||||||||||||||||||||
802 | } never executed: end of block | 0 | ||||||||||||||||||||||||
803 | } never executed: end of block | 0 | ||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||
805 | int QCalendarTextNavigator::dateEditAcceptDelay() const | - | ||||||||||||||||||||||||
806 | { | - | ||||||||||||||||||||||||
807 | return m_editDelay; never executed: return m_editDelay; | 0 | ||||||||||||||||||||||||
808 | } | - | ||||||||||||||||||||||||
809 | - | |||||||||||||||||||||||||
810 | void QCalendarTextNavigator::setDateEditAcceptDelay(int delay) | - | ||||||||||||||||||||||||
811 | { | - | ||||||||||||||||||||||||
812 | m_editDelay = delay; | - | ||||||||||||||||||||||||
813 | } never executed: end of block | 0 | ||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||
815 | class QCalendarView; | - | ||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||
817 | class QCalendarModel : public QAbstractTableModel | - | ||||||||||||||||||||||||
818 | { | - | ||||||||||||||||||||||||
819 | Q_OBJECT | - | ||||||||||||||||||||||||
820 | public: | - | ||||||||||||||||||||||||
821 | QCalendarModel(QObject *parent = 0); | - | ||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||
823 | int rowCount(const QModelIndex &) const Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
824 | { return RowCount + m_firstRow; } never executed: return RowCount + m_firstRow; | 0 | ||||||||||||||||||||||||
825 | int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
826 | { return ColumnCount + m_firstColumn; } never executed: return ColumnCount + m_firstColumn; | 0 | ||||||||||||||||||||||||
827 | QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
828 | Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
829 | - | |||||||||||||||||||||||||
830 | bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
831 | { | - | ||||||||||||||||||||||||
832 | beginInsertRows(parent, row, row + count - 1); | - | ||||||||||||||||||||||||
833 | endInsertRows(); | - | ||||||||||||||||||||||||
834 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
835 | } | - | ||||||||||||||||||||||||
836 | bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
837 | { | - | ||||||||||||||||||||||||
838 | beginInsertColumns(parent, column, column + count - 1); | - | ||||||||||||||||||||||||
839 | endInsertColumns(); | - | ||||||||||||||||||||||||
840 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
841 | } | - | ||||||||||||||||||||||||
842 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
843 | { | - | ||||||||||||||||||||||||
844 | beginRemoveRows(parent, row, row + count - 1); | - | ||||||||||||||||||||||||
845 | endRemoveRows(); | - | ||||||||||||||||||||||||
846 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
847 | } | - | ||||||||||||||||||||||||
848 | bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
849 | { | - | ||||||||||||||||||||||||
850 | beginRemoveColumns(parent, column, column + count - 1); | - | ||||||||||||||||||||||||
851 | endRemoveColumns(); | - | ||||||||||||||||||||||||
852 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
853 | } | - | ||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||
855 | void showMonth(int year, int month); | - | ||||||||||||||||||||||||
856 | void setDate(const QDate &d); | - | ||||||||||||||||||||||||
857 | - | |||||||||||||||||||||||||
858 | void setMinimumDate(const QDate &date); | - | ||||||||||||||||||||||||
859 | void setMaximumDate(const QDate &date); | - | ||||||||||||||||||||||||
860 | - | |||||||||||||||||||||||||
861 | void setRange(const QDate &min, const QDate &max); | - | ||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||
863 | void setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format); | - | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | void setFirstColumnDay(Qt::DayOfWeek dayOfWeek); | - | ||||||||||||||||||||||||
866 | Qt::DayOfWeek firstColumnDay() const; | - | ||||||||||||||||||||||||
867 | - | |||||||||||||||||||||||||
868 | bool weekNumbersShown() const; | - | ||||||||||||||||||||||||
869 | void setWeekNumbersShown(bool show); | - | ||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | QTextCharFormat formatForCell(int row, int col) const; | - | ||||||||||||||||||||||||
872 | Qt::DayOfWeek dayOfWeekForColumn(int section) const; | - | ||||||||||||||||||||||||
873 | int columnForDayOfWeek(Qt::DayOfWeek day) const; | - | ||||||||||||||||||||||||
874 | QDate dateForCell(int row, int column) const; | - | ||||||||||||||||||||||||
875 | void cellForDate(const QDate &date, int *row, int *column) const; | - | ||||||||||||||||||||||||
876 | QString dayName(Qt::DayOfWeek day) const; | - | ||||||||||||||||||||||||
877 | - | |||||||||||||||||||||||||
878 | void setView(QCalendarView *view) | - | ||||||||||||||||||||||||
879 | { m_view = view; } never executed: end of block | 0 | ||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | void internalUpdate(); | - | ||||||||||||||||||||||||
882 | QDate referenceDate() const; | - | ||||||||||||||||||||||||
883 | int columnForFirstOfMonth(const QDate &date) const; | - | ||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||
885 | int m_firstColumn; | - | ||||||||||||||||||||||||
886 | int m_firstRow; | - | ||||||||||||||||||||||||
887 | QDate m_date; | - | ||||||||||||||||||||||||
888 | QDate m_minimumDate; | - | ||||||||||||||||||||||||
889 | QDate m_maximumDate; | - | ||||||||||||||||||||||||
890 | int m_shownYear; | - | ||||||||||||||||||||||||
891 | int m_shownMonth; | - | ||||||||||||||||||||||||
892 | Qt::DayOfWeek m_firstDay; | - | ||||||||||||||||||||||||
893 | QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat; | - | ||||||||||||||||||||||||
894 | bool m_weekNumbersShown; | - | ||||||||||||||||||||||||
895 | QMap<Qt::DayOfWeek, QTextCharFormat> m_dayFormats; | - | ||||||||||||||||||||||||
896 | QMap<QDate, QTextCharFormat> m_dateFormats; | - | ||||||||||||||||||||||||
897 | QTextCharFormat m_headerFormat; | - | ||||||||||||||||||||||||
898 | QCalendarView *m_view; | - | ||||||||||||||||||||||||
899 | }; | - | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | class QCalendarView : public QTableView | - | ||||||||||||||||||||||||
902 | { | - | ||||||||||||||||||||||||
903 | Q_OBJECT | - | ||||||||||||||||||||||||
904 | public: | - | ||||||||||||||||||||||||
905 | QCalendarView(QWidget *parent = 0); | - | ||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||
907 | void internalUpdate() { updateGeometries(); } never executed: end of block | 0 | ||||||||||||||||||||||||
908 | void setReadOnly(bool enable); | - | ||||||||||||||||||||||||
909 | virtual void keyboardSearch(const QString & search) Q_DECL_OVERRIDE { Q_UNUSED(search) } never executed: end of block | 0 | ||||||||||||||||||||||||
910 | - | |||||||||||||||||||||||||
911 | signals: | - | ||||||||||||||||||||||||
912 | void showDate(const QDate &date); | - | ||||||||||||||||||||||||
913 | void changeDate(const QDate &date, bool changeMonth); | - | ||||||||||||||||||||||||
914 | void clicked(const QDate &date); | - | ||||||||||||||||||||||||
915 | void editingFinished(); | - | ||||||||||||||||||||||||
916 | protected: | - | ||||||||||||||||||||||||
917 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
918 | void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
919 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
920 | void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
921 | void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
922 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||
923 | void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
924 | #endif | - | ||||||||||||||||||||||||
925 | void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
926 | bool event(QEvent *event) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||
928 | QDate handleMouseEvent(QMouseEvent *event); | - | ||||||||||||||||||||||||
929 | public: | - | ||||||||||||||||||||||||
930 | bool readOnly; | - | ||||||||||||||||||||||||
931 | private: | - | ||||||||||||||||||||||||
932 | bool validDateClicked; | - | ||||||||||||||||||||||||
933 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
934 | QDate origDate; | - | ||||||||||||||||||||||||
935 | #endif | - | ||||||||||||||||||||||||
936 | }; | - | ||||||||||||||||||||||||
937 | - | |||||||||||||||||||||||||
938 | QCalendarModel::QCalendarModel(QObject *parent) | - | ||||||||||||||||||||||||
939 | : QAbstractTableModel(parent), | - | ||||||||||||||||||||||||
940 | m_firstColumn(1), | - | ||||||||||||||||||||||||
941 | m_firstRow(1), | - | ||||||||||||||||||||||||
942 | m_date(QDate::currentDate()), | - | ||||||||||||||||||||||||
943 | m_minimumDate(QDate::fromJulianDay(1)), | - | ||||||||||||||||||||||||
944 | m_maximumDate(7999, 12, 31), | - | ||||||||||||||||||||||||
945 | m_shownYear(m_date.year()), | - | ||||||||||||||||||||||||
946 | m_shownMonth(m_date.month()), | - | ||||||||||||||||||||||||
947 | m_firstDay(QLocale().firstDayOfWeek()), | - | ||||||||||||||||||||||||
948 | m_horizontalHeaderFormat(QCalendarWidget::ShortDayNames), | - | ||||||||||||||||||||||||
949 | m_weekNumbersShown(true), | - | ||||||||||||||||||||||||
950 | m_view(Q_NULLPTR) | - | ||||||||||||||||||||||||
951 | { | - | ||||||||||||||||||||||||
952 | } never executed: end of block | 0 | ||||||||||||||||||||||||
953 | - | |||||||||||||||||||||||||
954 | Qt::DayOfWeek QCalendarModel::dayOfWeekForColumn(int column) const | - | ||||||||||||||||||||||||
955 | { | - | ||||||||||||||||||||||||
956 | int col = column - m_firstColumn; | - | ||||||||||||||||||||||||
957 | if (col < 0 || col > 6)
| 0 | ||||||||||||||||||||||||
958 | return Qt::Sunday; never executed: return Qt::Sunday; | 0 | ||||||||||||||||||||||||
959 | int day = m_firstDay + col; | - | ||||||||||||||||||||||||
960 | if (day > 7)
| 0 | ||||||||||||||||||||||||
961 | day -= 7; never executed: day -= 7; | 0 | ||||||||||||||||||||||||
962 | return Qt::DayOfWeek(day); never executed: return Qt::DayOfWeek(day); | 0 | ||||||||||||||||||||||||
963 | } | - | ||||||||||||||||||||||||
964 | - | |||||||||||||||||||||||||
965 | int QCalendarModel::columnForDayOfWeek(Qt::DayOfWeek day) const | - | ||||||||||||||||||||||||
966 | { | - | ||||||||||||||||||||||||
967 | if (day < 1 || day > 7)
| 0 | ||||||||||||||||||||||||
968 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
969 | int column = (int)day - (int)m_firstDay; | - | ||||||||||||||||||||||||
970 | if (column < 0)
| 0 | ||||||||||||||||||||||||
971 | column += 7; never executed: column += 7; | 0 | ||||||||||||||||||||||||
972 | return column + m_firstColumn; never executed: return column + m_firstColumn; | 0 | ||||||||||||||||||||||||
973 | } | - | ||||||||||||||||||||||||
974 | - | |||||||||||||||||||||||||
975 | /* | - | ||||||||||||||||||||||||
976 | This simple algorithm tries to generate a valid date from the month shown. | - | ||||||||||||||||||||||||
977 | Some months don't contain a first day (e.g. Jan of -4713 year, | - | ||||||||||||||||||||||||
978 | so QDate (-4713, 1, 1) would be invalid). In that case we try to generate | - | ||||||||||||||||||||||||
979 | another valid date for that month. Later, returned date's day is the number of cells | - | ||||||||||||||||||||||||
980 | calendar widget will reserve for days before referenceDate. (E.g. if returned date's | - | ||||||||||||||||||||||||
981 | day is 16, that day will be placed in 3rd or 4th row, not in the 1st or 2nd row). | - | ||||||||||||||||||||||||
982 | Depending on referenceData we can change behaviour of Oct 1582. If referenceDate is 1st | - | ||||||||||||||||||||||||
983 | of Oct we render 1 Oct in 1st or 2nd row. If referenceDate is 17 of Oct we show always 16 | - | ||||||||||||||||||||||||
984 | dates before 17 of Oct, and since this month contains the hole 5-14 Oct, the first of Oct | - | ||||||||||||||||||||||||
985 | will be rendered in 2nd or 3rd row, showing more dates from previous month. | - | ||||||||||||||||||||||||
986 | */ | - | ||||||||||||||||||||||||
987 | QDate QCalendarModel::referenceDate() const | - | ||||||||||||||||||||||||
988 | { | - | ||||||||||||||||||||||||
989 | int refDay = 1; | - | ||||||||||||||||||||||||
990 | while (refDay <= 31) {
| 0 | ||||||||||||||||||||||||
991 | QDate refDate(m_shownYear, m_shownMonth, refDay); | - | ||||||||||||||||||||||||
992 | if (refDate.isValid())
| 0 | ||||||||||||||||||||||||
993 | return refDate; never executed: return refDate; | 0 | ||||||||||||||||||||||||
994 | refDay += 1; | - | ||||||||||||||||||||||||
995 | } never executed: end of block | 0 | ||||||||||||||||||||||||
996 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||
997 | } | - | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | int QCalendarModel::columnForFirstOfMonth(const QDate &date) const | - | ||||||||||||||||||||||||
1000 | { | - | ||||||||||||||||||||||||
1001 | return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7; never executed: return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7; | 0 | ||||||||||||||||||||||||
1002 | } | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | QDate QCalendarModel::dateForCell(int row, int column) const | - | ||||||||||||||||||||||||
1005 | { | - | ||||||||||||||||||||||||
1006 | if (row < m_firstRow || row > m_firstRow + RowCount - 1 ||
| 0 | ||||||||||||||||||||||||
1007 | column < m_firstColumn || column > m_firstColumn + ColumnCount - 1)
| 0 | ||||||||||||||||||||||||
1008 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||
1009 | const QDate refDate = referenceDate(); | - | ||||||||||||||||||||||||
1010 | if (!refDate.isValid())
| 0 | ||||||||||||||||||||||||
1011 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||
1013 | const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); | - | ||||||||||||||||||||||||
1014 | if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
| 0 | ||||||||||||||||||||||||
1015 | row -= 1; never executed: row -= 1; | 0 | ||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||
1017 | const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1; | - | ||||||||||||||||||||||||
1018 | return refDate.addDays(requestedDay); never executed: return refDate.addDays(requestedDay); | 0 | ||||||||||||||||||||||||
1019 | } | - | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const | - | ||||||||||||||||||||||||
1022 | { | - | ||||||||||||||||||||||||
1023 | if (!row && !column)
| 0 | ||||||||||||||||||||||||
1024 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||
1026 | if (row)
| 0 | ||||||||||||||||||||||||
1027 | *row = -1; never executed: *row = -1; | 0 | ||||||||||||||||||||||||
1028 | if (column)
| 0 | ||||||||||||||||||||||||
1029 | *column = -1; never executed: *column = -1; | 0 | ||||||||||||||||||||||||
1030 | - | |||||||||||||||||||||||||
1031 | const QDate refDate = referenceDate(); | - | ||||||||||||||||||||||||
1032 | if (!refDate.isValid())
| 0 | ||||||||||||||||||||||||
1033 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate); | - | ||||||||||||||||||||||||
1036 | const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1; | - | ||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||
1038 | int c = requestedPosition % 7; | - | ||||||||||||||||||||||||
1039 | int r = requestedPosition / 7; | - | ||||||||||||||||||||||||
1040 | if (c < 0) {
| 0 | ||||||||||||||||||||||||
1041 | c += 7; | - | ||||||||||||||||||||||||
1042 | r -= 1; | - | ||||||||||||||||||||||||
1043 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1044 | - | |||||||||||||||||||||||||
1045 | if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
| 0 | ||||||||||||||||||||||||
1046 | r += 1; never executed: r += 1; | 0 | ||||||||||||||||||||||||
1047 | - | |||||||||||||||||||||||||
1048 | if (r < 0 || r > RowCount - 1 || c < 0 || c > ColumnCount - 1)
| 0 | ||||||||||||||||||||||||
1049 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||
1051 | if (row)
| 0 | ||||||||||||||||||||||||
1052 | *row = r + m_firstRow; never executed: *row = r + m_firstRow; | 0 | ||||||||||||||||||||||||
1053 | if (column)
| 0 | ||||||||||||||||||||||||
1054 | *column = c + m_firstColumn; never executed: *column = c + m_firstColumn; | 0 | ||||||||||||||||||||||||
1055 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1056 | - | |||||||||||||||||||||||||
1057 | QString QCalendarModel::dayName(Qt::DayOfWeek day) const | - | ||||||||||||||||||||||||
1058 | { | - | ||||||||||||||||||||||||
1059 | switch (m_horizontalHeaderFormat) { | - | ||||||||||||||||||||||||
1060 | case QCalendarWidget::SingleLetterDayNames: { never executed: case QCalendarWidget::SingleLetterDayNames: | 0 | ||||||||||||||||||||||||
1061 | QString standaloneDayName = m_view->locale().standaloneDayName(day, QLocale::NarrowFormat); | - | ||||||||||||||||||||||||
1062 | if (standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat))
| 0 | ||||||||||||||||||||||||
1063 | return standaloneDayName.left(1); never executed: return standaloneDayName.left(1); | 0 | ||||||||||||||||||||||||
1064 | return standaloneDayName; never executed: return standaloneDayName; | 0 | ||||||||||||||||||||||||
1065 | } | - | ||||||||||||||||||||||||
1066 | case QCalendarWidget::ShortDayNames: never executed: case QCalendarWidget::ShortDayNames: | 0 | ||||||||||||||||||||||||
1067 | return m_view->locale().dayName(day, QLocale::ShortFormat); never executed: return m_view->locale().dayName(day, QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||
1068 | case QCalendarWidget::LongDayNames: never executed: case QCalendarWidget::LongDayNames: | 0 | ||||||||||||||||||||||||
1069 | return m_view->locale().dayName(day, QLocale::LongFormat); never executed: return m_view->locale().dayName(day, QLocale::LongFormat); | 0 | ||||||||||||||||||||||||
1070 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1071 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1072 | } | - | ||||||||||||||||||||||||
1073 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
1074 | } | - | ||||||||||||||||||||||||
1075 | - | |||||||||||||||||||||||||
1076 | QTextCharFormat QCalendarModel::formatForCell(int row, int col) const | - | ||||||||||||||||||||||||
1077 | { | - | ||||||||||||||||||||||||
1078 | QPalette pal; | - | ||||||||||||||||||||||||
1079 | QPalette::ColorGroup cg = QPalette::Active; | - | ||||||||||||||||||||||||
1080 | if (m_view) {
| 0 | ||||||||||||||||||||||||
1081 | pal = m_view->palette(); | - | ||||||||||||||||||||||||
1082 | if (!m_view->isEnabled())
| 0 | ||||||||||||||||||||||||
1083 | cg = QPalette::Disabled; never executed: cg = QPalette::Disabled; | 0 | ||||||||||||||||||||||||
1084 | else if (!m_view->isActiveWindow())
| 0 | ||||||||||||||||||||||||
1085 | cg = QPalette::Inactive; never executed: cg = QPalette::Inactive; | 0 | ||||||||||||||||||||||||
1086 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1087 | - | |||||||||||||||||||||||||
1088 | QTextCharFormat format; | - | ||||||||||||||||||||||||
1089 | format.setFont(m_view->font()); | - | ||||||||||||||||||||||||
1090 | bool header = (m_weekNumbersShown && col == HeaderColumn)
| 0 | ||||||||||||||||||||||||
1091 | || (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow);
| 0 | ||||||||||||||||||||||||
1092 | format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base)); | - | ||||||||||||||||||||||||
1093 | format.setForeground(pal.brush(cg, QPalette::Text)); | - | ||||||||||||||||||||||||
1094 | if (header) {
| 0 | ||||||||||||||||||||||||
1095 | format.merge(m_headerFormat); | - | ||||||||||||||||||||||||
1096 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1097 | - | |||||||||||||||||||||||||
1098 | if (col >= m_firstColumn && col < m_firstColumn + ColumnCount) {
| 0 | ||||||||||||||||||||||||
1099 | Qt::DayOfWeek dayOfWeek = dayOfWeekForColumn(col); | - | ||||||||||||||||||||||||
1100 | if (m_dayFormats.contains(dayOfWeek))
| 0 | ||||||||||||||||||||||||
1101 | format.merge(m_dayFormats.value(dayOfWeek)); never executed: format.merge(m_dayFormats.value(dayOfWeek)); | 0 | ||||||||||||||||||||||||
1102 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||
1104 | if (!header) {
| 0 | ||||||||||||||||||||||||
1105 | QDate date = dateForCell(row, col); | - | ||||||||||||||||||||||||
1106 | format.merge(m_dateFormats.value(date)); | - | ||||||||||||||||||||||||
1107 | if(date < m_minimumDate || date > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1108 | format.setBackground(pal.brush(cg, QPalette::Window)); never executed: format.setBackground(pal.brush(cg, QPalette::Window)); | 0 | ||||||||||||||||||||||||
1109 | if (m_shownMonth != date.month())
| 0 | ||||||||||||||||||||||||
1110 | format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text)); never executed: format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text)); | 0 | ||||||||||||||||||||||||
1111 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1112 | return format; never executed: return format; | 0 | ||||||||||||||||||||||||
1113 | } | - | ||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||
1115 | QVariant QCalendarModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||||||||
1116 | { | - | ||||||||||||||||||||||||
1117 | if (role == Qt::TextAlignmentRole)
| 0 | ||||||||||||||||||||||||
1118 | return (int) Qt::AlignCenter; never executed: return (int) Qt::AlignCenter; | 0 | ||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||
1120 | int row = index.row(); | - | ||||||||||||||||||||||||
1121 | int column = index.column(); | - | ||||||||||||||||||||||||
1122 | - | |||||||||||||||||||||||||
1123 | if(role == Qt::DisplayRole) {
| 0 | ||||||||||||||||||||||||
1124 | if (m_weekNumbersShown && column == HeaderColumn
| 0 | ||||||||||||||||||||||||
1125 | && row >= m_firstRow && row < m_firstRow + RowCount) {
| 0 | ||||||||||||||||||||||||
1126 | QDate date = dateForCell(row, columnForDayOfWeek(Qt::Monday)); | - | ||||||||||||||||||||||||
1127 | if (date.isValid())
| 0 | ||||||||||||||||||||||||
1128 | return date.weekNumber(); never executed: return date.weekNumber(); | 0 | ||||||||||||||||||||||||
1129 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1130 | if (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow
| 0 | ||||||||||||||||||||||||
1131 | && column >= m_firstColumn && column < m_firstColumn + ColumnCount)
| 0 | ||||||||||||||||||||||||
1132 | return dayName(dayOfWeekForColumn(column)); never executed: return dayName(dayOfWeekForColumn(column)); | 0 | ||||||||||||||||||||||||
1133 | QDate date = dateForCell(row, column); | - | ||||||||||||||||||||||||
1134 | if (date.isValid())
| 0 | ||||||||||||||||||||||||
1135 | return date.day(); never executed: return date.day(); | 0 | ||||||||||||||||||||||||
1136 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
1137 | } | - | ||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||
1139 | QTextCharFormat fmt = formatForCell(row, column); | - | ||||||||||||||||||||||||
1140 | if (role == Qt::BackgroundColorRole)
| 0 | ||||||||||||||||||||||||
1141 | return fmt.background().color(); never executed: return fmt.background().color(); | 0 | ||||||||||||||||||||||||
1142 | if (role == Qt::TextColorRole)
| 0 | ||||||||||||||||||||||||
1143 | return fmt.foreground().color(); never executed: return fmt.foreground().color(); | 0 | ||||||||||||||||||||||||
1144 | if (role == Qt::FontRole)
| 0 | ||||||||||||||||||||||||
1145 | return fmt.font(); never executed: return fmt.font(); | 0 | ||||||||||||||||||||||||
1146 | if (role == Qt::ToolTipRole)
| 0 | ||||||||||||||||||||||||
1147 | return fmt.toolTip(); never executed: return fmt.toolTip(); | 0 | ||||||||||||||||||||||||
1148 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
1149 | } | - | ||||||||||||||||||||||||
1150 | - | |||||||||||||||||||||||||
1151 | Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1152 | { | - | ||||||||||||||||||||||||
1153 | QDate date = dateForCell(index.row(), index.column()); | - | ||||||||||||||||||||||||
1154 | if (!date.isValid())
| 0 | ||||||||||||||||||||||||
1155 | return QAbstractTableModel::flags(index); never executed: return QAbstractTableModel::flags(index); | 0 | ||||||||||||||||||||||||
1156 | if (date < m_minimumDate)
| 0 | ||||||||||||||||||||||||
1157 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1158 | if (date > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1159 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1160 | return QAbstractTableModel::flags(index); never executed: return QAbstractTableModel::flags(index); | 0 | ||||||||||||||||||||||||
1161 | } | - | ||||||||||||||||||||||||
1162 | - | |||||||||||||||||||||||||
1163 | void QCalendarModel::setDate(const QDate &d) | - | ||||||||||||||||||||||||
1164 | { | - | ||||||||||||||||||||||||
1165 | m_date = d; | - | ||||||||||||||||||||||||
1166 | if (m_date < m_minimumDate)
| 0 | ||||||||||||||||||||||||
1167 | m_date = m_minimumDate; never executed: m_date = m_minimumDate; | 0 | ||||||||||||||||||||||||
1168 | else if (m_date > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1169 | m_date = m_maximumDate; never executed: m_date = m_maximumDate; | 0 | ||||||||||||||||||||||||
1170 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||
1172 | void QCalendarModel::showMonth(int year, int month) | - | ||||||||||||||||||||||||
1173 | { | - | ||||||||||||||||||||||||
1174 | if (m_shownYear == year && m_shownMonth == month)
| 0 | ||||||||||||||||||||||||
1175 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | m_shownYear = year; | - | ||||||||||||||||||||||||
1178 | m_shownMonth = month; | - | ||||||||||||||||||||||||
1179 | - | |||||||||||||||||||||||||
1180 | internalUpdate(); | - | ||||||||||||||||||||||||
1181 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1182 | - | |||||||||||||||||||||||||
1183 | void QCalendarModel::setMinimumDate(const QDate &d) | - | ||||||||||||||||||||||||
1184 | { | - | ||||||||||||||||||||||||
1185 | if (!d.isValid() || d == m_minimumDate)
| 0 | ||||||||||||||||||||||||
1186 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1187 | - | |||||||||||||||||||||||||
1188 | m_minimumDate = d; | - | ||||||||||||||||||||||||
1189 | if (m_maximumDate < m_minimumDate)
| 0 | ||||||||||||||||||||||||
1190 | m_maximumDate = m_minimumDate; never executed: m_maximumDate = m_minimumDate; | 0 | ||||||||||||||||||||||||
1191 | if (m_date < m_minimumDate)
| 0 | ||||||||||||||||||||||||
1192 | m_date = m_minimumDate; never executed: m_date = m_minimumDate; | 0 | ||||||||||||||||||||||||
1193 | internalUpdate(); | - | ||||||||||||||||||||||||
1194 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1195 | - | |||||||||||||||||||||||||
1196 | void QCalendarModel::setMaximumDate(const QDate &d) | - | ||||||||||||||||||||||||
1197 | { | - | ||||||||||||||||||||||||
1198 | if (!d.isValid() || d == m_maximumDate)
| 0 | ||||||||||||||||||||||||
1199 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1200 | - | |||||||||||||||||||||||||
1201 | m_maximumDate = d; | - | ||||||||||||||||||||||||
1202 | if (m_minimumDate > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1203 | m_minimumDate = m_maximumDate; never executed: m_minimumDate = m_maximumDate; | 0 | ||||||||||||||||||||||||
1204 | if (m_date > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1205 | m_date = m_maximumDate; never executed: m_date = m_maximumDate; | 0 | ||||||||||||||||||||||||
1206 | internalUpdate(); | - | ||||||||||||||||||||||||
1207 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1208 | - | |||||||||||||||||||||||||
1209 | void QCalendarModel::setRange(const QDate &min, const QDate &max) | - | ||||||||||||||||||||||||
1210 | { | - | ||||||||||||||||||||||||
1211 | m_minimumDate = min; | - | ||||||||||||||||||||||||
1212 | m_maximumDate = max; | - | ||||||||||||||||||||||||
1213 | if (m_minimumDate > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1214 | qSwap(m_minimumDate, m_maximumDate); never executed: qSwap(m_minimumDate, m_maximumDate); | 0 | ||||||||||||||||||||||||
1215 | if (m_date < m_minimumDate)
| 0 | ||||||||||||||||||||||||
1216 | m_date = m_minimumDate; never executed: m_date = m_minimumDate; | 0 | ||||||||||||||||||||||||
1217 | if (m_date > m_maximumDate)
| 0 | ||||||||||||||||||||||||
1218 | m_date = m_maximumDate; never executed: m_date = m_maximumDate; | 0 | ||||||||||||||||||||||||
1219 | internalUpdate(); | - | ||||||||||||||||||||||||
1220 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1221 | - | |||||||||||||||||||||||||
1222 | void QCalendarModel::internalUpdate() | - | ||||||||||||||||||||||||
1223 | { | - | ||||||||||||||||||||||||
1224 | QModelIndex begin = index(0, 0); | - | ||||||||||||||||||||||||
1225 | QModelIndex end = index(m_firstRow + RowCount - 1, m_firstColumn + ColumnCount - 1); | - | ||||||||||||||||||||||||
1226 | emit dataChanged(begin, end); | - | ||||||||||||||||||||||||
1227 | emit headerDataChanged(Qt::Vertical, 0, m_firstRow + RowCount - 1); | - | ||||||||||||||||||||||||
1228 | emit headerDataChanged(Qt::Horizontal, 0, m_firstColumn + ColumnCount - 1); | - | ||||||||||||||||||||||||
1229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1230 | - | |||||||||||||||||||||||||
1231 | void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) | - | ||||||||||||||||||||||||
1232 | { | - | ||||||||||||||||||||||||
1233 | if (m_horizontalHeaderFormat == format)
| 0 | ||||||||||||||||||||||||
1234 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1235 | - | |||||||||||||||||||||||||
1236 | int oldFormat = m_horizontalHeaderFormat; | - | ||||||||||||||||||||||||
1237 | m_horizontalHeaderFormat = format; | - | ||||||||||||||||||||||||
1238 | if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
| 0 | ||||||||||||||||||||||||
1239 | m_firstRow = 1; | - | ||||||||||||||||||||||||
1240 | insertRow(0); | - | ||||||||||||||||||||||||
1241 | } else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1242 | m_firstRow = 0; | - | ||||||||||||||||||||||||
1243 | removeRow(0); | - | ||||||||||||||||||||||||
1244 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1245 | internalUpdate(); | - | ||||||||||||||||||||||||
1246 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||
1248 | void QCalendarModel::setFirstColumnDay(Qt::DayOfWeek dayOfWeek) | - | ||||||||||||||||||||||||
1249 | { | - | ||||||||||||||||||||||||
1250 | if (m_firstDay == dayOfWeek)
| 0 | ||||||||||||||||||||||||
1251 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||
1253 | m_firstDay = dayOfWeek; | - | ||||||||||||||||||||||||
1254 | internalUpdate(); | - | ||||||||||||||||||||||||
1255 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||
1257 | Qt::DayOfWeek QCalendarModel::firstColumnDay() const | - | ||||||||||||||||||||||||
1258 | { | - | ||||||||||||||||||||||||
1259 | return m_firstDay; never executed: return m_firstDay; | 0 | ||||||||||||||||||||||||
1260 | } | - | ||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | bool QCalendarModel::weekNumbersShown() const | - | ||||||||||||||||||||||||
1263 | { | - | ||||||||||||||||||||||||
1264 | return m_weekNumbersShown; never executed: return m_weekNumbersShown; | 0 | ||||||||||||||||||||||||
1265 | } | - | ||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||
1267 | void QCalendarModel::setWeekNumbersShown(bool show) | - | ||||||||||||||||||||||||
1268 | { | - | ||||||||||||||||||||||||
1269 | if (m_weekNumbersShown == show)
| 0 | ||||||||||||||||||||||||
1270 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1271 | - | |||||||||||||||||||||||||
1272 | m_weekNumbersShown = show; | - | ||||||||||||||||||||||||
1273 | if (show) {
| 0 | ||||||||||||||||||||||||
1274 | m_firstColumn = 1; | - | ||||||||||||||||||||||||
1275 | insertColumn(0); | - | ||||||||||||||||||||||||
1276 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1277 | m_firstColumn = 0; | - | ||||||||||||||||||||||||
1278 | removeColumn(0); | - | ||||||||||||||||||||||||
1279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1280 | internalUpdate(); | - | ||||||||||||||||||||||||
1281 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1282 | - | |||||||||||||||||||||||||
1283 | QCalendarView::QCalendarView(QWidget *parent) | - | ||||||||||||||||||||||||
1284 | : QTableView(parent), | - | ||||||||||||||||||||||||
1285 | readOnly(false), | - | ||||||||||||||||||||||||
1286 | validDateClicked(false) | - | ||||||||||||||||||||||||
1287 | { | - | ||||||||||||||||||||||||
1288 | setTabKeyNavigation(false); | - | ||||||||||||||||||||||||
1289 | setShowGrid(false); | - | ||||||||||||||||||||||||
1290 | verticalHeader()->setVisible(false); | - | ||||||||||||||||||||||||
1291 | horizontalHeader()->setVisible(false); | - | ||||||||||||||||||||||||
1292 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||||||||
1293 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||||||||
1294 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1295 | - | |||||||||||||||||||||||||
1296 | QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - | ||||||||||||||||||||||||
1297 | { | - | ||||||||||||||||||||||||
1298 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1299 | if (!calendarModel)
| 0 | ||||||||||||||||||||||||
1300 | return QTableView::moveCursor(cursorAction, modifiers); never executed: return QTableView::moveCursor(cursorAction, modifiers); | 0 | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | if (readOnly)
| 0 | ||||||||||||||||||||||||
1303 | return currentIndex(); never executed: return currentIndex(); | 0 | ||||||||||||||||||||||||
1304 | - | |||||||||||||||||||||||||
1305 | QModelIndex index = currentIndex(); | - | ||||||||||||||||||||||||
1306 | QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); | - | ||||||||||||||||||||||||
1307 | switch (cursorAction) { | - | ||||||||||||||||||||||||
1308 | case QAbstractItemView::MoveUp: never executed: case QAbstractItemView::MoveUp: | 0 | ||||||||||||||||||||||||
1309 | currentDate = currentDate.addDays(-7); | - | ||||||||||||||||||||||||
1310 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1311 | case QAbstractItemView::MoveDown: never executed: case QAbstractItemView::MoveDown: | 0 | ||||||||||||||||||||||||
1312 | currentDate = currentDate.addDays(7); | - | ||||||||||||||||||||||||
1313 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1314 | case QAbstractItemView::MoveLeft: never executed: case QAbstractItemView::MoveLeft: | 0 | ||||||||||||||||||||||||
1315 | currentDate = currentDate.addDays(isRightToLeft() ? 1 : -1); | - | ||||||||||||||||||||||||
1316 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1317 | case QAbstractItemView::MoveRight: never executed: case QAbstractItemView::MoveRight: | 0 | ||||||||||||||||||||||||
1318 | currentDate = currentDate.addDays(isRightToLeft() ? -1 : 1); | - | ||||||||||||||||||||||||
1319 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1320 | case QAbstractItemView::MoveHome: never executed: case QAbstractItemView::MoveHome: | 0 | ||||||||||||||||||||||||
1321 | currentDate = QDate(currentDate.year(), currentDate.month(), 1); | - | ||||||||||||||||||||||||
1322 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1323 | case QAbstractItemView::MoveEnd: never executed: case QAbstractItemView::MoveEnd: | 0 | ||||||||||||||||||||||||
1324 | currentDate = QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth()); | - | ||||||||||||||||||||||||
1325 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1326 | case QAbstractItemView::MovePageUp: never executed: case QAbstractItemView::MovePageUp: | 0 | ||||||||||||||||||||||||
1327 | currentDate = currentDate.addMonths(-1); | - | ||||||||||||||||||||||||
1328 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1329 | case QAbstractItemView::MovePageDown: never executed: case QAbstractItemView::MovePageDown: | 0 | ||||||||||||||||||||||||
1330 | currentDate = currentDate.addMonths(1); | - | ||||||||||||||||||||||||
1331 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1332 | case QAbstractItemView::MoveNext: never executed: case QAbstractItemView::MoveNext: | 0 | ||||||||||||||||||||||||
1333 | case QAbstractItemView::MovePrevious: never executed: case QAbstractItemView::MovePrevious: | 0 | ||||||||||||||||||||||||
1334 | return currentIndex(); never executed: return currentIndex(); | 0 | ||||||||||||||||||||||||
1335 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1336 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1337 | } | - | ||||||||||||||||||||||||
1338 | emit changeDate(currentDate, true); | - | ||||||||||||||||||||||||
1339 | return currentIndex(); never executed: return currentIndex(); | 0 | ||||||||||||||||||||||||
1340 | } | - | ||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||
1342 | void QCalendarView::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||
1343 | { | - | ||||||||||||||||||||||||
1344 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1345 | if (event->key() == Qt::Key_Select) { | - | ||||||||||||||||||||||||
1346 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1347 | if (!hasEditFocus()) { | - | ||||||||||||||||||||||||
1348 | setEditFocus(true); | - | ||||||||||||||||||||||||
1349 | return; | - | ||||||||||||||||||||||||
1350 | } | - | ||||||||||||||||||||||||
1351 | } | - | ||||||||||||||||||||||||
1352 | } else if (event->key() == Qt::Key_Back) { | - | ||||||||||||||||||||||||
1353 | if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { | - | ||||||||||||||||||||||||
1354 | if (qobject_cast<QCalendarModel *>(model())) { | - | ||||||||||||||||||||||||
1355 | emit changeDate(origDate, true); //changes selection back to origDate, but doesn't activate | - | ||||||||||||||||||||||||
1356 | setEditFocus(false); | - | ||||||||||||||||||||||||
1357 | return; | - | ||||||||||||||||||||||||
1358 | } | - | ||||||||||||||||||||||||
1359 | } | - | ||||||||||||||||||||||||
1360 | } | - | ||||||||||||||||||||||||
1361 | #endif | - | ||||||||||||||||||||||||
1362 | - | |||||||||||||||||||||||||
1363 | if (!readOnly) {
| 0 | ||||||||||||||||||||||||
1364 | switch (event->key()) { | - | ||||||||||||||||||||||||
1365 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||
1366 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||
1367 | case Qt::Key_Select: never executed: case Qt::Key_Select: | 0 | ||||||||||||||||||||||||
1368 | emit editingFinished(); | - | ||||||||||||||||||||||||
1369 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1370 | default: never executed: default: | 0 | ||||||||||||||||||||||||
1371 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1372 | } | - | ||||||||||||||||||||||||
1373 | } | - | ||||||||||||||||||||||||
1374 | QTableView::keyPressEvent(event); | - | ||||||||||||||||||||||||
1375 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1376 | - | |||||||||||||||||||||||||
1377 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||
1378 | void QCalendarView::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||
1379 | { | - | ||||||||||||||||||||||||
1380 | const int numDegrees = event->delta() / 8; | - | ||||||||||||||||||||||||
1381 | const int numSteps = numDegrees / 15; | - | ||||||||||||||||||||||||
1382 | const QModelIndex index = currentIndex(); | - | ||||||||||||||||||||||||
1383 | QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column()); | - | ||||||||||||||||||||||||
1384 | currentDate = currentDate.addMonths(-numSteps); | - | ||||||||||||||||||||||||
1385 | emit showDate(currentDate); | - | ||||||||||||||||||||||||
1386 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1387 | #endif | - | ||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||
1389 | bool QCalendarView::event(QEvent *event) | - | ||||||||||||||||||||||||
1390 | { | - | ||||||||||||||||||||||||
1391 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1392 | if (event->type() == QEvent::FocusIn) { | - | ||||||||||||||||||||||||
1393 | if (QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model())) { | - | ||||||||||||||||||||||||
1394 | origDate = calendarModel->m_date; | - | ||||||||||||||||||||||||
1395 | } | - | ||||||||||||||||||||||||
1396 | } | - | ||||||||||||||||||||||||
1397 | #endif | - | ||||||||||||||||||||||||
1398 | - | |||||||||||||||||||||||||
1399 | return QTableView::event(event); never executed: return QTableView::event(event); | 0 | ||||||||||||||||||||||||
1400 | } | - | ||||||||||||||||||||||||
1401 | - | |||||||||||||||||||||||||
1402 | QDate QCalendarView::handleMouseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1403 | { | - | ||||||||||||||||||||||||
1404 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1405 | if (!calendarModel)
| 0 | ||||||||||||||||||||||||
1406 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||
1408 | QPoint pos = event->pos(); | - | ||||||||||||||||||||||||
1409 | QModelIndex index = indexAt(pos); | - | ||||||||||||||||||||||||
1410 | QDate date = calendarModel->dateForCell(index.row(), index.column()); | - | ||||||||||||||||||||||||
1411 | if (date.isValid() && date >= calendarModel->m_minimumDate
| 0 | ||||||||||||||||||||||||
1412 | && date <= calendarModel->m_maximumDate) {
| 0 | ||||||||||||||||||||||||
1413 | return date; never executed: return date; | 0 | ||||||||||||||||||||||||
1414 | } | - | ||||||||||||||||||||||||
1415 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||
1416 | } | - | ||||||||||||||||||||||||
1417 | - | |||||||||||||||||||||||||
1418 | void QCalendarView::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1419 | { | - | ||||||||||||||||||||||||
1420 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1421 | if (!calendarModel) {
| 0 | ||||||||||||||||||||||||
1422 | QTableView::mouseDoubleClickEvent(event); | - | ||||||||||||||||||||||||
1423 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1424 | } | - | ||||||||||||||||||||||||
1425 | - | |||||||||||||||||||||||||
1426 | if (readOnly)
| 0 | ||||||||||||||||||||||||
1427 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1428 | - | |||||||||||||||||||||||||
1429 | QDate date = handleMouseEvent(event); | - | ||||||||||||||||||||||||
1430 | validDateClicked = false; | - | ||||||||||||||||||||||||
1431 | if (date == calendarModel->m_date && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
| 0 | ||||||||||||||||||||||||
1432 | emit editingFinished(); | - | ||||||||||||||||||||||||
1433 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1434 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1435 | - | |||||||||||||||||||||||||
1436 | void QCalendarView::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1437 | { | - | ||||||||||||||||||||||||
1438 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1439 | if (!calendarModel) {
| 0 | ||||||||||||||||||||||||
1440 | QTableView::mousePressEvent(event); | - | ||||||||||||||||||||||||
1441 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1442 | } | - | ||||||||||||||||||||||||
1443 | - | |||||||||||||||||||||||||
1444 | if (readOnly)
| 0 | ||||||||||||||||||||||||
1445 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1446 | - | |||||||||||||||||||||||||
1447 | if (event->button() != Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
1448 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||
1450 | QDate date = handleMouseEvent(event); | - | ||||||||||||||||||||||||
1451 | if (date.isValid()) {
| 0 | ||||||||||||||||||||||||
1452 | validDateClicked = true; | - | ||||||||||||||||||||||||
1453 | int row = -1, col = -1; | - | ||||||||||||||||||||||||
1454 | static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); | - | ||||||||||||||||||||||||
1455 | if (row != -1 && col != -1) {
| 0 | ||||||||||||||||||||||||
1456 | selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
1457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1458 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1459 | validDateClicked = false; | - | ||||||||||||||||||||||||
1460 | event->ignore(); | - | ||||||||||||||||||||||||
1461 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1462 | } | - | ||||||||||||||||||||||||
1463 | - | |||||||||||||||||||||||||
1464 | void QCalendarView::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1465 | { | - | ||||||||||||||||||||||||
1466 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1467 | if (!calendarModel) {
| 0 | ||||||||||||||||||||||||
1468 | QTableView::mouseMoveEvent(event); | - | ||||||||||||||||||||||||
1469 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1470 | } | - | ||||||||||||||||||||||||
1471 | - | |||||||||||||||||||||||||
1472 | if (readOnly)
| 0 | ||||||||||||||||||||||||
1473 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1474 | - | |||||||||||||||||||||||||
1475 | if (validDateClicked) {
| 0 | ||||||||||||||||||||||||
1476 | QDate date = handleMouseEvent(event); | - | ||||||||||||||||||||||||
1477 | if (date.isValid()) {
| 0 | ||||||||||||||||||||||||
1478 | int row = -1, col = -1; | - | ||||||||||||||||||||||||
1479 | static_cast<QCalendarModel *>(model())->cellForDate(date, &row, &col); | - | ||||||||||||||||||||||||
1480 | if (row != -1 && col != -1) {
| 0 | ||||||||||||||||||||||||
1481 | selectionModel()->setCurrentIndex(model()->index(row, col), QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
1482 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1483 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1484 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1485 | event->ignore(); | - | ||||||||||||||||||||||||
1486 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1487 | } | - | ||||||||||||||||||||||||
1488 | - | |||||||||||||||||||||||||
1489 | void QCalendarView::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1490 | { | - | ||||||||||||||||||||||||
1491 | QCalendarModel *calendarModel = qobject_cast<QCalendarModel *>(model()); | - | ||||||||||||||||||||||||
1492 | if (!calendarModel) {
| 0 | ||||||||||||||||||||||||
1493 | QTableView::mouseReleaseEvent(event); | - | ||||||||||||||||||||||||
1494 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1495 | } | - | ||||||||||||||||||||||||
1496 | - | |||||||||||||||||||||||||
1497 | if (event->button() != Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
1498 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1499 | - | |||||||||||||||||||||||||
1500 | if (readOnly)
| 0 | ||||||||||||||||||||||||
1501 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1502 | - | |||||||||||||||||||||||||
1503 | if (validDateClicked) {
| 0 | ||||||||||||||||||||||||
1504 | QDate date = handleMouseEvent(event); | - | ||||||||||||||||||||||||
1505 | if (date.isValid()) {
| 0 | ||||||||||||||||||||||||
1506 | emit changeDate(date, true); | - | ||||||||||||||||||||||||
1507 | emit clicked(date); | - | ||||||||||||||||||||||||
1508 | if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick))
| 0 | ||||||||||||||||||||||||
1509 | emit editingFinished(); never executed: editingFinished(); | 0 | ||||||||||||||||||||||||
1510 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1511 | validDateClicked = false; | - | ||||||||||||||||||||||||
1512 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1513 | event->ignore(); | - | ||||||||||||||||||||||||
1514 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1515 | } | - | ||||||||||||||||||||||||
1516 | - | |||||||||||||||||||||||||
1517 | class QCalendarDelegate : public QItemDelegate | - | ||||||||||||||||||||||||
1518 | { | - | ||||||||||||||||||||||||
1519 | Q_OBJECT | - | ||||||||||||||||||||||||
1520 | public: | - | ||||||||||||||||||||||||
1521 | QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = 0) | - | ||||||||||||||||||||||||
1522 | : QItemDelegate(parent), calendarWidgetPrivate(w) | - | ||||||||||||||||||||||||
1523 | { } never executed: end of block | 0 | ||||||||||||||||||||||||
1524 | virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, | - | ||||||||||||||||||||||||
1525 | const QModelIndex &index) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
1526 | void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; | - | ||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||
1528 | private: | - | ||||||||||||||||||||||||
1529 | QCalendarWidgetPrivate *calendarWidgetPrivate; | - | ||||||||||||||||||||||||
1530 | mutable QStyleOptionViewItem storedOption; | - | ||||||||||||||||||||||||
1531 | }; | - | ||||||||||||||||||||||||
1532 | - | |||||||||||||||||||||||||
1533 | //Private tool button class | - | ||||||||||||||||||||||||
1534 | class QCalToolButton: public QToolButton | - | ||||||||||||||||||||||||
1535 | { | - | ||||||||||||||||||||||||
1536 | public: | - | ||||||||||||||||||||||||
1537 | QCalToolButton(QWidget * parent) | - | ||||||||||||||||||||||||
1538 | : QToolButton(parent) | - | ||||||||||||||||||||||||
1539 | { } never executed: end of block | 0 | ||||||||||||||||||||||||
1540 | protected: | - | ||||||||||||||||||||||||
1541 | void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
1542 | { | - | ||||||||||||||||||||||||
1543 | Q_UNUSED(e) | - | ||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||
1545 | #ifndef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||
1546 | QStyleOptionToolButton opt; | - | ||||||||||||||||||||||||
1547 | initStyleOption(&opt); | - | ||||||||||||||||||||||||
1548 | - | |||||||||||||||||||||||||
1549 | if (opt.state & QStyle::State_MouseOver || isDown()) {
| 0 | ||||||||||||||||||||||||
1550 | //act as normal button | - | ||||||||||||||||||||||||
1551 | setPalette(QPalette()); | - | ||||||||||||||||||||||||
1552 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1553 | //set the highlight color for button text | - | ||||||||||||||||||||||||
1554 | QPalette toolPalette = palette(); | - | ||||||||||||||||||||||||
1555 | toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText)); | - | ||||||||||||||||||||||||
1556 | setPalette(toolPalette); | - | ||||||||||||||||||||||||
1557 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1558 | #endif | - | ||||||||||||||||||||||||
1559 | QToolButton::paintEvent(e); | - | ||||||||||||||||||||||||
1560 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1561 | }; | - | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | class QPrevNextCalButton : public QToolButton | - | ||||||||||||||||||||||||
1564 | { | - | ||||||||||||||||||||||||
1565 | Q_OBJECT | - | ||||||||||||||||||||||||
1566 | public: | - | ||||||||||||||||||||||||
1567 | QPrevNextCalButton(QWidget *parent) : QToolButton(parent) {} never executed: end of block | 0 | ||||||||||||||||||||||||
1568 | protected: | - | ||||||||||||||||||||||||
1569 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE { | - | ||||||||||||||||||||||||
1570 | QStylePainter painter(this); | - | ||||||||||||||||||||||||
1571 | QStyleOptionToolButton opt; | - | ||||||||||||||||||||||||
1572 | initStyleOption(&opt); | - | ||||||||||||||||||||||||
1573 | opt.state &= ~QStyle::State_HasFocus; | - | ||||||||||||||||||||||||
1574 | painter.drawComplexControl(QStyle::CC_ToolButton, opt); | - | ||||||||||||||||||||||||
1575 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1576 | }; | - | ||||||||||||||||||||||||
1577 | - | |||||||||||||||||||||||||
1578 | } // unnamed namespace | - | ||||||||||||||||||||||||
1579 | - | |||||||||||||||||||||||||
1580 | class QCalendarWidgetPrivate : public QWidgetPrivate | - | ||||||||||||||||||||||||
1581 | { | - | ||||||||||||||||||||||||
1582 | Q_DECLARE_PUBLIC(QCalendarWidget) | - | ||||||||||||||||||||||||
1583 | public: | - | ||||||||||||||||||||||||
1584 | QCalendarWidgetPrivate(); | - | ||||||||||||||||||||||||
1585 | - | |||||||||||||||||||||||||
1586 | void showMonth(int year, int month); | - | ||||||||||||||||||||||||
1587 | void update(); | - | ||||||||||||||||||||||||
1588 | void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; | - | ||||||||||||||||||||||||
1589 | - | |||||||||||||||||||||||||
1590 | void _q_slotShowDate(const QDate &date); | - | ||||||||||||||||||||||||
1591 | void _q_slotChangeDate(const QDate &date); | - | ||||||||||||||||||||||||
1592 | void _q_slotChangeDate(const QDate &date, bool changeMonth); | - | ||||||||||||||||||||||||
1593 | void _q_editingFinished(); | - | ||||||||||||||||||||||||
1594 | void _q_monthChanged(QAction*); | - | ||||||||||||||||||||||||
1595 | void _q_prevMonthClicked(); | - | ||||||||||||||||||||||||
1596 | void _q_nextMonthClicked(); | - | ||||||||||||||||||||||||
1597 | void _q_yearEditingFinished(); | - | ||||||||||||||||||||||||
1598 | void _q_yearClicked(); | - | ||||||||||||||||||||||||
1599 | - | |||||||||||||||||||||||||
1600 | void createNavigationBar(QWidget *widget); | - | ||||||||||||||||||||||||
1601 | void updateButtonIcons(); | - | ||||||||||||||||||||||||
1602 | void updateMonthMenu(); | - | ||||||||||||||||||||||||
1603 | void updateMonthMenuNames(); | - | ||||||||||||||||||||||||
1604 | void updateNavigationBar(); | - | ||||||||||||||||||||||||
1605 | void updateCurrentPage(const QDate &newDate); | - | ||||||||||||||||||||||||
1606 | inline QDate getCurrentDate(); | - | ||||||||||||||||||||||||
1607 | void setNavigatorEnabled(bool enable); | - | ||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||
1609 | QCalendarModel *m_model; | - | ||||||||||||||||||||||||
1610 | QCalendarView *m_view; | - | ||||||||||||||||||||||||
1611 | QCalendarDelegate *m_delegate; | - | ||||||||||||||||||||||||
1612 | QItemSelectionModel *m_selection; | - | ||||||||||||||||||||||||
1613 | QCalendarTextNavigator *m_navigator; | - | ||||||||||||||||||||||||
1614 | bool m_dateEditEnabled; | - | ||||||||||||||||||||||||
1615 | - | |||||||||||||||||||||||||
1616 | QToolButton *nextMonth; | - | ||||||||||||||||||||||||
1617 | QToolButton *prevMonth; | - | ||||||||||||||||||||||||
1618 | QCalToolButton *monthButton; | - | ||||||||||||||||||||||||
1619 | QMenu *monthMenu; | - | ||||||||||||||||||||||||
1620 | QMap<int, QAction *> monthToAction; | - | ||||||||||||||||||||||||
1621 | QCalToolButton *yearButton; | - | ||||||||||||||||||||||||
1622 | QSpinBox *yearEdit; | - | ||||||||||||||||||||||||
1623 | QWidget *navBarBackground; | - | ||||||||||||||||||||||||
1624 | QSpacerItem *spaceHolder; | - | ||||||||||||||||||||||||
1625 | - | |||||||||||||||||||||||||
1626 | bool navBarVisible; | - | ||||||||||||||||||||||||
1627 | mutable QSize cachedSizeHint; | - | ||||||||||||||||||||||||
1628 | Qt::FocusPolicy oldFocusPolicy; | - | ||||||||||||||||||||||||
1629 | }; | - | ||||||||||||||||||||||||
1630 | - | |||||||||||||||||||||||||
1631 | void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, | - | ||||||||||||||||||||||||
1632 | const QModelIndex &index) const | - | ||||||||||||||||||||||||
1633 | { | - | ||||||||||||||||||||||||
1634 | QDate date = calendarWidgetPrivate->m_model->dateForCell(index.row(), index.column()); | - | ||||||||||||||||||||||||
1635 | if (date.isValid()) {
| 0 | ||||||||||||||||||||||||
1636 | storedOption = option; | - | ||||||||||||||||||||||||
1637 | QRect rect = option.rect; | - | ||||||||||||||||||||||||
1638 | calendarWidgetPrivate->paintCell(painter, rect, date); | - | ||||||||||||||||||||||||
1639 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1640 | QItemDelegate::paint(painter, option, index); | - | ||||||||||||||||||||||||
1641 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1642 | } | - | ||||||||||||||||||||||||
1643 | - | |||||||||||||||||||||||||
1644 | void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||||||||||||||
1645 | { | - | ||||||||||||||||||||||||
1646 | storedOption.rect = rect; | - | ||||||||||||||||||||||||
1647 | int row = -1; | - | ||||||||||||||||||||||||
1648 | int col = -1; | - | ||||||||||||||||||||||||
1649 | calendarWidgetPrivate->m_model->cellForDate(date, &row, &col); | - | ||||||||||||||||||||||||
1650 | QModelIndex idx = calendarWidgetPrivate->m_model->index(row, col); | - | ||||||||||||||||||||||||
1651 | QItemDelegate::paint(painter, storedOption, idx); | - | ||||||||||||||||||||||||
1652 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||
1654 | QCalendarWidgetPrivate::QCalendarWidgetPrivate() | - | ||||||||||||||||||||||||
1655 | : QWidgetPrivate() | - | ||||||||||||||||||||||||
1656 | { | - | ||||||||||||||||||||||||
1657 | m_model = 0; | - | ||||||||||||||||||||||||
1658 | m_view = 0; | - | ||||||||||||||||||||||||
1659 | m_delegate = 0; | - | ||||||||||||||||||||||||
1660 | m_selection = 0; | - | ||||||||||||||||||||||||
1661 | m_navigator = 0; | - | ||||||||||||||||||||||||
1662 | m_dateEditEnabled = false; | - | ||||||||||||||||||||||||
1663 | navBarVisible = true; | - | ||||||||||||||||||||||||
1664 | oldFocusPolicy = Qt::StrongFocus; | - | ||||||||||||||||||||||||
1665 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1666 | - | |||||||||||||||||||||||||
1667 | void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable) | - | ||||||||||||||||||||||||
1668 | { | - | ||||||||||||||||||||||||
1669 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1670 | - | |||||||||||||||||||||||||
1671 | bool navigatorEnabled = (m_navigator->widget() != 0); | - | ||||||||||||||||||||||||
1672 | if (enable == navigatorEnabled)
| 0 | ||||||||||||||||||||||||
1673 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1674 | - | |||||||||||||||||||||||||
1675 | if (enable) {
| 0 | ||||||||||||||||||||||||
1676 | m_navigator->setWidget(q); | - | ||||||||||||||||||||||||
1677 | q->connect(m_navigator, SIGNAL(dateChanged(QDate)), | - | ||||||||||||||||||||||||
1678 | q, SLOT(_q_slotChangeDate(QDate))); | - | ||||||||||||||||||||||||
1679 | q->connect(m_navigator, SIGNAL(editingFinished()), | - | ||||||||||||||||||||||||
1680 | q, SLOT(_q_editingFinished())); | - | ||||||||||||||||||||||||
1681 | m_view->installEventFilter(m_navigator); | - | ||||||||||||||||||||||||
1682 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1683 | m_navigator->setWidget(0); | - | ||||||||||||||||||||||||
1684 | q->disconnect(m_navigator, SIGNAL(dateChanged(QDate)), | - | ||||||||||||||||||||||||
1685 | q, SLOT(_q_slotChangeDate(QDate))); | - | ||||||||||||||||||||||||
1686 | q->disconnect(m_navigator, SIGNAL(editingFinished()), | - | ||||||||||||||||||||||||
1687 | q, SLOT(_q_editingFinished())); | - | ||||||||||||||||||||||||
1688 | m_view->removeEventFilter(m_navigator); | - | ||||||||||||||||||||||||
1689 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1690 | } | - | ||||||||||||||||||||||||
1691 | - | |||||||||||||||||||||||||
1692 | void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) | - | ||||||||||||||||||||||||
1693 | { | - | ||||||||||||||||||||||||
1694 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1695 | navBarBackground = new QWidget(widget); | - | ||||||||||||||||||||||||
1696 | navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar")); | - | ||||||||||||||||||||||||
1697 | navBarBackground->setAutoFillBackground(true); | - | ||||||||||||||||||||||||
1698 | navBarBackground->setBackgroundRole(QPalette::Highlight); | - | ||||||||||||||||||||||||
1699 | - | |||||||||||||||||||||||||
1700 | prevMonth = new QPrevNextCalButton(navBarBackground); | - | ||||||||||||||||||||||||
1701 | nextMonth = new QPrevNextCalButton(navBarBackground); | - | ||||||||||||||||||||||||
1702 | prevMonth->setAutoRaise(true); | - | ||||||||||||||||||||||||
1703 | nextMonth->setAutoRaise(true); | - | ||||||||||||||||||||||||
1704 | prevMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||||||||||||||
1705 | nextMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||||||||||||||
1706 | nextMonth->setAutoRaise(true); | - | ||||||||||||||||||||||||
1707 | updateButtonIcons(); | - | ||||||||||||||||||||||||
1708 | prevMonth->setAutoRepeat(true); | - | ||||||||||||||||||||||||
1709 | nextMonth->setAutoRepeat(true); | - | ||||||||||||||||||||||||
1710 | - | |||||||||||||||||||||||||
1711 | monthButton = new QCalToolButton(navBarBackground); | - | ||||||||||||||||||||||||
1712 | monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||||||||||||||
1713 | monthButton->setAutoRaise(true); | - | ||||||||||||||||||||||||
1714 | monthButton->setPopupMode(QToolButton::InstantPopup); | - | ||||||||||||||||||||||||
1715 | monthMenu = new QMenu(monthButton); | - | ||||||||||||||||||||||||
1716 | for (int i = 1; i <= 12; i++) {
| 0 | ||||||||||||||||||||||||
1717 | QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); | - | ||||||||||||||||||||||||
1718 | QAction *act = monthMenu->addAction(monthName); | - | ||||||||||||||||||||||||
1719 | act->setData(i); | - | ||||||||||||||||||||||||
1720 | monthToAction[i] = act; | - | ||||||||||||||||||||||||
1721 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1722 | monthButton->setMenu(monthMenu); | - | ||||||||||||||||||||||||
1723 | yearButton = new QCalToolButton(navBarBackground); | - | ||||||||||||||||||||||||
1724 | yearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); | - | ||||||||||||||||||||||||
1725 | yearButton->setAutoRaise(true); | - | ||||||||||||||||||||||||
1726 | yearEdit = new QSpinBox(navBarBackground); | - | ||||||||||||||||||||||||
1727 | - | |||||||||||||||||||||||||
1728 | QFont font = q->font(); | - | ||||||||||||||||||||||||
1729 | font.setBold(true); | - | ||||||||||||||||||||||||
1730 | monthButton->setFont(font); | - | ||||||||||||||||||||||||
1731 | yearButton->setFont(font); | - | ||||||||||||||||||||||||
1732 | yearEdit->setFrame(false); | - | ||||||||||||||||||||||||
1733 | yearEdit->setMinimum(m_model->m_minimumDate.year()); | - | ||||||||||||||||||||||||
1734 | yearEdit->setMaximum(m_model->m_maximumDate.year()); | - | ||||||||||||||||||||||||
1735 | yearEdit->hide(); | - | ||||||||||||||||||||||||
1736 | spaceHolder = new QSpacerItem(0,0); | - | ||||||||||||||||||||||||
1737 | - | |||||||||||||||||||||||||
1738 | QHBoxLayout *headerLayout = new QHBoxLayout; | - | ||||||||||||||||||||||||
1739 | headerLayout->setMargin(0); | - | ||||||||||||||||||||||||
1740 | headerLayout->setSpacing(0); | - | ||||||||||||||||||||||||
1741 | headerLayout->addWidget(prevMonth); | - | ||||||||||||||||||||||||
1742 | headerLayout->insertStretch(headerLayout->count()); | - | ||||||||||||||||||||||||
1743 | headerLayout->addWidget(monthButton); | - | ||||||||||||||||||||||||
1744 | headerLayout->addItem(spaceHolder); | - | ||||||||||||||||||||||||
1745 | headerLayout->addWidget(yearButton); | - | ||||||||||||||||||||||||
1746 | headerLayout->insertStretch(headerLayout->count()); | - | ||||||||||||||||||||||||
1747 | headerLayout->addWidget(nextMonth); | - | ||||||||||||||||||||||||
1748 | navBarBackground->setLayout(headerLayout); | - | ||||||||||||||||||||||||
1749 | - | |||||||||||||||||||||||||
1750 | yearEdit->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||||||||
1751 | prevMonth->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
1752 | nextMonth->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
1753 | yearButton->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
1754 | monthButton->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
1755 | - | |||||||||||||||||||||||||
1756 | //set names for the header controls. | - | ||||||||||||||||||||||||
1757 | prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth")); | - | ||||||||||||||||||||||||
1758 | nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth")); | - | ||||||||||||||||||||||||
1759 | monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton")); | - | ||||||||||||||||||||||||
1760 | yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton")); | - | ||||||||||||||||||||||||
1761 | yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit")); | - | ||||||||||||||||||||||||
1762 | - | |||||||||||||||||||||||||
1763 | updateMonthMenu(); | - | ||||||||||||||||||||||||
1764 | showMonth(m_model->m_date.year(), m_model->m_date.month()); | - | ||||||||||||||||||||||||
1765 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1766 | - | |||||||||||||||||||||||||
1767 | void QCalendarWidgetPrivate::updateButtonIcons() | - | ||||||||||||||||||||||||
1768 | { | - | ||||||||||||||||||||||||
1769 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1770 | prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, 0, q)); | - | ||||||||||||||||||||||||
1771 | nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, 0, q)); | - | ||||||||||||||||||||||||
1772 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1773 | - | |||||||||||||||||||||||||
1774 | void QCalendarWidgetPrivate::updateMonthMenu() | - | ||||||||||||||||||||||||
1775 | { | - | ||||||||||||||||||||||||
1776 | int beg = 1, end = 12; | - | ||||||||||||||||||||||||
1777 | bool prevEnabled = true; | - | ||||||||||||||||||||||||
1778 | bool nextEnabled = true; | - | ||||||||||||||||||||||||
1779 | if (m_model->m_shownYear == m_model->m_minimumDate.year()) {
| 0 | ||||||||||||||||||||||||
1780 | beg = m_model->m_minimumDate.month(); | - | ||||||||||||||||||||||||
1781 | if (m_model->m_shownMonth == m_model->m_minimumDate.month())
| 0 | ||||||||||||||||||||||||
1782 | prevEnabled = false; never executed: prevEnabled = false; | 0 | ||||||||||||||||||||||||
1783 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1784 | if (m_model->m_shownYear == m_model->m_maximumDate.year()) {
| 0 | ||||||||||||||||||||||||
1785 | end = m_model->m_maximumDate.month(); | - | ||||||||||||||||||||||||
1786 | if (m_model->m_shownMonth == m_model->m_maximumDate.month())
| 0 | ||||||||||||||||||||||||
1787 | nextEnabled = false; never executed: nextEnabled = false; | 0 | ||||||||||||||||||||||||
1788 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1789 | prevMonth->setEnabled(prevEnabled); | - | ||||||||||||||||||||||||
1790 | nextMonth->setEnabled(nextEnabled); | - | ||||||||||||||||||||||||
1791 | for (int i = 1; i <= 12; i++) {
| 0 | ||||||||||||||||||||||||
1792 | bool monthEnabled = true; | - | ||||||||||||||||||||||||
1793 | if (i < beg || i > end)
| 0 | ||||||||||||||||||||||||
1794 | monthEnabled = false; never executed: monthEnabled = false; | 0 | ||||||||||||||||||||||||
1795 | monthToAction[i]->setEnabled(monthEnabled); | - | ||||||||||||||||||||||||
1796 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1797 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1798 | - | |||||||||||||||||||||||||
1799 | void QCalendarWidgetPrivate::updateMonthMenuNames() | - | ||||||||||||||||||||||||
1800 | { | - | ||||||||||||||||||||||||
1801 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1802 | - | |||||||||||||||||||||||||
1803 | for (int i = 1; i <= 12; i++) {
| 0 | ||||||||||||||||||||||||
1804 | QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); | - | ||||||||||||||||||||||||
1805 | monthToAction[i]->setText(monthName); | - | ||||||||||||||||||||||||
1806 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1807 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1808 | - | |||||||||||||||||||||||||
1809 | void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date) | - | ||||||||||||||||||||||||
1810 | { | - | ||||||||||||||||||||||||
1811 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1812 | - | |||||||||||||||||||||||||
1813 | QDate newDate = date; | - | ||||||||||||||||||||||||
1814 | QDate minDate = q->minimumDate(); | - | ||||||||||||||||||||||||
1815 | QDate maxDate = q->maximumDate(); | - | ||||||||||||||||||||||||
1816 | if (minDate.isValid()&& minDate.daysTo(newDate) < 0)
| 0 | ||||||||||||||||||||||||
1817 | newDate = minDate; never executed: newDate = minDate; | 0 | ||||||||||||||||||||||||
1818 | if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0)
| 0 | ||||||||||||||||||||||||
1819 | newDate = maxDate; never executed: newDate = maxDate; | 0 | ||||||||||||||||||||||||
1820 | showMonth(newDate.year(), newDate.month()); | - | ||||||||||||||||||||||||
1821 | int row = -1, col = -1; | - | ||||||||||||||||||||||||
1822 | m_model->cellForDate(newDate, &row, &col); | - | ||||||||||||||||||||||||
1823 | if (row != -1 && col != -1)
| 0 | ||||||||||||||||||||||||
1824 | { | - | ||||||||||||||||||||||||
1825 | m_view->selectionModel()->setCurrentIndex(m_model->index(row, col), | - | ||||||||||||||||||||||||
1826 | QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
1827 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1828 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1829 | - | |||||||||||||||||||||||||
1830 | void QCalendarWidgetPrivate::_q_monthChanged(QAction *act) | - | ||||||||||||||||||||||||
1831 | { | - | ||||||||||||||||||||||||
1832 | monthButton->setText(act->text()); | - | ||||||||||||||||||||||||
1833 | QDate currentDate = getCurrentDate(); | - | ||||||||||||||||||||||||
1834 | QDate newDate = currentDate.addMonths(act->data().toInt()-currentDate.month()); | - | ||||||||||||||||||||||||
1835 | updateCurrentPage(newDate); | - | ||||||||||||||||||||||||
1836 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1837 | - | |||||||||||||||||||||||||
1838 | QDate QCalendarWidgetPrivate::getCurrentDate() | - | ||||||||||||||||||||||||
1839 | { | - | ||||||||||||||||||||||||
1840 | QModelIndex index = m_view->currentIndex(); | - | ||||||||||||||||||||||||
1841 | return m_model->dateForCell(index.row(), index.column()); never executed: return m_model->dateForCell(index.row(), index.column()); | 0 | ||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||
1843 | - | |||||||||||||||||||||||||
1844 | void QCalendarWidgetPrivate::_q_prevMonthClicked() | - | ||||||||||||||||||||||||
1845 | { | - | ||||||||||||||||||||||||
1846 | QDate currentDate = getCurrentDate().addMonths(-1); | - | ||||||||||||||||||||||||
1847 | updateCurrentPage(currentDate); | - | ||||||||||||||||||||||||
1848 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1849 | - | |||||||||||||||||||||||||
1850 | void QCalendarWidgetPrivate::_q_nextMonthClicked() | - | ||||||||||||||||||||||||
1851 | { | - | ||||||||||||||||||||||||
1852 | QDate currentDate = getCurrentDate().addMonths(1); | - | ||||||||||||||||||||||||
1853 | updateCurrentPage(currentDate); | - | ||||||||||||||||||||||||
1854 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1855 | - | |||||||||||||||||||||||||
1856 | void QCalendarWidgetPrivate::_q_yearEditingFinished() | - | ||||||||||||||||||||||||
1857 | { | - | ||||||||||||||||||||||||
1858 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1859 | yearButton->setText(yearEdit->text()); | - | ||||||||||||||||||||||||
1860 | yearEdit->hide(); | - | ||||||||||||||||||||||||
1861 | q->setFocusPolicy(oldFocusPolicy); | - | ||||||||||||||||||||||||
1862 | qApp->removeEventFilter(q); | - | ||||||||||||||||||||||||
1863 | spaceHolder->changeSize(0, 0); | - | ||||||||||||||||||||||||
1864 | yearButton->show(); | - | ||||||||||||||||||||||||
1865 | QDate currentDate = getCurrentDate(); | - | ||||||||||||||||||||||||
1866 | currentDate = currentDate.addYears(yearEdit->text().toInt() - currentDate.year()); | - | ||||||||||||||||||||||||
1867 | updateCurrentPage(currentDate); | - | ||||||||||||||||||||||||
1868 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1869 | - | |||||||||||||||||||||||||
1870 | void QCalendarWidgetPrivate::_q_yearClicked() | - | ||||||||||||||||||||||||
1871 | { | - | ||||||||||||||||||||||||
1872 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1873 | //show the spinbox on top of the button | - | ||||||||||||||||||||||||
1874 | yearEdit->setGeometry(yearButton->x(), yearButton->y(), | - | ||||||||||||||||||||||||
1875 | yearEdit->sizeHint().width(), yearButton->height()); | - | ||||||||||||||||||||||||
1876 | spaceHolder->changeSize(yearButton->width(), 0); | - | ||||||||||||||||||||||||
1877 | yearButton->hide(); | - | ||||||||||||||||||||||||
1878 | oldFocusPolicy = q->focusPolicy(); | - | ||||||||||||||||||||||||
1879 | q->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
1880 | yearEdit->show(); | - | ||||||||||||||||||||||||
1881 | qApp->installEventFilter(q); | - | ||||||||||||||||||||||||
1882 | yearEdit->raise(); | - | ||||||||||||||||||||||||
1883 | yearEdit->selectAll(); | - | ||||||||||||||||||||||||
1884 | yearEdit->setFocus(Qt::MouseFocusReason); | - | ||||||||||||||||||||||||
1885 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1886 | - | |||||||||||||||||||||||||
1887 | void QCalendarWidgetPrivate::showMonth(int year, int month) | - | ||||||||||||||||||||||||
1888 | { | - | ||||||||||||||||||||||||
1889 | if (m_model->m_shownYear == year && m_model->m_shownMonth == month)
| 0 | ||||||||||||||||||||||||
1890 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1891 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1892 | m_model->showMonth(year, month); | - | ||||||||||||||||||||||||
1893 | updateNavigationBar(); | - | ||||||||||||||||||||||||
1894 | emit q->currentPageChanged(year, month); | - | ||||||||||||||||||||||||
1895 | m_view->internalUpdate(); | - | ||||||||||||||||||||||||
1896 | cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
1897 | update(); | - | ||||||||||||||||||||||||
1898 | updateMonthMenu(); | - | ||||||||||||||||||||||||
1899 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1900 | - | |||||||||||||||||||||||||
1901 | void QCalendarWidgetPrivate::updateNavigationBar() | - | ||||||||||||||||||||||||
1902 | { | - | ||||||||||||||||||||||||
1903 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1904 | - | |||||||||||||||||||||||||
1905 | QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat); | - | ||||||||||||||||||||||||
1906 | - | |||||||||||||||||||||||||
1907 | monthButton->setText(monthName); | - | ||||||||||||||||||||||||
1908 | yearButton->setText(QString::number(m_model->m_shownYear)); | - | ||||||||||||||||||||||||
1909 | yearEdit->setValue(m_model->m_shownYear); | - | ||||||||||||||||||||||||
1910 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1911 | - | |||||||||||||||||||||||||
1912 | void QCalendarWidgetPrivate::update() | - | ||||||||||||||||||||||||
1913 | { | - | ||||||||||||||||||||||||
1914 | QDate currentDate = m_model->m_date; | - | ||||||||||||||||||||||||
1915 | int row, column; | - | ||||||||||||||||||||||||
1916 | m_model->cellForDate(currentDate, &row, &column); | - | ||||||||||||||||||||||||
1917 | QModelIndex idx; | - | ||||||||||||||||||||||||
1918 | m_selection->clear(); | - | ||||||||||||||||||||||||
1919 | if (row != -1 && column != -1) {
| 0 | ||||||||||||||||||||||||
1920 | idx = m_model->index(row, column); | - | ||||||||||||||||||||||||
1921 | m_selection->setCurrentIndex(idx, QItemSelectionModel::SelectCurrent); | - | ||||||||||||||||||||||||
1922 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1923 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1924 | - | |||||||||||||||||||||||||
1925 | void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||||||||||||||
1926 | { | - | ||||||||||||||||||||||||
1927 | Q_Q(const QCalendarWidget); | - | ||||||||||||||||||||||||
1928 | q->paintCell(painter, rect, date); | - | ||||||||||||||||||||||||
1929 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1930 | - | |||||||||||||||||||||||||
1931 | void QCalendarWidgetPrivate::_q_slotShowDate(const QDate &date) | - | ||||||||||||||||||||||||
1932 | { | - | ||||||||||||||||||||||||
1933 | updateCurrentPage(date); | - | ||||||||||||||||||||||||
1934 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1935 | - | |||||||||||||||||||||||||
1936 | void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date) | - | ||||||||||||||||||||||||
1937 | { | - | ||||||||||||||||||||||||
1938 | _q_slotChangeDate(date, true); | - | ||||||||||||||||||||||||
1939 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1940 | - | |||||||||||||||||||||||||
1941 | void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date, bool changeMonth) | - | ||||||||||||||||||||||||
1942 | { | - | ||||||||||||||||||||||||
1943 | QDate oldDate = m_model->m_date; | - | ||||||||||||||||||||||||
1944 | m_model->setDate(date); | - | ||||||||||||||||||||||||
1945 | QDate newDate = m_model->m_date; | - | ||||||||||||||||||||||||
1946 | if (changeMonth)
| 0 | ||||||||||||||||||||||||
1947 | showMonth(newDate.year(), newDate.month()); never executed: showMonth(newDate.year(), newDate.month()); | 0 | ||||||||||||||||||||||||
1948 | if (oldDate != newDate) {
| 0 | ||||||||||||||||||||||||
1949 | update(); | - | ||||||||||||||||||||||||
1950 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1951 | m_navigator->setDate(newDate); | - | ||||||||||||||||||||||||
1952 | emit q->selectionChanged(); | - | ||||||||||||||||||||||||
1953 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1954 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1955 | - | |||||||||||||||||||||||||
1956 | void QCalendarWidgetPrivate::_q_editingFinished() | - | ||||||||||||||||||||||||
1957 | { | - | ||||||||||||||||||||||||
1958 | Q_Q(QCalendarWidget); | - | ||||||||||||||||||||||||
1959 | emit q->activated(m_model->m_date); | - | ||||||||||||||||||||||||
1960 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1961 | - | |||||||||||||||||||||||||
1962 | /*! | - | ||||||||||||||||||||||||
1963 | \class QCalendarWidget | - | ||||||||||||||||||||||||
1964 | \brief The QCalendarWidget class provides a monthly based | - | ||||||||||||||||||||||||
1965 | calendar widget allowing the user to select a date. | - | ||||||||||||||||||||||||
1966 | \since 4.2 | - | ||||||||||||||||||||||||
1967 | - | |||||||||||||||||||||||||
1968 | \ingroup advanced | - | ||||||||||||||||||||||||
1969 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
1970 | - | |||||||||||||||||||||||||
1971 | \image fusion-calendarwidget.png | - | ||||||||||||||||||||||||
1972 | - | |||||||||||||||||||||||||
1973 | The widget is initialized with the current month and year, but | - | ||||||||||||||||||||||||
1974 | QCalendarWidget provides several public slots to change the year | - | ||||||||||||||||||||||||
1975 | and month that is shown. | - | ||||||||||||||||||||||||
1976 | - | |||||||||||||||||||||||||
1977 | By default, today's date is selected, and the user can select a | - | ||||||||||||||||||||||||
1978 | date using both mouse and keyboard. The currently selected date | - | ||||||||||||||||||||||||
1979 | can be retrieved using the selectedDate() function. It is | - | ||||||||||||||||||||||||
1980 | possible to constrain the user selection to a given date range by | - | ||||||||||||||||||||||||
1981 | setting the minimumDate and maximumDate properties. | - | ||||||||||||||||||||||||
1982 | Alternatively, both properties can be set in one go using the | - | ||||||||||||||||||||||||
1983 | setDateRange() convenience slot. Set the \l selectionMode | - | ||||||||||||||||||||||||
1984 | property to NoSelection to prohibit the user from selecting at | - | ||||||||||||||||||||||||
1985 | all. Note that a date also can be selected programmatically using | - | ||||||||||||||||||||||||
1986 | the setSelectedDate() slot. | - | ||||||||||||||||||||||||
1987 | - | |||||||||||||||||||||||||
1988 | The currently displayed month and year can be retrieved using the | - | ||||||||||||||||||||||||
1989 | monthShown() and yearShown() functions, respectively. | - | ||||||||||||||||||||||||
1990 | - | |||||||||||||||||||||||||
1991 | A newly created calendar widget uses abbreviated day names, and | - | ||||||||||||||||||||||||
1992 | both Saturdays and Sundays are marked in red. The calendar grid is | - | ||||||||||||||||||||||||
1993 | not visible. The week numbers are displayed, and the first column | - | ||||||||||||||||||||||||
1994 | day is the first day of the week for the calendar's locale. | - | ||||||||||||||||||||||||
1995 | - | |||||||||||||||||||||||||
1996 | The notation of the days can be altered to a single letter | - | ||||||||||||||||||||||||
1997 | abbreviations ("M" for "Monday") by setting the | - | ||||||||||||||||||||||||
1998 | horizontalHeaderFormat property to | - | ||||||||||||||||||||||||
1999 | QCalendarWidget::SingleLetterDayNames. Setting the same property | - | ||||||||||||||||||||||||
2000 | to QCalendarWidget::LongDayNames makes the header display the | - | ||||||||||||||||||||||||
2001 | complete day names. The week numbers can be removed by setting | - | ||||||||||||||||||||||||
2002 | the verticalHeaderFormat property to | - | ||||||||||||||||||||||||
2003 | QCalendarWidget::NoVerticalHeader. The calendar grid can be | - | ||||||||||||||||||||||||
2004 | turned on by setting the gridVisible property to true using the | - | ||||||||||||||||||||||||
2005 | setGridVisible() function: | - | ||||||||||||||||||||||||
2006 | - | |||||||||||||||||||||||||
2007 | \table | - | ||||||||||||||||||||||||
2008 | \row \li | - | ||||||||||||||||||||||||
2009 | \image qcalendarwidget-grid.png | - | ||||||||||||||||||||||||
2010 | \row \li | - | ||||||||||||||||||||||||
2011 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 0 | - | ||||||||||||||||||||||||
2012 | \endtable | - | ||||||||||||||||||||||||
2013 | - | |||||||||||||||||||||||||
2014 | Finally, the day in the first column can be altered using the | - | ||||||||||||||||||||||||
2015 | setFirstDayOfWeek() function. | - | ||||||||||||||||||||||||
2016 | - | |||||||||||||||||||||||||
2017 | The QCalendarWidget class also provides three signals, | - | ||||||||||||||||||||||||
2018 | selectionChanged(), activated() and currentPageChanged() making it | - | ||||||||||||||||||||||||
2019 | possible to respond to user interaction. | - | ||||||||||||||||||||||||
2020 | - | |||||||||||||||||||||||||
2021 | The rendering of the headers, weekdays or single days can be | - | ||||||||||||||||||||||||
2022 | largely customized by setting QTextCharFormat's for some special | - | ||||||||||||||||||||||||
2023 | weekday, a special date or for the rendering of the headers. | - | ||||||||||||||||||||||||
2024 | - | |||||||||||||||||||||||||
2025 | Only a subset of the properties in QTextCharFormat are used by the | - | ||||||||||||||||||||||||
2026 | calendar widget. Currently, the foreground, background and font | - | ||||||||||||||||||||||||
2027 | properties are used to determine the rendering of individual cells | - | ||||||||||||||||||||||||
2028 | in the widget. | - | ||||||||||||||||||||||||
2029 | - | |||||||||||||||||||||||||
2030 | \sa QDate, QDateEdit, QTextCharFormat | - | ||||||||||||||||||||||||
2031 | */ | - | ||||||||||||||||||||||||
2032 | - | |||||||||||||||||||||||||
2033 | /*! | - | ||||||||||||||||||||||||
2034 | \enum QCalendarWidget::SelectionMode | - | ||||||||||||||||||||||||
2035 | - | |||||||||||||||||||||||||
2036 | This enum describes the types of selection offered to the user for | - | ||||||||||||||||||||||||
2037 | selecting dates in the calendar. | - | ||||||||||||||||||||||||
2038 | - | |||||||||||||||||||||||||
2039 | \value NoSelection Dates cannot be selected. | - | ||||||||||||||||||||||||
2040 | \value SingleSelection Single dates can be selected. | - | ||||||||||||||||||||||||
2041 | - | |||||||||||||||||||||||||
2042 | \sa selectionMode | - | ||||||||||||||||||||||||
2043 | */ | - | ||||||||||||||||||||||||
2044 | - | |||||||||||||||||||||||||
2045 | /*! | - | ||||||||||||||||||||||||
2046 | Constructs a calendar widget with the given \a parent. | - | ||||||||||||||||||||||||
2047 | - | |||||||||||||||||||||||||
2048 | The widget is initialized with the current month and year, and the | - | ||||||||||||||||||||||||
2049 | currently selected date is today. | - | ||||||||||||||||||||||||
2050 | - | |||||||||||||||||||||||||
2051 | \sa setCurrentPage() | - | ||||||||||||||||||||||||
2052 | */ | - | ||||||||||||||||||||||||
2053 | QCalendarWidget::QCalendarWidget(QWidget *parent) | - | ||||||||||||||||||||||||
2054 | : QWidget(*new QCalendarWidgetPrivate, parent, 0) | - | ||||||||||||||||||||||||
2055 | { | - | ||||||||||||||||||||||||
2056 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2057 | - | |||||||||||||||||||||||||
2058 | setAutoFillBackground(true); | - | ||||||||||||||||||||||||
2059 | setBackgroundRole(QPalette::Window); | - | ||||||||||||||||||||||||
2060 | - | |||||||||||||||||||||||||
2061 | QVBoxLayout *layoutV = new QVBoxLayout(this); | - | ||||||||||||||||||||||||
2062 | layoutV->setMargin(0); | - | ||||||||||||||||||||||||
2063 | d->m_model = new QCalendarModel(this); | - | ||||||||||||||||||||||||
2064 | QTextCharFormat fmt; | - | ||||||||||||||||||||||||
2065 | fmt.setForeground(QBrush(Qt::red)); | - | ||||||||||||||||||||||||
2066 | d->m_model->m_dayFormats.insert(Qt::Saturday, fmt); | - | ||||||||||||||||||||||||
2067 | d->m_model->m_dayFormats.insert(Qt::Sunday, fmt); | - | ||||||||||||||||||||||||
2068 | d->m_view = new QCalendarView(this); | - | ||||||||||||||||||||||||
2069 | d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview")); | - | ||||||||||||||||||||||||
2070 | d->m_view->setModel(d->m_model); | - | ||||||||||||||||||||||||
2071 | d->m_model->setView(d->m_view); | - | ||||||||||||||||||||||||
2072 | d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems); | - | ||||||||||||||||||||||||
2073 | d->m_view->setSelectionMode(QAbstractItemView::SingleSelection); | - | ||||||||||||||||||||||||
2074 | d->m_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | - | ||||||||||||||||||||||||
2075 | d->m_view->horizontalHeader()->setSectionsClickable(false); | - | ||||||||||||||||||||||||
2076 | d->m_view->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); | - | ||||||||||||||||||||||||
2077 | d->m_view->verticalHeader()->setSectionsClickable(false); | - | ||||||||||||||||||||||||
2078 | d->m_selection = d->m_view->selectionModel(); | - | ||||||||||||||||||||||||
2079 | d->createNavigationBar(this); | - | ||||||||||||||||||||||||
2080 | d->m_view->setFrameStyle(QFrame::NoFrame); | - | ||||||||||||||||||||||||
2081 | d->m_delegate = new QCalendarDelegate(d, this); | - | ||||||||||||||||||||||||
2082 | d->m_view->setItemDelegate(d->m_delegate); | - | ||||||||||||||||||||||||
2083 | d->update(); | - | ||||||||||||||||||||||||
2084 | d->updateNavigationBar(); | - | ||||||||||||||||||||||||
2085 | setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||||||||
2086 | setFocusProxy(d->m_view); | - | ||||||||||||||||||||||||
2087 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | - | ||||||||||||||||||||||||
2088 | - | |||||||||||||||||||||||||
2089 | connect(d->m_view, SIGNAL(showDate(QDate)), | - | ||||||||||||||||||||||||
2090 | this, SLOT(_q_slotShowDate(QDate))); | - | ||||||||||||||||||||||||
2091 | connect(d->m_view, SIGNAL(changeDate(QDate,bool)), | - | ||||||||||||||||||||||||
2092 | this, SLOT(_q_slotChangeDate(QDate,bool))); | - | ||||||||||||||||||||||||
2093 | connect(d->m_view, SIGNAL(clicked(QDate)), | - | ||||||||||||||||||||||||
2094 | this, SIGNAL(clicked(QDate))); | - | ||||||||||||||||||||||||
2095 | connect(d->m_view, SIGNAL(editingFinished()), | - | ||||||||||||||||||||||||
2096 | this, SLOT(_q_editingFinished())); | - | ||||||||||||||||||||||||
2097 | - | |||||||||||||||||||||||||
2098 | connect(d->prevMonth, SIGNAL(clicked(bool)), | - | ||||||||||||||||||||||||
2099 | this, SLOT(_q_prevMonthClicked())); | - | ||||||||||||||||||||||||
2100 | connect(d->nextMonth, SIGNAL(clicked(bool)), | - | ||||||||||||||||||||||||
2101 | this, SLOT(_q_nextMonthClicked())); | - | ||||||||||||||||||||||||
2102 | connect(d->yearButton, SIGNAL(clicked(bool)), | - | ||||||||||||||||||||||||
2103 | this, SLOT(_q_yearClicked())); | - | ||||||||||||||||||||||||
2104 | connect(d->monthMenu, SIGNAL(triggered(QAction*)), | - | ||||||||||||||||||||||||
2105 | this, SLOT(_q_monthChanged(QAction*))); | - | ||||||||||||||||||||||||
2106 | connect(d->yearEdit, SIGNAL(editingFinished()), | - | ||||||||||||||||||||||||
2107 | this, SLOT(_q_yearEditingFinished())); | - | ||||||||||||||||||||||||
2108 | - | |||||||||||||||||||||||||
2109 | layoutV->setMargin(0); | - | ||||||||||||||||||||||||
2110 | layoutV->setSpacing(0); | - | ||||||||||||||||||||||||
2111 | layoutV->addWidget(d->navBarBackground); | - | ||||||||||||||||||||||||
2112 | layoutV->addWidget(d->m_view); | - | ||||||||||||||||||||||||
2113 | - | |||||||||||||||||||||||||
2114 | d->m_navigator = new QCalendarTextNavigator(this); | - | ||||||||||||||||||||||||
2115 | setDateEditEnabled(true); | - | ||||||||||||||||||||||||
2116 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2117 | - | |||||||||||||||||||||||||
2118 | /*! | - | ||||||||||||||||||||||||
2119 | Destroys the calendar widget. | - | ||||||||||||||||||||||||
2120 | */ | - | ||||||||||||||||||||||||
2121 | QCalendarWidget::~QCalendarWidget() | - | ||||||||||||||||||||||||
2122 | { | - | ||||||||||||||||||||||||
2123 | } | - | ||||||||||||||||||||||||
2124 | - | |||||||||||||||||||||||||
2125 | /*! | - | ||||||||||||||||||||||||
2126 | \reimp | - | ||||||||||||||||||||||||
2127 | */ | - | ||||||||||||||||||||||||
2128 | QSize QCalendarWidget::sizeHint() const | - | ||||||||||||||||||||||||
2129 | { | - | ||||||||||||||||||||||||
2130 | return minimumSizeHint(); never executed: return minimumSizeHint(); | 0 | ||||||||||||||||||||||||
2131 | } | - | ||||||||||||||||||||||||
2132 | - | |||||||||||||||||||||||||
2133 | /*! | - | ||||||||||||||||||||||||
2134 | \reimp | - | ||||||||||||||||||||||||
2135 | */ | - | ||||||||||||||||||||||||
2136 | QSize QCalendarWidget::minimumSizeHint() const | - | ||||||||||||||||||||||||
2137 | { | - | ||||||||||||||||||||||||
2138 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2139 | if (d->cachedSizeHint.isValid())
| 0 | ||||||||||||||||||||||||
2140 | return d->cachedSizeHint; never executed: return d->cachedSizeHint; | 0 | ||||||||||||||||||||||||
2141 | - | |||||||||||||||||||||||||
2142 | ensurePolished(); | - | ||||||||||||||||||||||||
2143 | - | |||||||||||||||||||||||||
2144 | int w = 0; | - | ||||||||||||||||||||||||
2145 | int h = 0; | - | ||||||||||||||||||||||||
2146 | - | |||||||||||||||||||||||||
2147 | int end = 53; | - | ||||||||||||||||||||||||
2148 | int rows = 7; | - | ||||||||||||||||||||||||
2149 | int cols = 8; | - | ||||||||||||||||||||||||
2150 | - | |||||||||||||||||||||||||
2151 | const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2; | - | ||||||||||||||||||||||||
2152 | - | |||||||||||||||||||||||||
2153 | if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
| 0 | ||||||||||||||||||||||||
2154 | rows = 6; | - | ||||||||||||||||||||||||
2155 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2156 | for (int i = 1; i <= 7; i++) {
| 0 | ||||||||||||||||||||||||
2157 | QFontMetrics fm(d->m_model->formatForCell(0, i).font()); | - | ||||||||||||||||||||||||
2158 | w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH); | - | ||||||||||||||||||||||||
2159 | h = qMax(h, fm.height()); | - | ||||||||||||||||||||||||
2160 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2161 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2162 | - | |||||||||||||||||||||||||
2163 | if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) {
| 0 | ||||||||||||||||||||||||
2164 | cols = 7; | - | ||||||||||||||||||||||||
2165 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2166 | for (int i = 1; i <= 6; i++) {
| 0 | ||||||||||||||||||||||||
2167 | QFontMetrics fm(d->m_model->formatForCell(i, 0).font()); | - | ||||||||||||||||||||||||
2168 | for (int j = 1; j < end; j++)
| 0 | ||||||||||||||||||||||||
2169 | w = qMax(w, fm.width(QString::number(j)) + marginH); never executed: w = qMax(w, fm.width(QString::number(j)) + marginH); | 0 | ||||||||||||||||||||||||
2170 | h = qMax(h, fm.height()); | - | ||||||||||||||||||||||||
2171 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2173 | - | |||||||||||||||||||||||||
2174 | QFontMetrics fm(d->m_model->formatForCell(1, 1).font()); | - | ||||||||||||||||||||||||
2175 | for (int i = 1; i <= end; i++) {
| 0 | ||||||||||||||||||||||||
2176 | w = qMax(w, fm.width(QString::number(i)) + marginH); | - | ||||||||||||||||||||||||
2177 | h = qMax(h, fm.height()); | - | ||||||||||||||||||||||||
2178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2179 | - | |||||||||||||||||||||||||
2180 | if (d->m_view->showGrid()) {
| 0 | ||||||||||||||||||||||||
2181 | // hardcoded in tableview | - | ||||||||||||||||||||||||
2182 | w += 1; | - | ||||||||||||||||||||||||
2183 | h += 1; | - | ||||||||||||||||||||||||
2184 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2185 | - | |||||||||||||||||||||||||
2186 | w += 1; // default column span | - | ||||||||||||||||||||||||
2187 | - | |||||||||||||||||||||||||
2188 | h = qMax(h, d->m_view->verticalHeader()->minimumSectionSize()); | - | ||||||||||||||||||||||||
2189 | w = qMax(w, d->m_view->horizontalHeader()->minimumSectionSize()); | - | ||||||||||||||||||||||||
2190 | - | |||||||||||||||||||||||||
2191 | //add the size of the header. | - | ||||||||||||||||||||||||
2192 | QSize headerSize(0, 0); | - | ||||||||||||||||||||||||
2193 | if (d->navBarVisible) {
| 0 | ||||||||||||||||||||||||
2194 | int headerH = d->navBarBackground->sizeHint().height(); | - | ||||||||||||||||||||||||
2195 | int headerW = 0; | - | ||||||||||||||||||||||||
2196 | - | |||||||||||||||||||||||||
2197 | headerW += d->prevMonth->sizeHint().width(); | - | ||||||||||||||||||||||||
2198 | headerW += d->nextMonth->sizeHint().width(); | - | ||||||||||||||||||||||||
2199 | - | |||||||||||||||||||||||||
2200 | QFontMetrics fm = d->monthButton->fontMetrics(); | - | ||||||||||||||||||||||||
2201 | int monthW = 0; | - | ||||||||||||||||||||||||
2202 | for (int i = 1; i < 12; i++) {
| 0 | ||||||||||||||||||||||||
2203 | QString monthName = locale().standaloneMonthName(i, QLocale::LongFormat); | - | ||||||||||||||||||||||||
2204 | monthW = qMax(monthW, fm.boundingRect(monthName).width()); | - | ||||||||||||||||||||||||
2205 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2206 | const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width(); | - | ||||||||||||||||||||||||
2207 | headerW += monthW + buttonDecoMargin; | - | ||||||||||||||||||||||||
2208 | - | |||||||||||||||||||||||||
2209 | fm = d->yearButton->fontMetrics(); | - | ||||||||||||||||||||||||
2210 | headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin; | - | ||||||||||||||||||||||||
2211 | - | |||||||||||||||||||||||||
2212 | headerSize = QSize(headerW, headerH); | - | ||||||||||||||||||||||||
2213 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2214 | w *= cols; | - | ||||||||||||||||||||||||
2215 | w = qMax(headerSize.width(), w); | - | ||||||||||||||||||||||||
2216 | h = (h * rows) + headerSize.height(); | - | ||||||||||||||||||||||||
2217 | QMargins cm = contentsMargins(); | - | ||||||||||||||||||||||||
2218 | w += cm.left() + cm.right(); | - | ||||||||||||||||||||||||
2219 | h += cm.top() + cm.bottom(); | - | ||||||||||||||||||||||||
2220 | d->cachedSizeHint = QSize(w, h); | - | ||||||||||||||||||||||||
2221 | return d->cachedSizeHint; never executed: return d->cachedSizeHint; | 0 | ||||||||||||||||||||||||
2222 | } | - | ||||||||||||||||||||||||
2223 | - | |||||||||||||||||||||||||
2224 | /*! | - | ||||||||||||||||||||||||
2225 | Paints the cell specified by the given \a date, using the given \a painter and \a rect. | - | ||||||||||||||||||||||||
2226 | */ | - | ||||||||||||||||||||||||
2227 | - | |||||||||||||||||||||||||
2228 | void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | - | ||||||||||||||||||||||||
2229 | { | - | ||||||||||||||||||||||||
2230 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2231 | d->m_delegate->paintCell(painter, rect, date); | - | ||||||||||||||||||||||||
2232 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2233 | - | |||||||||||||||||||||||||
2234 | /*! | - | ||||||||||||||||||||||||
2235 | \property QCalendarWidget::selectedDate | - | ||||||||||||||||||||||||
2236 | \brief the currently selected date. | - | ||||||||||||||||||||||||
2237 | - | |||||||||||||||||||||||||
2238 | The selected date must be within the date range specified by the | - | ||||||||||||||||||||||||
2239 | minimumDate and maximumDate properties. By default, the selected | - | ||||||||||||||||||||||||
2240 | date is the current date. | - | ||||||||||||||||||||||||
2241 | - | |||||||||||||||||||||||||
2242 | \sa setDateRange() | - | ||||||||||||||||||||||||
2243 | */ | - | ||||||||||||||||||||||||
2244 | - | |||||||||||||||||||||||||
2245 | QDate QCalendarWidget::selectedDate() const | - | ||||||||||||||||||||||||
2246 | { | - | ||||||||||||||||||||||||
2247 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2248 | return d->m_model->m_date; never executed: return d->m_model->m_date; | 0 | ||||||||||||||||||||||||
2249 | } | - | ||||||||||||||||||||||||
2250 | - | |||||||||||||||||||||||||
2251 | void QCalendarWidget::setSelectedDate(const QDate &date) | - | ||||||||||||||||||||||||
2252 | { | - | ||||||||||||||||||||||||
2253 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2254 | if (d->m_model->m_date == date && date == d->getCurrentDate())
| 0 | ||||||||||||||||||||||||
2255 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2256 | - | |||||||||||||||||||||||||
2257 | if (!date.isValid())
| 0 | ||||||||||||||||||||||||
2258 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2259 | - | |||||||||||||||||||||||||
2260 | d->m_model->setDate(date); | - | ||||||||||||||||||||||||
2261 | d->update(); | - | ||||||||||||||||||||||||
2262 | QDate newDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2263 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||||||||||||||
2264 | emit selectionChanged(); | - | ||||||||||||||||||||||||
2265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2266 | - | |||||||||||||||||||||||||
2267 | /*! | - | ||||||||||||||||||||||||
2268 | Returns the year of the currently displayed month. Months are | - | ||||||||||||||||||||||||
2269 | numbered from 1 to 12. | - | ||||||||||||||||||||||||
2270 | - | |||||||||||||||||||||||||
2271 | \sa monthShown(), setCurrentPage() | - | ||||||||||||||||||||||||
2272 | */ | - | ||||||||||||||||||||||||
2273 | - | |||||||||||||||||||||||||
2274 | int QCalendarWidget::yearShown() const | - | ||||||||||||||||||||||||
2275 | { | - | ||||||||||||||||||||||||
2276 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2277 | return d->m_model->m_shownYear; never executed: return d->m_model->m_shownYear; | 0 | ||||||||||||||||||||||||
2278 | } | - | ||||||||||||||||||||||||
2279 | - | |||||||||||||||||||||||||
2280 | /*! | - | ||||||||||||||||||||||||
2281 | Returns the currently displayed month. Months are numbered from 1 to | - | ||||||||||||||||||||||||
2282 | 12. | - | ||||||||||||||||||||||||
2283 | - | |||||||||||||||||||||||||
2284 | \sa yearShown(), setCurrentPage() | - | ||||||||||||||||||||||||
2285 | */ | - | ||||||||||||||||||||||||
2286 | - | |||||||||||||||||||||||||
2287 | int QCalendarWidget::monthShown() const | - | ||||||||||||||||||||||||
2288 | { | - | ||||||||||||||||||||||||
2289 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2290 | return d->m_model->m_shownMonth; never executed: return d->m_model->m_shownMonth; | 0 | ||||||||||||||||||||||||
2291 | } | - | ||||||||||||||||||||||||
2292 | - | |||||||||||||||||||||||||
2293 | /*! | - | ||||||||||||||||||||||||
2294 | Displays the given \a month of the given \a year without changing | - | ||||||||||||||||||||||||
2295 | the selected date. Use the setSelectedDate() function to alter the | - | ||||||||||||||||||||||||
2296 | selected date. | - | ||||||||||||||||||||||||
2297 | - | |||||||||||||||||||||||||
2298 | The currently displayed month and year can be retrieved using the | - | ||||||||||||||||||||||||
2299 | monthShown() and yearShown() functions respectively. | - | ||||||||||||||||||||||||
2300 | - | |||||||||||||||||||||||||
2301 | \sa yearShown(), monthShown(), showPreviousMonth(), showNextMonth(), | - | ||||||||||||||||||||||||
2302 | showPreviousYear(), showNextYear() | - | ||||||||||||||||||||||||
2303 | */ | - | ||||||||||||||||||||||||
2304 | - | |||||||||||||||||||||||||
2305 | void QCalendarWidget::setCurrentPage(int year, int month) | - | ||||||||||||||||||||||||
2306 | { | - | ||||||||||||||||||||||||
2307 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2308 | QDate currentDate = d->getCurrentDate(); | - | ||||||||||||||||||||||||
2309 | int day = currentDate.day(); | - | ||||||||||||||||||||||||
2310 | int daysInMonths = QDate(year, month, 1).daysInMonth(); | - | ||||||||||||||||||||||||
2311 | if (day > daysInMonths)
| 0 | ||||||||||||||||||||||||
2312 | day = daysInMonths; never executed: day = daysInMonths; | 0 | ||||||||||||||||||||||||
2313 | - | |||||||||||||||||||||||||
2314 | d->showMonth(year, month); | - | ||||||||||||||||||||||||
2315 | - | |||||||||||||||||||||||||
2316 | QDate newDate(year, month, day); | - | ||||||||||||||||||||||||
2317 | int row = -1, col = -1; | - | ||||||||||||||||||||||||
2318 | d->m_model->cellForDate(newDate, &row, &col); | - | ||||||||||||||||||||||||
2319 | if (row != -1 && col != -1) {
| 0 | ||||||||||||||||||||||||
2320 | d->m_view->selectionModel()->setCurrentIndex(d->m_model->index(row, col), | - | ||||||||||||||||||||||||
2321 | QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
2322 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2323 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2324 | - | |||||||||||||||||||||||||
2325 | /*! | - | ||||||||||||||||||||||||
2326 | Shows the next month relative to the currently displayed | - | ||||||||||||||||||||||||
2327 | month. Note that the selected date is not changed. | - | ||||||||||||||||||||||||
2328 | - | |||||||||||||||||||||||||
2329 | \sa showPreviousMonth(), setCurrentPage(), setSelectedDate() | - | ||||||||||||||||||||||||
2330 | */ | - | ||||||||||||||||||||||||
2331 | - | |||||||||||||||||||||||||
2332 | void QCalendarWidget::showNextMonth() | - | ||||||||||||||||||||||||
2333 | { | - | ||||||||||||||||||||||||
2334 | int year = yearShown(); | - | ||||||||||||||||||||||||
2335 | int month = monthShown(); | - | ||||||||||||||||||||||||
2336 | if (month == 12) {
| 0 | ||||||||||||||||||||||||
2337 | ++year; | - | ||||||||||||||||||||||||
2338 | month = 1; | - | ||||||||||||||||||||||||
2339 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2340 | ++month; | - | ||||||||||||||||||||||||
2341 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2342 | setCurrentPage(year, month); | - | ||||||||||||||||||||||||
2343 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2344 | - | |||||||||||||||||||||||||
2345 | /*! | - | ||||||||||||||||||||||||
2346 | Shows the previous month relative to the currently displayed | - | ||||||||||||||||||||||||
2347 | month. Note that the selected date is not changed. | - | ||||||||||||||||||||||||
2348 | - | |||||||||||||||||||||||||
2349 | \sa showNextMonth(), setCurrentPage(), setSelectedDate() | - | ||||||||||||||||||||||||
2350 | */ | - | ||||||||||||||||||||||||
2351 | - | |||||||||||||||||||||||||
2352 | void QCalendarWidget::showPreviousMonth() | - | ||||||||||||||||||||||||
2353 | { | - | ||||||||||||||||||||||||
2354 | int year = yearShown(); | - | ||||||||||||||||||||||||
2355 | int month = monthShown(); | - | ||||||||||||||||||||||||
2356 | if (month == 1) {
| 0 | ||||||||||||||||||||||||
2357 | --year; | - | ||||||||||||||||||||||||
2358 | month = 12; | - | ||||||||||||||||||||||||
2359 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2360 | --month; | - | ||||||||||||||||||||||||
2361 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2362 | setCurrentPage(year, month); | - | ||||||||||||||||||||||||
2363 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2364 | - | |||||||||||||||||||||||||
2365 | /*! | - | ||||||||||||||||||||||||
2366 | Shows the currently displayed month in the \e next year relative | - | ||||||||||||||||||||||||
2367 | to the currently displayed year. Note that the selected date is | - | ||||||||||||||||||||||||
2368 | not changed. | - | ||||||||||||||||||||||||
2369 | - | |||||||||||||||||||||||||
2370 | \sa showPreviousYear(), setCurrentPage(), setSelectedDate() | - | ||||||||||||||||||||||||
2371 | */ | - | ||||||||||||||||||||||||
2372 | - | |||||||||||||||||||||||||
2373 | void QCalendarWidget::showNextYear() | - | ||||||||||||||||||||||||
2374 | { | - | ||||||||||||||||||||||||
2375 | int year = yearShown(); | - | ||||||||||||||||||||||||
2376 | int month = monthShown(); | - | ||||||||||||||||||||||||
2377 | ++year; | - | ||||||||||||||||||||||||
2378 | setCurrentPage(year, month); | - | ||||||||||||||||||||||||
2379 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2380 | - | |||||||||||||||||||||||||
2381 | /*! | - | ||||||||||||||||||||||||
2382 | Shows the currently displayed month in the \e previous year | - | ||||||||||||||||||||||||
2383 | relative to the currently displayed year. Note that the selected | - | ||||||||||||||||||||||||
2384 | date is not changed. | - | ||||||||||||||||||||||||
2385 | - | |||||||||||||||||||||||||
2386 | \sa showNextYear(), setCurrentPage(), setSelectedDate() | - | ||||||||||||||||||||||||
2387 | */ | - | ||||||||||||||||||||||||
2388 | - | |||||||||||||||||||||||||
2389 | void QCalendarWidget::showPreviousYear() | - | ||||||||||||||||||||||||
2390 | { | - | ||||||||||||||||||||||||
2391 | int year = yearShown(); | - | ||||||||||||||||||||||||
2392 | int month = monthShown(); | - | ||||||||||||||||||||||||
2393 | --year; | - | ||||||||||||||||||||||||
2394 | setCurrentPage(year, month); | - | ||||||||||||||||||||||||
2395 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2396 | - | |||||||||||||||||||||||||
2397 | /*! | - | ||||||||||||||||||||||||
2398 | Shows the month of the selected date. | - | ||||||||||||||||||||||||
2399 | - | |||||||||||||||||||||||||
2400 | \sa selectedDate(), setCurrentPage() | - | ||||||||||||||||||||||||
2401 | */ | - | ||||||||||||||||||||||||
2402 | void QCalendarWidget::showSelectedDate() | - | ||||||||||||||||||||||||
2403 | { | - | ||||||||||||||||||||||||
2404 | QDate currentDate = selectedDate(); | - | ||||||||||||||||||||||||
2405 | setCurrentPage(currentDate.year(), currentDate.month()); | - | ||||||||||||||||||||||||
2406 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2407 | - | |||||||||||||||||||||||||
2408 | /*! | - | ||||||||||||||||||||||||
2409 | Shows the month of the today's date. | - | ||||||||||||||||||||||||
2410 | - | |||||||||||||||||||||||||
2411 | \sa selectedDate(), setCurrentPage() | - | ||||||||||||||||||||||||
2412 | */ | - | ||||||||||||||||||||||||
2413 | void QCalendarWidget::showToday() | - | ||||||||||||||||||||||||
2414 | { | - | ||||||||||||||||||||||||
2415 | QDate currentDate = QDate::currentDate(); | - | ||||||||||||||||||||||||
2416 | setCurrentPage(currentDate.year(), currentDate.month()); | - | ||||||||||||||||||||||||
2417 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2418 | - | |||||||||||||||||||||||||
2419 | /*! | - | ||||||||||||||||||||||||
2420 | \property QCalendarWidget::minimumDate | - | ||||||||||||||||||||||||
2421 | \brief the minimum date of the currently specified date range. | - | ||||||||||||||||||||||||
2422 | - | |||||||||||||||||||||||||
2423 | The user will not be able to select a date that is before the | - | ||||||||||||||||||||||||
2424 | currently set minimum date. | - | ||||||||||||||||||||||||
2425 | - | |||||||||||||||||||||||||
2426 | \table | - | ||||||||||||||||||||||||
2427 | \row | - | ||||||||||||||||||||||||
2428 | \li \image qcalendarwidget-minimum.png | - | ||||||||||||||||||||||||
2429 | \row | - | ||||||||||||||||||||||||
2430 | \li | - | ||||||||||||||||||||||||
2431 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 1 | - | ||||||||||||||||||||||||
2432 | \endtable | - | ||||||||||||||||||||||||
2433 | - | |||||||||||||||||||||||||
2434 | By default, the minimum date is the earliest date that the QDate | - | ||||||||||||||||||||||||
2435 | class can handle. | - | ||||||||||||||||||||||||
2436 | - | |||||||||||||||||||||||||
2437 | When setting a minimum date, the maximumDate and selectedDate | - | ||||||||||||||||||||||||
2438 | properties are adjusted if the selection range becomes invalid. If | - | ||||||||||||||||||||||||
2439 | the provided date is not a valid QDate object, the | - | ||||||||||||||||||||||||
2440 | setMinimumDate() function does nothing. | - | ||||||||||||||||||||||||
2441 | - | |||||||||||||||||||||||||
2442 | \sa setDateRange() | - | ||||||||||||||||||||||||
2443 | */ | - | ||||||||||||||||||||||||
2444 | - | |||||||||||||||||||||||||
2445 | QDate QCalendarWidget::minimumDate() const | - | ||||||||||||||||||||||||
2446 | { | - | ||||||||||||||||||||||||
2447 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2448 | return d->m_model->m_minimumDate; never executed: return d->m_model->m_minimumDate; | 0 | ||||||||||||||||||||||||
2449 | } | - | ||||||||||||||||||||||||
2450 | - | |||||||||||||||||||||||||
2451 | void QCalendarWidget::setMinimumDate(const QDate &date) | - | ||||||||||||||||||||||||
2452 | { | - | ||||||||||||||||||||||||
2453 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2454 | if (!date.isValid() || d->m_model->m_minimumDate == date)
| 0 | ||||||||||||||||||||||||
2455 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2456 | - | |||||||||||||||||||||||||
2457 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2458 | d->m_model->setMinimumDate(date); | - | ||||||||||||||||||||||||
2459 | d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); | - | ||||||||||||||||||||||||
2460 | d->updateMonthMenu(); | - | ||||||||||||||||||||||||
2461 | QDate newDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2462 | if (oldDate != newDate) {
| 0 | ||||||||||||||||||||||||
2463 | d->update(); | - | ||||||||||||||||||||||||
2464 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||||||||||||||
2465 | d->m_navigator->setDate(newDate); | - | ||||||||||||||||||||||||
2466 | emit selectionChanged(); | - | ||||||||||||||||||||||||
2467 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2468 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2469 | - | |||||||||||||||||||||||||
2470 | /*! | - | ||||||||||||||||||||||||
2471 | \property QCalendarWidget::maximumDate | - | ||||||||||||||||||||||||
2472 | \brief the maximum date of the currently specified date range. | - | ||||||||||||||||||||||||
2473 | - | |||||||||||||||||||||||||
2474 | The user will not be able to select a date which is after the | - | ||||||||||||||||||||||||
2475 | currently set maximum date. | - | ||||||||||||||||||||||||
2476 | - | |||||||||||||||||||||||||
2477 | \table | - | ||||||||||||||||||||||||
2478 | \row | - | ||||||||||||||||||||||||
2479 | \li \image qcalendarwidget-maximum.png | - | ||||||||||||||||||||||||
2480 | \row | - | ||||||||||||||||||||||||
2481 | \li | - | ||||||||||||||||||||||||
2482 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 2 | - | ||||||||||||||||||||||||
2483 | \endtable | - | ||||||||||||||||||||||||
2484 | - | |||||||||||||||||||||||||
2485 | By default, the maximum date is the last day the QDate class can | - | ||||||||||||||||||||||||
2486 | handle. | - | ||||||||||||||||||||||||
2487 | - | |||||||||||||||||||||||||
2488 | When setting a maximum date, the minimumDate and selectedDate | - | ||||||||||||||||||||||||
2489 | properties are adjusted if the selection range becomes invalid. If | - | ||||||||||||||||||||||||
2490 | the provided date is not a valid QDate object, the | - | ||||||||||||||||||||||||
2491 | setMaximumDate() function does nothing. | - | ||||||||||||||||||||||||
2492 | - | |||||||||||||||||||||||||
2493 | \sa setDateRange() | - | ||||||||||||||||||||||||
2494 | */ | - | ||||||||||||||||||||||||
2495 | - | |||||||||||||||||||||||||
2496 | QDate QCalendarWidget::maximumDate() const | - | ||||||||||||||||||||||||
2497 | { | - | ||||||||||||||||||||||||
2498 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2499 | return d->m_model->m_maximumDate; never executed: return d->m_model->m_maximumDate; | 0 | ||||||||||||||||||||||||
2500 | } | - | ||||||||||||||||||||||||
2501 | - | |||||||||||||||||||||||||
2502 | void QCalendarWidget::setMaximumDate(const QDate &date) | - | ||||||||||||||||||||||||
2503 | { | - | ||||||||||||||||||||||||
2504 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2505 | if (!date.isValid() || d->m_model->m_maximumDate == date)
| 0 | ||||||||||||||||||||||||
2506 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2507 | - | |||||||||||||||||||||||||
2508 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2509 | d->m_model->setMaximumDate(date); | - | ||||||||||||||||||||||||
2510 | d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); | - | ||||||||||||||||||||||||
2511 | d->updateMonthMenu(); | - | ||||||||||||||||||||||||
2512 | QDate newDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2513 | if (oldDate != newDate) {
| 0 | ||||||||||||||||||||||||
2514 | d->update(); | - | ||||||||||||||||||||||||
2515 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||||||||||||||
2516 | d->m_navigator->setDate(newDate); | - | ||||||||||||||||||||||||
2517 | emit selectionChanged(); | - | ||||||||||||||||||||||||
2518 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2519 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2520 | - | |||||||||||||||||||||||||
2521 | /*! | - | ||||||||||||||||||||||||
2522 | Defines a date range by setting the minimumDate and maximumDate | - | ||||||||||||||||||||||||
2523 | properties. | - | ||||||||||||||||||||||||
2524 | - | |||||||||||||||||||||||||
2525 | The date range restricts the user selection, i.e. the user can | - | ||||||||||||||||||||||||
2526 | only select dates within the specified date range. Note that | - | ||||||||||||||||||||||||
2527 | - | |||||||||||||||||||||||||
2528 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 3 | - | ||||||||||||||||||||||||
2529 | - | |||||||||||||||||||||||||
2530 | is analogous to | - | ||||||||||||||||||||||||
2531 | - | |||||||||||||||||||||||||
2532 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 4 | - | ||||||||||||||||||||||||
2533 | - | |||||||||||||||||||||||||
2534 | If either the \a min or \a max parameters are not valid QDate | - | ||||||||||||||||||||||||
2535 | objects, this function does nothing. | - | ||||||||||||||||||||||||
2536 | - | |||||||||||||||||||||||||
2537 | \sa setMinimumDate(), setMaximumDate() | - | ||||||||||||||||||||||||
2538 | */ | - | ||||||||||||||||||||||||
2539 | - | |||||||||||||||||||||||||
2540 | void QCalendarWidget::setDateRange(const QDate &min, const QDate &max) | - | ||||||||||||||||||||||||
2541 | { | - | ||||||||||||||||||||||||
2542 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2543 | if (d->m_model->m_minimumDate == min && d->m_model->m_maximumDate == max)
| 0 | ||||||||||||||||||||||||
2544 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2545 | if (!min.isValid() || !max.isValid())
| 0 | ||||||||||||||||||||||||
2546 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2547 | - | |||||||||||||||||||||||||
2548 | QDate oldDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2549 | d->m_model->setRange(min, max); | - | ||||||||||||||||||||||||
2550 | d->yearEdit->setMinimum(d->m_model->m_minimumDate.year()); | - | ||||||||||||||||||||||||
2551 | d->yearEdit->setMaximum(d->m_model->m_maximumDate.year()); | - | ||||||||||||||||||||||||
2552 | d->updateMonthMenu(); | - | ||||||||||||||||||||||||
2553 | QDate newDate = d->m_model->m_date; | - | ||||||||||||||||||||||||
2554 | if (oldDate != newDate) {
| 0 | ||||||||||||||||||||||||
2555 | d->update(); | - | ||||||||||||||||||||||||
2556 | d->showMonth(newDate.year(), newDate.month()); | - | ||||||||||||||||||||||||
2557 | d->m_navigator->setDate(newDate); | - | ||||||||||||||||||||||||
2558 | emit selectionChanged(); | - | ||||||||||||||||||||||||
2559 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2560 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2561 | - | |||||||||||||||||||||||||
2562 | - | |||||||||||||||||||||||||
2563 | /*! \enum QCalendarWidget::HorizontalHeaderFormat | - | ||||||||||||||||||||||||
2564 | - | |||||||||||||||||||||||||
2565 | This enum type defines the various formats the horizontal header can display. | - | ||||||||||||||||||||||||
2566 | - | |||||||||||||||||||||||||
2567 | \value SingleLetterDayNames The header displays a single letter abbreviation for day names (e.g. M for Monday). | - | ||||||||||||||||||||||||
2568 | \value ShortDayNames The header displays a short abbreviation for day names (e.g. Mon for Monday). | - | ||||||||||||||||||||||||
2569 | \value LongDayNames The header displays complete day names (e.g. Monday). | - | ||||||||||||||||||||||||
2570 | \value NoHorizontalHeader The header is hidden. | - | ||||||||||||||||||||||||
2571 | - | |||||||||||||||||||||||||
2572 | \sa horizontalHeaderFormat(), VerticalHeaderFormat | - | ||||||||||||||||||||||||
2573 | */ | - | ||||||||||||||||||||||||
2574 | - | |||||||||||||||||||||||||
2575 | /*! | - | ||||||||||||||||||||||||
2576 | \property QCalendarWidget::horizontalHeaderFormat | - | ||||||||||||||||||||||||
2577 | \brief the format of the horizontal header. | - | ||||||||||||||||||||||||
2578 | - | |||||||||||||||||||||||||
2579 | The default value is QCalendarWidget::ShortDayNames. | - | ||||||||||||||||||||||||
2580 | */ | - | ||||||||||||||||||||||||
2581 | - | |||||||||||||||||||||||||
2582 | void QCalendarWidget::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format) | - | ||||||||||||||||||||||||
2583 | { | - | ||||||||||||||||||||||||
2584 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2585 | if (d->m_model->m_horizontalHeaderFormat == format)
| 0 | ||||||||||||||||||||||||
2586 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2587 | - | |||||||||||||||||||||||||
2588 | d->m_model->setHorizontalHeaderFormat(format); | - | ||||||||||||||||||||||||
2589 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2590 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2591 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2592 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2593 | - | |||||||||||||||||||||||||
2594 | QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat() const | - | ||||||||||||||||||||||||
2595 | { | - | ||||||||||||||||||||||||
2596 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2597 | return d->m_model->m_horizontalHeaderFormat; never executed: return d->m_model->m_horizontalHeaderFormat; | 0 | ||||||||||||||||||||||||
2598 | } | - | ||||||||||||||||||||||||
2599 | - | |||||||||||||||||||||||||
2600 | - | |||||||||||||||||||||||||
2601 | /*! | - | ||||||||||||||||||||||||
2602 | \enum QCalendarWidget::VerticalHeaderFormat | - | ||||||||||||||||||||||||
2603 | - | |||||||||||||||||||||||||
2604 | This enum type defines the various formats the vertical header can display. | - | ||||||||||||||||||||||||
2605 | - | |||||||||||||||||||||||||
2606 | \value ISOWeekNumbers The header displays ISO week numbers as described by \l QDate::weekNumber(). | - | ||||||||||||||||||||||||
2607 | \value NoVerticalHeader The header is hidden. | - | ||||||||||||||||||||||||
2608 | - | |||||||||||||||||||||||||
2609 | \sa verticalHeaderFormat(), HorizontalHeaderFormat | - | ||||||||||||||||||||||||
2610 | */ | - | ||||||||||||||||||||||||
2611 | - | |||||||||||||||||||||||||
2612 | /*! | - | ||||||||||||||||||||||||
2613 | \property QCalendarWidget::verticalHeaderFormat | - | ||||||||||||||||||||||||
2614 | \brief the format of the vertical header. | - | ||||||||||||||||||||||||
2615 | - | |||||||||||||||||||||||||
2616 | The default value is QCalendarWidget::ISOWeekNumber. | - | ||||||||||||||||||||||||
2617 | */ | - | ||||||||||||||||||||||||
2618 | - | |||||||||||||||||||||||||
2619 | QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat() const | - | ||||||||||||||||||||||||
2620 | { | - | ||||||||||||||||||||||||
2621 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2622 | bool shown = d->m_model->weekNumbersShown(); | - | ||||||||||||||||||||||||
2623 | if (shown)
| 0 | ||||||||||||||||||||||||
2624 | return QCalendarWidget::ISOWeekNumbers; never executed: return QCalendarWidget::ISOWeekNumbers; | 0 | ||||||||||||||||||||||||
2625 | return QCalendarWidget::NoVerticalHeader; never executed: return QCalendarWidget::NoVerticalHeader; | 0 | ||||||||||||||||||||||||
2626 | } | - | ||||||||||||||||||||||||
2627 | - | |||||||||||||||||||||||||
2628 | void QCalendarWidget::setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat format) | - | ||||||||||||||||||||||||
2629 | { | - | ||||||||||||||||||||||||
2630 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2631 | bool show = false; | - | ||||||||||||||||||||||||
2632 | if (format == QCalendarWidget::ISOWeekNumbers)
| 0 | ||||||||||||||||||||||||
2633 | show = true; never executed: show = true; | 0 | ||||||||||||||||||||||||
2634 | if (d->m_model->weekNumbersShown() == show)
| 0 | ||||||||||||||||||||||||
2635 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2636 | d->m_model->setWeekNumbersShown(show); | - | ||||||||||||||||||||||||
2637 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2638 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2639 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2640 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2641 | - | |||||||||||||||||||||||||
2642 | /*! | - | ||||||||||||||||||||||||
2643 | \property QCalendarWidget::gridVisible | - | ||||||||||||||||||||||||
2644 | \brief whether the table grid is displayed. | - | ||||||||||||||||||||||||
2645 | - | |||||||||||||||||||||||||
2646 | \table | - | ||||||||||||||||||||||||
2647 | \row | - | ||||||||||||||||||||||||
2648 | \li \inlineimage qcalendarwidget-grid.png | - | ||||||||||||||||||||||||
2649 | \row | - | ||||||||||||||||||||||||
2650 | \li | - | ||||||||||||||||||||||||
2651 | \snippet code/src_gui_widgets_qcalendarwidget.cpp 5 | - | ||||||||||||||||||||||||
2652 | \endtable | - | ||||||||||||||||||||||||
2653 | - | |||||||||||||||||||||||||
2654 | The default value is false. | - | ||||||||||||||||||||||||
2655 | */ | - | ||||||||||||||||||||||||
2656 | - | |||||||||||||||||||||||||
2657 | bool QCalendarWidget::isGridVisible() const | - | ||||||||||||||||||||||||
2658 | { | - | ||||||||||||||||||||||||
2659 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2660 | return d->m_view->showGrid(); never executed: return d->m_view->showGrid(); | 0 | ||||||||||||||||||||||||
2661 | } | - | ||||||||||||||||||||||||
2662 | - | |||||||||||||||||||||||||
2663 | void QCalendarWidget::setGridVisible(bool show) | - | ||||||||||||||||||||||||
2664 | { | - | ||||||||||||||||||||||||
2665 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2666 | d->m_view->setShowGrid(show); | - | ||||||||||||||||||||||||
2667 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2668 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2669 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2670 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2671 | - | |||||||||||||||||||||||||
2672 | /*! | - | ||||||||||||||||||||||||
2673 | \property QCalendarWidget::selectionMode | - | ||||||||||||||||||||||||
2674 | \brief the type of selection the user can make in the calendar | - | ||||||||||||||||||||||||
2675 | - | |||||||||||||||||||||||||
2676 | When this property is set to SingleSelection, the user can select a date | - | ||||||||||||||||||||||||
2677 | within the minimum and maximum allowed dates, using either the mouse or | - | ||||||||||||||||||||||||
2678 | the keyboard. | - | ||||||||||||||||||||||||
2679 | - | |||||||||||||||||||||||||
2680 | When the property is set to NoSelection, the user will be unable to select | - | ||||||||||||||||||||||||
2681 | dates, but they can still be selected programmatically. Note that the date | - | ||||||||||||||||||||||||
2682 | that is selected when the property is set to NoSelection will still be | - | ||||||||||||||||||||||||
2683 | the selected date of the calendar. | - | ||||||||||||||||||||||||
2684 | - | |||||||||||||||||||||||||
2685 | The default value is SingleSelection. | - | ||||||||||||||||||||||||
2686 | */ | - | ||||||||||||||||||||||||
2687 | - | |||||||||||||||||||||||||
2688 | QCalendarWidget::SelectionMode QCalendarWidget::selectionMode() const | - | ||||||||||||||||||||||||
2689 | { | - | ||||||||||||||||||||||||
2690 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2691 | return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection; never executed: return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
| 0 | ||||||||||||||||||||||||
2692 | } | - | ||||||||||||||||||||||||
2693 | - | |||||||||||||||||||||||||
2694 | void QCalendarWidget::setSelectionMode(SelectionMode mode) | - | ||||||||||||||||||||||||
2695 | { | - | ||||||||||||||||||||||||
2696 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2697 | d->m_view->readOnly = (mode == QCalendarWidget::NoSelection); | - | ||||||||||||||||||||||||
2698 | d->setNavigatorEnabled(isDateEditEnabled() && (selectionMode() != QCalendarWidget::NoSelection)); | - | ||||||||||||||||||||||||
2699 | d->update(); | - | ||||||||||||||||||||||||
2700 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2701 | - | |||||||||||||||||||||||||
2702 | /*! | - | ||||||||||||||||||||||||
2703 | \property QCalendarWidget::firstDayOfWeek | - | ||||||||||||||||||||||||
2704 | \brief a value identifying the day displayed in the first column. | - | ||||||||||||||||||||||||
2705 | - | |||||||||||||||||||||||||
2706 | By default, the day displayed in the first column | - | ||||||||||||||||||||||||
2707 | is the first day of the week for the calendar's locale. | - | ||||||||||||||||||||||||
2708 | */ | - | ||||||||||||||||||||||||
2709 | - | |||||||||||||||||||||||||
2710 | void QCalendarWidget::setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek) | - | ||||||||||||||||||||||||
2711 | { | - | ||||||||||||||||||||||||
2712 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2713 | if ((Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek)
| 0 | ||||||||||||||||||||||||
2714 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2715 | - | |||||||||||||||||||||||||
2716 | d->m_model->setFirstColumnDay(dayOfWeek); | - | ||||||||||||||||||||||||
2717 | d->update(); | - | ||||||||||||||||||||||||
2718 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2719 | - | |||||||||||||||||||||||||
2720 | Qt::DayOfWeek QCalendarWidget::firstDayOfWeek() const | - | ||||||||||||||||||||||||
2721 | { | - | ||||||||||||||||||||||||
2722 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2723 | return (Qt::DayOfWeek)d->m_model->firstColumnDay(); never executed: return (Qt::DayOfWeek)d->m_model->firstColumnDay(); | 0 | ||||||||||||||||||||||||
2724 | } | - | ||||||||||||||||||||||||
2725 | - | |||||||||||||||||||||||||
2726 | /*! | - | ||||||||||||||||||||||||
2727 | Returns the text char format for rendering the header. | - | ||||||||||||||||||||||||
2728 | */ | - | ||||||||||||||||||||||||
2729 | QTextCharFormat QCalendarWidget::headerTextFormat() const | - | ||||||||||||||||||||||||
2730 | { | - | ||||||||||||||||||||||||
2731 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2732 | return d->m_model->m_headerFormat; never executed: return d->m_model->m_headerFormat; | 0 | ||||||||||||||||||||||||
2733 | } | - | ||||||||||||||||||||||||
2734 | - | |||||||||||||||||||||||||
2735 | /*! | - | ||||||||||||||||||||||||
2736 | Sets the text char format for rendering the header to \a format. | - | ||||||||||||||||||||||||
2737 | If you also set a weekday text format, this format's foreground and | - | ||||||||||||||||||||||||
2738 | background color will take precedence over the header's format. | - | ||||||||||||||||||||||||
2739 | The other formatting information will still be decided by | - | ||||||||||||||||||||||||
2740 | the header's format. | - | ||||||||||||||||||||||||
2741 | */ | - | ||||||||||||||||||||||||
2742 | void QCalendarWidget::setHeaderTextFormat(const QTextCharFormat &format) | - | ||||||||||||||||||||||||
2743 | { | - | ||||||||||||||||||||||||
2744 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2745 | d->m_model->m_headerFormat = format; | - | ||||||||||||||||||||||||
2746 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2747 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2748 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2749 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||
2751 | /*! | - | ||||||||||||||||||||||||
2752 | Returns the text char format for rendering of day in the week \a dayOfWeek. | - | ||||||||||||||||||||||||
2753 | - | |||||||||||||||||||||||||
2754 | \sa headerTextFormat() | - | ||||||||||||||||||||||||
2755 | */ | - | ||||||||||||||||||||||||
2756 | QTextCharFormat QCalendarWidget::weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const | - | ||||||||||||||||||||||||
2757 | { | - | ||||||||||||||||||||||||
2758 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2759 | return d->m_model->m_dayFormats.value(dayOfWeek); never executed: return d->m_model->m_dayFormats.value(dayOfWeek); | 0 | ||||||||||||||||||||||||
2760 | } | - | ||||||||||||||||||||||||
2761 | - | |||||||||||||||||||||||||
2762 | /*! | - | ||||||||||||||||||||||||
2763 | Sets the text char format for rendering of day in the week \a dayOfWeek to \a format. | - | ||||||||||||||||||||||||
2764 | The format will take precedence over the header format in case of foreground | - | ||||||||||||||||||||||||
2765 | and background color. Other text formatting information is taken from the headers format. | - | ||||||||||||||||||||||||
2766 | - | |||||||||||||||||||||||||
2767 | \sa setHeaderTextFormat() | - | ||||||||||||||||||||||||
2768 | */ | - | ||||||||||||||||||||||||
2769 | void QCalendarWidget::setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format) | - | ||||||||||||||||||||||||
2770 | { | - | ||||||||||||||||||||||||
2771 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2772 | d->m_model->m_dayFormats[dayOfWeek] = format; | - | ||||||||||||||||||||||||
2773 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2774 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2775 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2776 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2777 | - | |||||||||||||||||||||||||
2778 | /*! | - | ||||||||||||||||||||||||
2779 | Returns a QMap from QDate to QTextCharFormat showing all dates | - | ||||||||||||||||||||||||
2780 | that use a special format that alters their rendering. | - | ||||||||||||||||||||||||
2781 | */ | - | ||||||||||||||||||||||||
2782 | QMap<QDate, QTextCharFormat> QCalendarWidget::dateTextFormat() const | - | ||||||||||||||||||||||||
2783 | { | - | ||||||||||||||||||||||||
2784 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2785 | return d->m_model->m_dateFormats; never executed: return d->m_model->m_dateFormats; | 0 | ||||||||||||||||||||||||
2786 | } | - | ||||||||||||||||||||||||
2787 | - | |||||||||||||||||||||||||
2788 | /*! | - | ||||||||||||||||||||||||
2789 | Returns a QTextCharFormat for \a date. The char format can be be | - | ||||||||||||||||||||||||
2790 | empty if the date is not renderd specially. | - | ||||||||||||||||||||||||
2791 | */ | - | ||||||||||||||||||||||||
2792 | QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const | - | ||||||||||||||||||||||||
2793 | { | - | ||||||||||||||||||||||||
2794 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2795 | return d->m_model->m_dateFormats.value(date); never executed: return d->m_model->m_dateFormats.value(date); | 0 | ||||||||||||||||||||||||
2796 | } | - | ||||||||||||||||||||||||
2797 | - | |||||||||||||||||||||||||
2798 | /*! | - | ||||||||||||||||||||||||
2799 | Sets the format used to render the given \a date to that specified by \a format. | - | ||||||||||||||||||||||||
2800 | - | |||||||||||||||||||||||||
2801 | If \a date is null, all date formats are cleared. | - | ||||||||||||||||||||||||
2802 | */ | - | ||||||||||||||||||||||||
2803 | void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format) | - | ||||||||||||||||||||||||
2804 | { | - | ||||||||||||||||||||||||
2805 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2806 | if (date.isNull())
| 0 | ||||||||||||||||||||||||
2807 | d->m_model->m_dateFormats.clear(); never executed: d->m_model->m_dateFormats.clear(); | 0 | ||||||||||||||||||||||||
2808 | else | - | ||||||||||||||||||||||||
2809 | d->m_model->m_dateFormats[date] = format; never executed: d->m_model->m_dateFormats[date] = format; | 0 | ||||||||||||||||||||||||
2810 | d->m_view->viewport()->update(); | - | ||||||||||||||||||||||||
2811 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
2812 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2813 | - | |||||||||||||||||||||||||
2814 | /*! | - | ||||||||||||||||||||||||
2815 | \property QCalendarWidget::dateEditEnabled | - | ||||||||||||||||||||||||
2816 | \brief whether the date edit popup is enabled | - | ||||||||||||||||||||||||
2817 | \since 4.3 | - | ||||||||||||||||||||||||
2818 | - | |||||||||||||||||||||||||
2819 | If this property is enabled, pressing a non-modifier key will cause a | - | ||||||||||||||||||||||||
2820 | date edit to popup if the calendar widget has focus, allowing the user | - | ||||||||||||||||||||||||
2821 | to specify a date in the form specified by the current locale. | - | ||||||||||||||||||||||||
2822 | - | |||||||||||||||||||||||||
2823 | By default, this property is enabled. | - | ||||||||||||||||||||||||
2824 | - | |||||||||||||||||||||||||
2825 | The date edit is simpler in appearance than QDateEdit, but allows the | - | ||||||||||||||||||||||||
2826 | user to navigate between fields using the left and right cursor keys, | - | ||||||||||||||||||||||||
2827 | increment and decrement individual fields using the up and down cursor | - | ||||||||||||||||||||||||
2828 | keys, and enter values directly using the number keys. | - | ||||||||||||||||||||||||
2829 | - | |||||||||||||||||||||||||
2830 | \sa QCalendarWidget::dateEditAcceptDelay | - | ||||||||||||||||||||||||
2831 | */ | - | ||||||||||||||||||||||||
2832 | bool QCalendarWidget::isDateEditEnabled() const | - | ||||||||||||||||||||||||
2833 | { | - | ||||||||||||||||||||||||
2834 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2835 | return d->m_dateEditEnabled; never executed: return d->m_dateEditEnabled; | 0 | ||||||||||||||||||||||||
2836 | } | - | ||||||||||||||||||||||||
2837 | - | |||||||||||||||||||||||||
2838 | void QCalendarWidget::setDateEditEnabled(bool enable) | - | ||||||||||||||||||||||||
2839 | { | - | ||||||||||||||||||||||||
2840 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2841 | if (isDateEditEnabled() == enable)
| 0 | ||||||||||||||||||||||||
2842 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2843 | - | |||||||||||||||||||||||||
2844 | d->m_dateEditEnabled = enable; | - | ||||||||||||||||||||||||
2845 | - | |||||||||||||||||||||||||
2846 | d->setNavigatorEnabled(enable && (selectionMode() != QCalendarWidget::NoSelection)); | - | ||||||||||||||||||||||||
2847 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2848 | - | |||||||||||||||||||||||||
2849 | /*! | - | ||||||||||||||||||||||||
2850 | \property QCalendarWidget::dateEditAcceptDelay | - | ||||||||||||||||||||||||
2851 | \brief the time an inactive date edit is shown before its contents are accepted | - | ||||||||||||||||||||||||
2852 | \since 4.3 | - | ||||||||||||||||||||||||
2853 | - | |||||||||||||||||||||||||
2854 | If the calendar widget's \l{dateEditEnabled}{date edit is enabled}, this | - | ||||||||||||||||||||||||
2855 | property specifies the amount of time (in millseconds) that the date edit | - | ||||||||||||||||||||||||
2856 | remains open after the most recent user input. Once this time has elapsed, | - | ||||||||||||||||||||||||
2857 | the date specified in the date edit is accepted and the popup is closed. | - | ||||||||||||||||||||||||
2858 | - | |||||||||||||||||||||||||
2859 | By default, the delay is defined to be 1500 milliseconds (1.5 seconds). | - | ||||||||||||||||||||||||
2860 | */ | - | ||||||||||||||||||||||||
2861 | int QCalendarWidget::dateEditAcceptDelay() const | - | ||||||||||||||||||||||||
2862 | { | - | ||||||||||||||||||||||||
2863 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2864 | return d->m_navigator->dateEditAcceptDelay(); never executed: return d->m_navigator->dateEditAcceptDelay(); | 0 | ||||||||||||||||||||||||
2865 | } | - | ||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||
2867 | void QCalendarWidget::setDateEditAcceptDelay(int delay) | - | ||||||||||||||||||||||||
2868 | { | - | ||||||||||||||||||||||||
2869 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2870 | d->m_navigator->setDateEditAcceptDelay(delay); | - | ||||||||||||||||||||||||
2871 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2872 | - | |||||||||||||||||||||||||
2873 | /*! | - | ||||||||||||||||||||||||
2874 | \since 4.4 | - | ||||||||||||||||||||||||
2875 | - | |||||||||||||||||||||||||
2876 | Updates the cell specified by the given \a date unless updates | - | ||||||||||||||||||||||||
2877 | are disabled or the cell is hidden. | - | ||||||||||||||||||||||||
2878 | - | |||||||||||||||||||||||||
2879 | \sa updateCells(), yearShown(), monthShown() | - | ||||||||||||||||||||||||
2880 | */ | - | ||||||||||||||||||||||||
2881 | void QCalendarWidget::updateCell(const QDate &date) | - | ||||||||||||||||||||||||
2882 | { | - | ||||||||||||||||||||||||
2883 | if (!date.isValid()) {
| 0 | ||||||||||||||||||||||||
2884 | qWarning("QCalendarWidget::updateCell: Invalid date"); | - | ||||||||||||||||||||||||
2885 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2886 | } | - | ||||||||||||||||||||||||
2887 | - | |||||||||||||||||||||||||
2888 | if (!isVisible())
| 0 | ||||||||||||||||||||||||
2889 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2890 | - | |||||||||||||||||||||||||
2891 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2892 | int row, column; | - | ||||||||||||||||||||||||
2893 | d->m_model->cellForDate(date, &row, &column); | - | ||||||||||||||||||||||||
2894 | if (row == -1 || column == -1)
| 0 | ||||||||||||||||||||||||
2895 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2896 | - | |||||||||||||||||||||||||
2897 | QModelIndex modelIndex = d->m_model->index(row, column); | - | ||||||||||||||||||||||||
2898 | if (!modelIndex.isValid())
| 0 | ||||||||||||||||||||||||
2899 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2900 | - | |||||||||||||||||||||||||
2901 | d->m_view->viewport()->update(d->m_view->visualRect(modelIndex)); | - | ||||||||||||||||||||||||
2902 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2903 | - | |||||||||||||||||||||||||
2904 | /*! | - | ||||||||||||||||||||||||
2905 | \since 4.4 | - | ||||||||||||||||||||||||
2906 | - | |||||||||||||||||||||||||
2907 | Updates all visible cells unless updates are disabled. | - | ||||||||||||||||||||||||
2908 | - | |||||||||||||||||||||||||
2909 | \sa updateCell() | - | ||||||||||||||||||||||||
2910 | */ | - | ||||||||||||||||||||||||
2911 | void QCalendarWidget::updateCells() | - | ||||||||||||||||||||||||
2912 | { | - | ||||||||||||||||||||||||
2913 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2914 | if (isVisible())
| 0 | ||||||||||||||||||||||||
2915 | d->m_view->viewport()->update(); never executed: d->m_view->viewport()->update(); | 0 | ||||||||||||||||||||||||
2916 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2917 | - | |||||||||||||||||||||||||
2918 | /*! | - | ||||||||||||||||||||||||
2919 | \fn void QCalendarWidget::selectionChanged() | - | ||||||||||||||||||||||||
2920 | - | |||||||||||||||||||||||||
2921 | This signal is emitted when the currently selected date is | - | ||||||||||||||||||||||||
2922 | changed. | - | ||||||||||||||||||||||||
2923 | - | |||||||||||||||||||||||||
2924 | The currently selected date can be changed by the user using the | - | ||||||||||||||||||||||||
2925 | mouse or keyboard, or by the programmer using setSelectedDate(). | - | ||||||||||||||||||||||||
2926 | - | |||||||||||||||||||||||||
2927 | \sa selectedDate() | - | ||||||||||||||||||||||||
2928 | */ | - | ||||||||||||||||||||||||
2929 | - | |||||||||||||||||||||||||
2930 | /*! | - | ||||||||||||||||||||||||
2931 | \fn void QCalendarWidget::currentPageChanged(int year, int month) | - | ||||||||||||||||||||||||
2932 | - | |||||||||||||||||||||||||
2933 | This signal is emitted when the currently shown month is changed. | - | ||||||||||||||||||||||||
2934 | The new \a year and \a month are passed as parameters. | - | ||||||||||||||||||||||||
2935 | - | |||||||||||||||||||||||||
2936 | \sa setCurrentPage() | - | ||||||||||||||||||||||||
2937 | */ | - | ||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||
2939 | /*! | - | ||||||||||||||||||||||||
2940 | \fn void QCalendarWidget::activated(const QDate &date) | - | ||||||||||||||||||||||||
2941 | - | |||||||||||||||||||||||||
2942 | This signal is emitted whenever the user presses the Return or | - | ||||||||||||||||||||||||
2943 | Enter key or double-clicks a \a date in the calendar | - | ||||||||||||||||||||||||
2944 | widget. | - | ||||||||||||||||||||||||
2945 | */ | - | ||||||||||||||||||||||||
2946 | - | |||||||||||||||||||||||||
2947 | /*! | - | ||||||||||||||||||||||||
2948 | \fn void QCalendarWidget::clicked(const QDate &date) | - | ||||||||||||||||||||||||
2949 | - | |||||||||||||||||||||||||
2950 | This signal is emitted when a mouse button is clicked. The date | - | ||||||||||||||||||||||||
2951 | the mouse was clicked on is specified by \a date. The signal is | - | ||||||||||||||||||||||||
2952 | only emitted when clicked on a valid date, e.g., dates are not | - | ||||||||||||||||||||||||
2953 | outside the minimumDate() and maximumDate(). If the selection mode | - | ||||||||||||||||||||||||
2954 | is NoSelection, this signal will not be emitted. | - | ||||||||||||||||||||||||
2955 | - | |||||||||||||||||||||||||
2956 | */ | - | ||||||||||||||||||||||||
2957 | - | |||||||||||||||||||||||||
2958 | /*! | - | ||||||||||||||||||||||||
2959 | \property QCalendarWidget::navigationBarVisible | - | ||||||||||||||||||||||||
2960 | \brief whether the navigation bar is shown or not | - | ||||||||||||||||||||||||
2961 | - | |||||||||||||||||||||||||
2962 | \since 4.3 | - | ||||||||||||||||||||||||
2963 | - | |||||||||||||||||||||||||
2964 | When this property is \c true (the default), the next month, | - | ||||||||||||||||||||||||
2965 | previous month, month selection, year selection controls are | - | ||||||||||||||||||||||||
2966 | shown on top. | - | ||||||||||||||||||||||||
2967 | - | |||||||||||||||||||||||||
2968 | When the property is set to false, these controls are hidden. | - | ||||||||||||||||||||||||
2969 | */ | - | ||||||||||||||||||||||||
2970 | - | |||||||||||||||||||||||||
2971 | bool QCalendarWidget::isNavigationBarVisible() const | - | ||||||||||||||||||||||||
2972 | { | - | ||||||||||||||||||||||||
2973 | Q_D(const QCalendarWidget); | - | ||||||||||||||||||||||||
2974 | return d->navBarVisible; never executed: return d->navBarVisible; | 0 | ||||||||||||||||||||||||
2975 | } | - | ||||||||||||||||||||||||
2976 | - | |||||||||||||||||||||||||
2977 | - | |||||||||||||||||||||||||
2978 | void QCalendarWidget::setNavigationBarVisible(bool visible) | - | ||||||||||||||||||||||||
2979 | { | - | ||||||||||||||||||||||||
2980 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2981 | d->navBarVisible = visible; | - | ||||||||||||||||||||||||
2982 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
2983 | d->navBarBackground->setVisible(visible); | - | ||||||||||||||||||||||||
2984 | updateGeometry(); | - | ||||||||||||||||||||||||
2985 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2986 | - | |||||||||||||||||||||||||
2987 | /*! | - | ||||||||||||||||||||||||
2988 | \reimp | - | ||||||||||||||||||||||||
2989 | */ | - | ||||||||||||||||||||||||
2990 | bool QCalendarWidget::event(QEvent *event) | - | ||||||||||||||||||||||||
2991 | { | - | ||||||||||||||||||||||||
2992 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
2993 | switch (event->type()) { | - | ||||||||||||||||||||||||
2994 | case QEvent::LayoutDirectionChange: never executed: case QEvent::LayoutDirectionChange: | 0 | ||||||||||||||||||||||||
2995 | d->updateButtonIcons(); | - | ||||||||||||||||||||||||
2996 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2997 | case QEvent::LocaleChange: never executed: case QEvent::LocaleChange: | 0 | ||||||||||||||||||||||||
2998 | d->m_model->setFirstColumnDay(locale().firstDayOfWeek()); | - | ||||||||||||||||||||||||
2999 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
3000 | d->updateMonthMenuNames(); | - | ||||||||||||||||||||||||
3001 | d->updateNavigationBar(); | - | ||||||||||||||||||||||||
3002 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
3003 | break; never executed: break; | 0 | ||||||||||||||||||||||||
3004 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||
3005 | case QEvent::ApplicationFontChange: never executed: case QEvent::ApplicationFontChange: | 0 | ||||||||||||||||||||||||
3006 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
3007 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
3008 | break; never executed: break; | 0 | ||||||||||||||||||||||||
3009 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||
3010 | d->cachedSizeHint = QSize(); | - | ||||||||||||||||||||||||
3011 | d->m_view->updateGeometry(); | - | ||||||||||||||||||||||||
3012 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||||||||
3013 | break; never executed: break; | 0 | ||||||||||||||||||||||||
3014 | } | - | ||||||||||||||||||||||||
3015 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||||||||
3016 | } | - | ||||||||||||||||||||||||
3017 | - | |||||||||||||||||||||||||
3018 | /*! | - | ||||||||||||||||||||||||
3019 | \reimp | - | ||||||||||||||||||||||||
3020 | */ | - | ||||||||||||||||||||||||
3021 | bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) | - | ||||||||||||||||||||||||
3022 | { | - | ||||||||||||||||||||||||
3023 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
3024 | if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) {
| 0 | ||||||||||||||||||||||||
3025 | QWidget *tlw = window(); | - | ||||||||||||||||||||||||
3026 | QWidget *widget = static_cast<QWidget*>(watched); | - | ||||||||||||||||||||||||
3027 | //as we have a event filter on the whole application we first make sure that the top level widget | - | ||||||||||||||||||||||||
3028 | //of both this and the watched widget are the same to decide if we should finish the year edition. | - | ||||||||||||||||||||||||
3029 | if (widget->window() == tlw) {
| 0 | ||||||||||||||||||||||||
3030 | QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); | - | ||||||||||||||||||||||||
3031 | QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); | - | ||||||||||||||||||||||||
3032 | if (!geom.contains(mousePos)) {
| 0 | ||||||||||||||||||||||||
3033 | event->accept(); | - | ||||||||||||||||||||||||
3034 | d->_q_yearEditingFinished(); | - | ||||||||||||||||||||||||
3035 | setFocus(); | - | ||||||||||||||||||||||||
3036 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
3037 | } | - | ||||||||||||||||||||||||
3038 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3039 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3040 | return QWidget::eventFilter(watched, event); never executed: return QWidget::eventFilter(watched, event); | 0 | ||||||||||||||||||||||||
3041 | } | - | ||||||||||||||||||||||||
3042 | - | |||||||||||||||||||||||||
3043 | /*! | - | ||||||||||||||||||||||||
3044 | \reimp | - | ||||||||||||||||||||||||
3045 | */ | - | ||||||||||||||||||||||||
3046 | void QCalendarWidget::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
3047 | { | - | ||||||||||||||||||||||||
3048 | setAttribute(Qt::WA_NoMouseReplay); | - | ||||||||||||||||||||||||
3049 | QWidget::mousePressEvent(event); | - | ||||||||||||||||||||||||
3050 | setFocus(); | - | ||||||||||||||||||||||||
3051 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3052 | - | |||||||||||||||||||||||||
3053 | /*! | - | ||||||||||||||||||||||||
3054 | \reimp | - | ||||||||||||||||||||||||
3055 | */ | - | ||||||||||||||||||||||||
3056 | void QCalendarWidget::resizeEvent(QResizeEvent * event) | - | ||||||||||||||||||||||||
3057 | { | - | ||||||||||||||||||||||||
3058 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
3059 | - | |||||||||||||||||||||||||
3060 | // XXX Should really use a QWidgetStack for yearEdit and yearButton, | - | ||||||||||||||||||||||||
3061 | // XXX here we hide the year edit when the layout is likely to break | - | ||||||||||||||||||||||||
3062 | // XXX the manual positioning of the yearEdit over the yearButton. | - | ||||||||||||||||||||||||
3063 | if(d->yearEdit->isVisible() && event->size().width() != event->oldSize().width())
| 0 | ||||||||||||||||||||||||
3064 | d->_q_yearEditingFinished(); never executed: d->_q_yearEditingFinished(); | 0 | ||||||||||||||||||||||||
3065 | - | |||||||||||||||||||||||||
3066 | QWidget::resizeEvent(event); | - | ||||||||||||||||||||||||
3067 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3068 | - | |||||||||||||||||||||||||
3069 | /*! | - | ||||||||||||||||||||||||
3070 | \reimp | - | ||||||||||||||||||||||||
3071 | */ | - | ||||||||||||||||||||||||
3072 | void QCalendarWidget::keyPressEvent(QKeyEvent * event) | - | ||||||||||||||||||||||||
3073 | { | - | ||||||||||||||||||||||||
3074 | Q_D(QCalendarWidget); | - | ||||||||||||||||||||||||
3075 | if (d->yearEdit->isVisible()&& event->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||||||||
3076 | d->yearEdit->setValue(yearShown()); | - | ||||||||||||||||||||||||
3077 | d->_q_yearEditingFinished(); | - | ||||||||||||||||||||||||
3078 | return; never executed: return; | 0 | ||||||||||||||||||||||||
3079 | } | - | ||||||||||||||||||||||||
3080 | QWidget::keyPressEvent(event); | - | ||||||||||||||||||||||||
3081 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3082 | - | |||||||||||||||||||||||||
3083 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
3084 | - | |||||||||||||||||||||||||
3085 | #include "qcalendarwidget.moc" | - | ||||||||||||||||||||||||
3086 | #include "moc_qcalendarwidget.cpp" | - | ||||||||||||||||||||||||
3087 | - | |||||||||||||||||||||||||
3088 | #endif //QT_NO_CALENDARWIDGET | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |