7#include <QtGui/qstylehints.h>
8#include <QtGui/qguiapplication.h>
9#include <QtQuickTemplates2/private/qquickcontrol_p_p.h>
10#include <QtQml/qqmlinfo.h>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
54
55
56
57
60
61
62
63
66
67
68
69
72
73
74
75
79 Q_DECLARE_PUBLIC(QQuickMonthGrid)
92 bool handlePress(
const QPointF &point, ulong timestamp)
override;
93 bool handleMove(
const QPointF &point, ulong timestamp)
override;
115 itemSize.setWidth((contentItem->width() - 6 * spacing) / 7);
116 itemSize.setHeight((contentItem->height() - 5 * spacing) / 6);
118 const auto childItems = contentItem->childItems();
119 for (QQuickItem *item : childItems) {
120 if (!QQuickItemPrivate::get(item)->isTransparentForPositioner())
121 item->setSize(itemSize);
127 Q_Q(
const QQuickMonthGrid);
129 QPointF mapped = q->mapToItem(contentItem, pos);
130 return contentItem->childAt(mapped.x(), mapped.y());
138 return model->dateAt(contentItem->childItems().indexOf(cell));
144 Q_Q(QQuickMonthGrid);
146 pressedItem = cellAt(pos);
147 pressedDate = dateOf(pressedItem);
148 if (pressedDate.isValid())
149 emit q->pressed(pressedDate);
154 Q_Q(QQuickMonthGrid);
155 if (pressedDate.isValid()) {
156 emit q->released(pressedDate);
158 emit q->clicked(pressedDate);
161 pressedItem =
nullptr;
166 Q_Q(QQuickMonthGrid);
167 QQuickControlPrivate::handlePress(point, timestamp);
169 if (pressedDate.isValid())
170 pressTimer = q->startTimer(qGuiApp->styleHints()->mousePressAndHoldInterval());
176 QQuickControlPrivate::handleMove(point, timestamp);
183 QQuickControlPrivate::handleRelease(point, timestamp);
190 QQuickControlPrivate::handleUngrab();
195 QQuickControl(*(
new QQuickMonthGridPrivate), parent)
197 Q_D(QQuickMonthGrid);
198 setFlag(ItemIsFocusScope);
199 setActiveFocusOnTab(
true);
200 setAcceptedMouseButtons(Qt::LeftButton);
202 setCursor(Qt::ArrowCursor);
205 d->model =
new QQuickMonthModel(
this);
206 d->source = QVariant::fromValue(d->model);
207 connect(d->model, &QQuickMonthModel::monthChanged,
this, &QQuickMonthGrid::monthChanged);
208 connect(d->model, &QQuickMonthModel::yearChanged,
this, &QQuickMonthGrid::yearChanged);
209 connect(d->model, &QQuickMonthModel::titleChanged,
this, &QQuickMonthGrid::titleChanged);
213
214
215
216
217
218
219
220
221
224 Q_D(
const QQuickMonthGrid);
225 return d->model->month() - 1;
230 Q_D(QQuickMonthGrid);
231 if (month < 0 || month > 11) {
232 qmlWarning(
this) <<
"month " << month <<
" is out of range [0...11]";
235 d->model->setMonth(month + 1);
239
240
241
242
243
244
245
248 Q_D(
const QQuickMonthGrid);
249 return d->model->year();
254 Q_D(QQuickMonthGrid);
255 if (year < -271820 || year > 275759) {
256 qmlWarning(
this) <<
"year " << year <<
" is out of range [-271820...275759]";
259 d->model->setYear(year);
263
264
265
266
267
268
271 Q_D(
const QQuickMonthGrid);
277 Q_D(QQuickMonthGrid);
278 if (d->source != source) {
280 emit sourceChanged();
285
286
287
288
289
290
291
292
295 Q_D(
const QQuickMonthGrid);
296 if (d->title.isNull())
297 return d->model->title();
303 Q_D(QQuickMonthGrid);
304 if (d->title != title) {
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
336 Q_D(
const QQuickMonthGrid);
342 Q_D(QQuickMonthGrid);
343 if (d->delegate != delegate) {
344 d->delegate = delegate;
345 emit delegateChanged();
351 Q_D(QQuickMonthGrid);
352 QQuickControl::componentComplete();
358 Q_D(QQuickMonthGrid);
359 QQuickControl::geometryChange(newGeometry, oldGeometry);
360 if (isComponentComplete())
366 Q_D(QQuickMonthGrid);
367 QQuickControl::localeChange(newLocale, oldLocale);
368 d->model->setLocale(newLocale);
373 Q_D(QQuickMonthGrid);
374 QQuickControl::paddingChange(newPadding, oldPadding);
375 if (isComponentComplete())
381 Q_D(QQuickMonthGrid);
382 QQuickControl::updatePolish();
388 Q_D(QQuickMonthGrid);
389 if (event->timerId() == d->pressTimer) {
390 if (d->pressedDate.isValid())
391 emit pressAndHold(d->pressedDate);
392 killTimer(d->pressTimer);
398#include "moc_qquickmonthgrid_p.cpp"
A grid of days for a calendar month.
bool handleRelease(const QPointF &point, ulong timestamp) override
bool handlePress(const QPointF &point, ulong timestamp) override
QQuickItem * cellAt(const QPointF &pos) const
void handleUngrab() override
QDateTime dateOf(QQuickItem *cell) const
bool handleMove(const QPointF &point, ulong timestamp) override
void clearPress(bool clicked)
void updatePress(const QPointF &pos)
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
int month() const
\qmlproperty int QtQuick.Controls::MonthGrid::month
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setTitle(const QString &title)
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
QQmlComponent * delegate() const
\qmlproperty Component QtQuick.Controls::MonthGrid::delegate
void setSource(const QVariant &source)
void setDelegate(QQmlComponent *delegate)
QString title() const
\qmlproperty string QtQuick.Controls::MonthGrid::title
void updatePolish() override
This function should perform any layout as required for this item.
int year() const
\qmlproperty int QtQuick.Controls::MonthGrid::year