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
52
53
56
57
58
59
62
63
64
65
68
69
70
71
74
75
76
77
81 Q_DECLARE_PUBLIC(QQuickMonthGrid)
94 bool handlePress(
const QPointF &point, ulong timestamp)
override;
95 bool handleMove(
const QPointF &point, ulong timestamp)
override;
117 itemSize.setWidth((contentItem->width() - 6 * spacing) / 7);
118 itemSize.setHeight((contentItem->height() - 5 * spacing) / 6);
120 const auto childItems = contentItem->childItems();
121 for (QQuickItem *item : childItems) {
122 if (!QQuickItemPrivate::get(item)->isTransparentForPositioner())
123 item->setSize(itemSize);
129 Q_Q(
const QQuickMonthGrid);
131 QPointF mapped = q->mapToItem(contentItem, pos);
132 return contentItem->childAt(mapped.x(), mapped.y());
140 return model->dateAt(contentItem->childItems().indexOf(cell));
146 Q_Q(QQuickMonthGrid);
148 pressedItem = cellAt(pos);
149 pressedDate = dateOf(pressedItem);
150 if (pressedDate.isValid())
151 emit q->pressed(pressedDate);
156 Q_Q(QQuickMonthGrid);
157 if (pressedDate.isValid()) {
158 emit q->released(pressedDate);
160 emit q->clicked(pressedDate);
163 pressedItem =
nullptr;
168 Q_Q(QQuickMonthGrid);
169 QQuickControlPrivate::handlePress(point, timestamp);
171 if (pressedDate.isValid())
172 pressTimer = q->startTimer(qGuiApp->styleHints()->mousePressAndHoldInterval());
178 QQuickControlPrivate::handleMove(point, timestamp);
185 QQuickControlPrivate::handleRelease(point, timestamp);
192 QQuickControlPrivate::handleUngrab();
197 QQuickControl(*(
new QQuickMonthGridPrivate), parent)
199 Q_D(QQuickMonthGrid);
200 setFlag(ItemIsFocusScope);
201 setActiveFocusOnTab(
true);
202 setAcceptedMouseButtons(Qt::LeftButton);
204 setCursor(Qt::ArrowCursor);
207 d->model =
new QQuickMonthModel(
this);
208 d->source = QVariant::fromValue(d->model);
209 connect(d->model, &QQuickMonthModel::monthChanged,
this, &QQuickMonthGrid::monthChanged);
215
216
217
218
219
220
221
222
223
226 Q_D(
const QQuickMonthGrid);
227 return d->model->month() - 1;
232 Q_D(QQuickMonthGrid);
233 if (month < 0 || month > 11) {
234 qmlWarning(
this) <<
"month " << month <<
" is out of range [0...11]";
237 d->model->setMonth(month + 1);
241
242
243
244
245
246
247
250 Q_D(
const QQuickMonthGrid);
251 return d->model->year();
256 Q_D(QQuickMonthGrid);
257 if (year < -271820 || year > 275759) {
258 qmlWarning(
this) <<
"year " << year <<
" is out of range [-271820...275759]";
261 d->model->setYear(year);
265
266
267
268
269
270
273 Q_D(
const QQuickMonthGrid);
279 Q_D(QQuickMonthGrid);
280 if (d->source != source) {
282 emit sourceChanged();
287
288
289
290
291
292
293
294
297 Q_D(
const QQuickMonthGrid);
298 if (d->title.isNull())
299 return d->model->title();
305 Q_D(QQuickMonthGrid);
306 if (d->title != title) {
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
338 Q_D(
const QQuickMonthGrid);
344 Q_D(QQuickMonthGrid);
345 if (d->delegate != delegate) {
346 d->delegate = delegate;
347 emit delegateChanged();
353 Q_D(QQuickMonthGrid);
354 QQuickControl::componentComplete();
360 Q_D(QQuickMonthGrid);
361 QQuickControl::geometryChange(newGeometry, oldGeometry);
362 if (isComponentComplete())
368 Q_D(QQuickMonthGrid);
369 QQuickControl::localeChange(newLocale, oldLocale);
370 d->model->setLocale(newLocale);
375 Q_D(QQuickMonthGrid);
376 QQuickControl::paddingChange(newPadding, oldPadding);
377 if (isComponentComplete())
383 Q_D(QQuickMonthGrid);
384 QQuickControl::updatePolish();
390 Q_D(QQuickMonthGrid);
391 if (event->timerId() == d->pressTimer) {
392 if (d->pressedDate.isValid())
393 emit pressAndHold(d->pressedDate);
394 killTimer(d->pressTimer);
400#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
Combined button and popup list for selecting options.