Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickmonthgrid.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qquickmonthgrid_p.h"
5
6#include <QtGui/qstylehints.h>
7#include <QtGui/qguiapplication.h>
8#include <QtQuickTemplates2/private/qquickcontrol_p_p.h>
9#include <QtQml/qqmlinfo.h>
10
12
17
76{
77 Q_DECLARE_PUBLIC(QQuickMonthGrid)
78
79public:
81
82 void resizeItems();
83
84 QQuickItem *cellAt(const QPointF &pos) const;
85 QDate dateOf(QQuickItem *cell) const;
86
87 void updatePress(const QPointF &pos);
88 void clearPress(bool clicked);
89
90 bool handlePress(const QPointF &point, ulong timestamp) override;
91 bool handleMove(const QPointF &point, ulong timestamp) override;
92 bool handleRelease(const QPointF &point, ulong timestamp) override;
93 void handleUngrab() override;
94
102};
103
105{
106 if (!contentItem)
107 return;
108
109 QSizeF itemSize;
110 itemSize.setWidth((contentItem->width() - 6 * spacing) / 7);
111 itemSize.setHeight((contentItem->height() - 5 * spacing) / 6);
112
113 const auto childItems = contentItem->childItems();
114 for (QQuickItem *item : childItems) {
115 if (!QQuickItemPrivate::get(item)->isTransparentForPositioner())
116 item->setSize(itemSize);
117 }
118}
119
121{
122 Q_Q(const QQuickMonthGrid);
123 if (contentItem) {
124 QPointF mapped = q->mapToItem(contentItem, pos);
125 return contentItem->childAt(mapped.x(), mapped.y());
126 }
127 return nullptr;
128}
129
131{
132 if (contentItem)
133 return model->dateAt(contentItem->childItems().indexOf(cell));
134 return QDate();
135}
136
146
148{
149 Q_Q(QQuickMonthGrid);
150 if (pressedDate.isValid()) {
151 emit q->released(pressedDate);
152 if (clicked)
153 emit q->clicked(pressedDate);
154 }
155 pressedDate = QDate();
156 pressedItem = nullptr;
157}
158
160{
161 Q_Q(QQuickMonthGrid);
162 QQuickControlPrivate::handlePress(point, timestamp);
163 updatePress(point);
164 if (pressedDate.isValid())
165 pressTimer = q->startTimer(qGuiApp->styleHints()->mousePressAndHoldInterval());
166 return true;
167}
168
170{
171 QQuickControlPrivate::handleMove(point, timestamp);
172 updatePress(point);
173 return true;
174}
175
177{
178 QQuickControlPrivate::handleRelease(point, timestamp);
179 clearPress(true);
180 return true;
181}
182
188
206
218{
219 Q_D(const QQuickMonthGrid);
220 return d->model->month() - 1;
221}
222
224{
225 Q_D(QQuickMonthGrid);
226 if (month < 0 || month > 11) {
227 qmlWarning(this) << "month " << month << " is out of range [0...11]";
228 return;
229 }
230 d->model->setMonth(month + 1);
231}
232
242{
243 Q_D(const QQuickMonthGrid);
244 return d->model->year();
245}
246
248{
249 Q_D(QQuickMonthGrid);
250 if (year < -271820 || year > 275759) {
251 qmlWarning(this) << "year " << year << " is out of range [-271820...275759]";
252 return;
253 }
254 d->model->setYear(year);
255}
256
265{
266 Q_D(const QQuickMonthGrid);
267 return d->source;
268}
269
271{
272 Q_D(QQuickMonthGrid);
273 if (d->source != source) {
274 d->source = source;
276 }
277}
278
289{
290 Q_D(const QQuickMonthGrid);
291 if (d->title.isNull())
292 return d->model->title();
293 return d->title;
294}
295
297{
298 Q_D(QQuickMonthGrid);
299 if (d->title != title) {
300 d->title = title;
302 }
303}
304
328{
329 Q_D(const QQuickMonthGrid);
330 return d->delegate;
331}
332
334{
335 Q_D(QQuickMonthGrid);
336 if (d->delegate != delegate) {
337 d->delegate = delegate;
339 }
340}
341
343{
344 Q_D(QQuickMonthGrid);
346 d->resizeItems();
347}
348
349void QQuickMonthGrid::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
350{
351 Q_D(QQuickMonthGrid);
352 QQuickControl::geometryChange(newGeometry, oldGeometry);
354 d->resizeItems();
355}
356
357void QQuickMonthGrid::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
358{
359 Q_D(QQuickMonthGrid);
360 QQuickControl::localeChange(newLocale, oldLocale);
361 d->model->setLocale(newLocale);
362}
363
364void QQuickMonthGrid::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
365{
366 Q_D(QQuickMonthGrid);
367 QQuickControl::paddingChange(newPadding, oldPadding);
369 d->resizeItems();
370}
371
373{
374 Q_D(QQuickMonthGrid);
376 d->resizeItems();
377}
378
380{
381 Q_D(QQuickMonthGrid);
382 if (event->timerId() == d->pressTimer) {
383 if (d->pressedDate.isValid())
384 emit pressAndHold(d->pressedDate);
385 killTimer(d->pressTimer);
386 }
387}
388
390
391#include "moc_qquickmonthgrid_p.cpp"
\inmodule QtCore \reentrant
Definition qdatetime.h:29
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition qdatetime.h:71
\inmodule QtCore
Definition qmargins.h:270
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition qobject.cpp:1912
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QQmlComponent class encapsulates a QML component definition.
virtual bool handlePress(const QPointF &point, ulong timestamp)
QQuickDeferredPointer< QQuickItem > contentItem
virtual void handleUngrab()
virtual bool handleRelease(const QPointF &point, ulong timestamp)
virtual bool handleMove(const QPointF &point, ulong timestamp)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
static QQuickItemPrivate * get(QQuickItem *item)
QList< QQuickItem * > childItems
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QList< QQuickItem * > childItems() const
Returns the children of this item.
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
Q_INVOKABLE QQuickItem * childAt(qreal x, qreal y) const
\qmlmethod QtQuick::Item::childAt(real x, real y)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
virtual void updatePolish()
This function should perform any layout as required for this item.
void setActiveFocusOnTab(bool)
A grid of days for a calendar month.
bool handleRelease(const QPointF &point, ulong timestamp) override
bool handlePress(const QPointF &point, ulong timestamp) override
QQuickMonthModel * model
QQuickItem * cellAt(const QPointF &pos) const
QDate dateOf(QQuickItem *cell) const
bool handleMove(const QPointF &point, ulong timestamp) override
void clearPress(bool clicked)
void updatePress(const QPointF &pos)
void pressAndHold(QDate date)
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
QQmlComponent * delegate
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setTitle(const QString &title)
QQuickMonthGrid(QQuickItem *parent=nullptr)
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void setSource(const QVariant &source)
void setDelegate(QQmlComponent *delegate)
void delegateChanged()
void setMonth(int month)
void updatePolish() override
This function should perform any layout as required for this item.
void sourceChanged()
void setYear(int year)
Q_INVOKABLE QDate dateAt(int index) const
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:208
constexpr void setHeight(qreal h) noexcept
Sets the height to the given finite height.
Definition qsize.h:341
constexpr void setWidth(qreal w) noexcept
Sets the width to the given finite width.
Definition qsize.h:338
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
\inmodule QtCore
Definition qvariant.h:65
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
@ ArrowCursor
#define qGuiApp
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define emit
unsigned long ulong
Definition qtypes.h:35
QObject::connect nullptr
QString title
[35]
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962