Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickpopupitem.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
6#include "qquickpage_p_p.h"
8#include "qquickpopup_p_p.h"
10
11#if QT_CONFIG(accessibility)
12#include <QtQuick/private/qquickaccessibleattached_p.h>
13#endif
14
16
17Q_LOGGING_CATEGORY(lcPopupItem, "qt.quick.controls.popupitem")
18
20 : popup(popup)
21{
22 isTabFence = true;
23}
24
26{
27 qCDebug(lcPopupItem).nospace() << "implicitWidthChanged called on " << q_func() << "; new implicitWidth is " << implicitWidth;
30}
31
33{
34 qCDebug(lcPopupItem).nospace() << "implicitHeightChanged called on " << q_func() << "; new implicitHeight is " << implicitHeight;
37}
38
40{
41 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(popup->window()))
42 inheritFont(window->font());
43 else
45}
46
48{
49 Q_Q(QQuickPopupItem);
51 return item;
52
53 return new QQuickContentItem(popup, q);
54}
55
56static inline QString contentItemName() { return QStringLiteral("contentItem"); }
57
59{
61}
62
64{
66 return;
67
68 if (!contentItem || complete)
70 if (complete)
72}
73
75{
77}
78
80{
82 return;
83
84 if (!background || complete)
86 if (complete)
88}
89
92{
93 setParent(popup);
96#if QT_CONFIG(quicktemplates2_multitouch)
98#endif
99#if QT_CONFIG(cursor)
101#endif
102
103 connect(popup, &QQuickPopup::paletteChanged, this, &QQuickItem::paletteChanged);
104 connect(popup, &QQuickPopup::paletteCreated, this, &QQuickItem::paletteCreated);
105
106#if QT_CONFIG(quicktemplates2_hover)
107 // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8
108 setHoverEnabled(true);
109 // setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects());
110 // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, this, &QQuickItem::setAcceptHoverEvents);
111#endif
112}
113
115{
117}
118
120{
122}
123
125{
127}
128
130{
132}
133
135{
137}
138
140{
141 return QQuickPopupPrivate::get(popup)->parentPalette(fallbackPalette);
142}
143
145{
146 Q_D(QQuickPopupItem);
147 return QQuickPopupPrivate::get(d->popup)->reposition();
148}
149
151{
152 Q_D(QQuickPopupItem);
153 return d->popup->childMouseEventFilter(child, event);
154}
155
157{
158 Q_D(QQuickPopupItem);
159 d->popup->focusInEvent(event);
160}
161
163{
164 Q_D(QQuickPopupItem);
165 d->popup->focusOutEvent(event);
166}
167
169{
170 Q_D(QQuickPopupItem);
171 d->popup->keyPressEvent(event);
172}
173
175{
176 Q_D(QQuickPopupItem);
177 d->popup->keyReleaseEvent(event);
178}
179
181{
182 Q_D(QQuickPopupItem);
183 d->popup->mousePressEvent(event);
184}
185
187{
188 Q_D(QQuickPopupItem);
189 d->popup->mouseMoveEvent(event);
190}
191
193{
194 Q_D(QQuickPopupItem);
195 d->popup->mouseReleaseEvent(event);
196}
197
199{
200 Q_D(QQuickPopupItem);
201 d->popup->mouseDoubleClickEvent(event);
202}
203
205{
206 Q_D(QQuickPopupItem);
207 d->popup->mouseUngrabEvent();
208}
209
210#if QT_CONFIG(quicktemplates2_multitouch)
212{
213 Q_D(QQuickPopupItem);
214 d->popup->touchEvent(event);
215}
216
218{
219 Q_D(QQuickPopupItem);
220 d->popup->touchUngrabEvent();
221}
222#endif
223
224#if QT_CONFIG(wheelevent)
225void QQuickPopupItem::wheelEvent(QWheelEvent *event)
226{
227 Q_D(QQuickPopupItem);
228 d->popup->wheelEvent(event);
229}
230#endif
231
233{
234 Q_D(QQuickPopupItem);
235 QQuickPage::contentItemChange(newItem, oldItem);
236 d->popup->contentItemChange(newItem, oldItem);
237}
238
239void QQuickPopupItem::contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
240{
241 Q_D(QQuickPopupItem);
242 qCDebug(lcPopupItem) << "contentSizeChange called on" << this << "newSize" << newSize << "oldSize" << oldSize;
243 QQuickPage::contentSizeChange(newSize, oldSize);
244 d->popup->contentSizeChange(newSize, oldSize);
245}
246
247void QQuickPopupItem::fontChange(const QFont &newFont, const QFont &oldFont)
248{
249 Q_D(QQuickPopupItem);
250 QQuickPage::fontChange(newFont, oldFont);
251 d->popup->fontChange(newFont, oldFont);
252}
253
254void QQuickPopupItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
255{
256 Q_D(QQuickPopupItem);
257 qCDebug(lcPopupItem) << "geometryChange called on" << this << "newGeometry" << newGeometry << "oldGeometry" << oldGeometry;
258 QQuickPage::geometryChange(newGeometry, oldGeometry);
259 d->popup->geometryChange(newGeometry, oldGeometry);
260}
261
262void QQuickPopupItem::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
263{
264 Q_D(QQuickPopupItem);
265 QQuickPage::localeChange(newLocale, oldLocale);
266 d->popup->localeChange(newLocale, oldLocale);
267}
268
270{
271 Q_D(QQuickPopupItem);
272 emit d->popup->mirroredChanged();
273}
274
276{
277 Q_D(QQuickPopupItem);
279 d->popup->itemChange(change, data);
280}
281
282void QQuickPopupItem::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
283{
284 Q_D(QQuickPopupItem);
285 QQuickPage::paddingChange(newPadding, oldPadding);
286 d->popup->paddingChange(newPadding, oldPadding);
287}
288
290{
291 Q_D(QQuickPopupItem);
292 // Just having QQuickPopup connect our QQuickItem::enabledChanged() signal
293 // to its enabledChanged() signal is enough for the enabled property to work,
294 // but we must also ensure that its paletteChanged() signal is emitted
295 // so that bindings to palette are re-evaluated, because QQuickControl::palette()
296 // returns a different palette depending on whether or not the control is enabled.
297 // To save a connection, we also emit enabledChanged here.
298 emit d->popup->enabledChanged();
299}
300
302{
303 Q_D(const QQuickPopupItem);
304 return d->popup->defaultFont();
305}
306
307#if QT_CONFIG(accessibility)
308QAccessible::Role QQuickPopupItem::accessibleRole() const
309{
310 Q_D(const QQuickPopupItem);
311 return d->popup->effectiveAccessibleRole();
312}
313
314void QQuickPopupItem::accessibilityActiveChanged(bool active)
315{
316 Q_D(const QQuickPopupItem);
317 // Can't just use d->popup->accessibleName() here, because that refers to the accessible
318 // name of us, the popup item, which is not what we want.
319 const QQuickAccessibleAttached *popupAccessibleAttached = QQuickControlPrivate::accessibleAttached(d->popup);
320 const QString oldPopupName = popupAccessibleAttached ? popupAccessibleAttached->name() : QString();
321 const bool wasNameExplicitlySetOnPopup = popupAccessibleAttached && popupAccessibleAttached->wasNameExplicitlySet();
322
323 QQuickPage::accessibilityActiveChanged(active);
324
325 QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this);
326 const QString ourName = accessibleAttached ? accessibleAttached->name() : QString();
327 if (wasNameExplicitlySetOnPopup && accessibleAttached && ourName != oldPopupName) {
328 // The user set Accessible.name on the Popup. Since the Popup and its popup item
329 // have different accessible attached properties, the popup item doesn't know that
330 // a name was set on the Popup by the user, and that it should use that, rather than
331 // whatever QQuickPage sets. That's why we need to do it here.
332 // To avoid it being overridden by the call to accessibilityActiveChanged() below,
333 // we set it explicitly. It's safe to do this as the popup item is an internal implementation detail.
334 accessibleAttached->setName(oldPopupName);
335 }
336
337 // This allows the different popup types to set a name on their popup item accordingly.
338 // For example: Dialog uses its title and ToolTip uses its text.
339 d->popup->accessibilityActiveChanged(active);
340}
341#endif
342
344
345#include "moc_qquickpopupitem_p_p.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant
Definition qfont.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:423
\inmodule QtCore
Definition qmargins.h:274
\inmodule QtGui
Definition qevent.h:195
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
QQuickDeferredPointer< QQuickItem > background
QQuickDeferredPointer< QQuickItem > contentItem
virtual QQuickItem * getContentItem()
void inheritFont(const QFont &font)
virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
void setHoverEnabled(bool enabled)
virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale)
virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
virtual void fontChange(const QFont &newFont, const QFont &oldFont)
virtual void implicitHeightChanged()
QQuickWindow * window
virtual void implicitWidthChanged()
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
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...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void setAcceptTouchEvents(bool accept)
If enabled is true, this sets the item to accept touch events; otherwise, touch events are not accept...
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
virtual void touchUngrabEvent()
This event handler can be reimplemented in a subclass to be notified when a touch ungrab event has oc...
virtual void touchEvent(QTouchEvent *event)
This event handler can be reimplemented in a subclass to receive touch events for an item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
friend class QQuickAccessibleAttached
Definition qquickitem.h:474
QPalette parentPalette(const QPalette &fallbackPalette) const override
Contains color groups for each QML item state. \inmodule QtQuick.
virtual void contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
void implicitWidthChanged() override
void executeContentItem(bool complete=false) override
void resolveFont() override
QPalette defaultPalette() const override
bool providesPalette() const override
void implicitHeightChanged() override
void setPalette(QQuickPalette *p) override
QQuickItem * getContentItem() override
QQuickPalette * palette() const override
QPalette parentPalette(const QPalette &fallbackPalette) const override
void cancelContentItem() override
void cancelBackground() override
void executeBackground(bool complete=false) override
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize) override
void mouseDoubleClickEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse double-click events for an ite...
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override
void mouseReleaseEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
void updatePolish() override
This function should perform any layout as required for this item.
void focusOutEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
void focusInEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
bool childMouseEventFilter(QQuickItem *child, QEvent *event) override
Reimplement this method to filter the pointer events that are received by this item's children.
QQuickPopupItem(QQuickPopup *popup)
void mousePressEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
void mouseUngrabEvent() override
This event handler can be reimplemented in a subclass to be notified when a mouse ungrab event has oc...
QFont defaultFont() const override
void itemChange(ItemChange change, const ItemChangeData &data) override
Called when change occurs for this item.
void fontChange(const QFont &newFont, const QFont &oldFont) override
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
void mouseMoveEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
void mirrorChange() override
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override
void enabledChange() override
QPalette defaultPalette() const override
static QQuickPopupPrivate * get(QQuickPopup *popup)
void implicitWidthChanged()
void implicitHeightChanged()
static QFont font(Scope scope)
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore
Definition qsize.h:207
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:916
Combined button and popup list for selecting options.
@ AllButtons
Definition qnamespace.h:89
@ ArrowCursor
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
static QString contentItemName()
void quickCancelDeferred(QObject *object, const QString &property)
void quickCompleteDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
void quickBeginDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
static QString contentItemName()
#define QStringLiteral(str)
#define emit
static QString backgroundName()
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QObject::connect nullptr
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
QLayoutItem * child
[0]
file setParent(multiPart)
\inmodule QtQuick
Definition qquickitem.h:158