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
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 return popupItem->d_func();
28}
29
31{
32 qCDebug(lcPopupItem).nospace() << "implicitWidthChanged called on " << q_func() << "; new implicitWidth is " << implicitWidth;
35}
36
38{
39 qCDebug(lcPopupItem).nospace() << "implicitHeightChanged called on " << q_func() << "; new implicitHeight is " << implicitHeight;
42}
43
45{
46 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(popup->window()))
47 inheritFont(window->font());
48 else
50}
51
60
61static inline QString contentItemName() { return QStringLiteral("contentItem"); }
62
67
69{
71 return;
72
73 if (!contentItem || complete)
75 if (complete)
77}
78
83
85{
87 return;
88
89 if (!background || complete)
91 if (complete)
93}
94
97{
98 setParent(popup);
101#if QT_CONFIG(quicktemplates2_multitouch)
103#endif
104#if QT_CONFIG(cursor)
106#endif
107
108 connect(popup, &QQuickPopup::paletteChanged, this, &QQuickItem::paletteChanged);
109 connect(popup, &QQuickPopup::paletteCreated, this, &QQuickItem::paletteCreated);
110
111#if QT_CONFIG(quicktemplates2_hover)
112 // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8
113 setHoverEnabled(true);
114 // setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects());
115 // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, this, &QQuickItem::setAcceptHoverEvents);
116#endif
117}
118
123
128
133
135{
136 return QQuickPopupPrivate::get(popup)->defaultPalette();
137}
138
140{
141 return QQuickPopupPrivate::get(popup)->providesPalette();
142}
143
145{
146 return QQuickPopupPrivate::get(popup)->parentPalette(fallbackPalette);
147}
148
150{
151 Q_D(QQuickPopupItem);
152 return QQuickPopupPrivate::get(d->popup)->reposition();
153}
154
156{
157 Q_D(QQuickPopupItem);
158 return d->popup->childMouseEventFilter(child, event);
159}
160
162{
163 Q_D(QQuickPopupItem);
164 d->popup->focusInEvent(event);
165}
166
168{
169 Q_D(QQuickPopupItem);
170 d->popup->focusOutEvent(event);
171}
172
174{
175 Q_D(QQuickPopupItem);
176 d->popup->keyPressEvent(event);
177}
178
180{
181 Q_D(QQuickPopupItem);
182 d->popup->keyReleaseEvent(event);
183}
184
186{
187 Q_D(QQuickPopupItem);
188 d->popup->mousePressEvent(event);
189}
190
192{
193 Q_D(QQuickPopupItem);
194 d->popup->mouseMoveEvent(event);
195}
196
198{
199 Q_D(QQuickPopupItem);
200 d->popup->mouseReleaseEvent(event);
201}
202
204{
205 Q_D(QQuickPopupItem);
206 d->popup->mouseDoubleClickEvent(event);
207}
208
210{
211 Q_D(QQuickPopupItem);
212 d->popup->mouseUngrabEvent();
213}
214
215#if QT_CONFIG(quicktemplates2_multitouch)
217{
218 Q_D(QQuickPopupItem);
219 d->popup->touchEvent(event);
220}
221
223{
224 Q_D(QQuickPopupItem);
225 d->popup->touchUngrabEvent();
226}
227#endif
228
229#if QT_CONFIG(wheelevent)
230void QQuickPopupItem::wheelEvent(QWheelEvent *event)
231{
232 Q_D(QQuickPopupItem);
233 d->popup->wheelEvent(event);
234}
235#endif
236
238{
239 Q_D(QQuickPopupItem);
240 QQuickPage::contentItemChange(newItem, oldItem);
241 d->popup->contentItemChange(newItem, oldItem);
242}
243
244void QQuickPopupItem::contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
245{
246 Q_D(QQuickPopupItem);
247 qCDebug(lcPopupItem) << "contentSizeChange called on" << this << "newSize" << newSize << "oldSize" << oldSize;
248 QQuickPage::contentSizeChange(newSize, oldSize);
249 d->popup->contentSizeChange(newSize, oldSize);
250}
251
252void QQuickPopupItem::fontChange(const QFont &newFont, const QFont &oldFont)
253{
254 Q_D(QQuickPopupItem);
255 QQuickPage::fontChange(newFont, oldFont);
256 d->popup->fontChange(newFont, oldFont);
257}
258
259void QQuickPopupItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
260{
261 Q_D(QQuickPopupItem);
262 qCDebug(lcPopupItem) << "geometryChange called on" << this << "newGeometry" << newGeometry << "oldGeometry" << oldGeometry;
263 QQuickPage::geometryChange(newGeometry, oldGeometry);
264 d->popup->geometryChange(newGeometry, oldGeometry);
265}
266
267void QQuickPopupItem::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
268{
269 Q_D(QQuickPopupItem);
270 QQuickPage::localeChange(newLocale, oldLocale);
271 d->popup->localeChange(newLocale, oldLocale);
272}
273
275{
276 Q_D(QQuickPopupItem);
277 emit d->popup->mirroredChanged();
278}
279
281{
282 Q_D(QQuickPopupItem);
284 d->popup->itemChange(change, data);
285}
286
287void QQuickPopupItem::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
288{
289 Q_D(QQuickPopupItem);
290 QQuickPage::paddingChange(newPadding, oldPadding);
291 d->popup->paddingChange(newPadding, oldPadding);
292}
293
295{
296 Q_D(QQuickPopupItem);
297 // Just having QQuickPopup connect our QQuickItem::enabledChanged() signal
298 // to its enabledChanged() signal is enough for the enabled property to work,
299 // but we must also ensure that its paletteChanged() signal is emitted
300 // so that bindings to palette are re-evaluated, because QQuickControl::palette()
301 // returns a different palette depending on whether or not the control is enabled.
302 // To save a connection, we also emit enabledChanged here.
303 emit d->popup->enabledChanged();
304}
305
307{
308 Q_D(const QQuickPopupItem);
309 return d->popup->defaultFont();
310}
311
312#if QT_CONFIG(accessibility)
313QAccessible::Role QQuickPopupItem::accessibleRole() const
314{
315 Q_D(const QQuickPopupItem);
316 return d->popup->effectiveAccessibleRole();
317}
318
319void QQuickPopupItem::accessibilityActiveChanged(bool active)
320{
321 Q_D(const QQuickPopupItem);
322 // Can't just use d->popup->accessibleName() here, because that refers to the accessible
323 // name of us, the popup item, which is not what we want.
324 const QQuickAccessibleAttached *popupAccessibleAttached = QQuickControlPrivate::accessibleAttached(d->popup);
325 const QString oldPopupName = popupAccessibleAttached ? popupAccessibleAttached->name() : QString();
326 const bool wasNameExplicitlySetOnPopup = popupAccessibleAttached && popupAccessibleAttached->wasNameExplicitlySet();
327
328 QQuickPage::accessibilityActiveChanged(active);
329
330 QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this);
331 const QString ourName = accessibleAttached ? accessibleAttached->name() : QString();
332 if (wasNameExplicitlySetOnPopup && accessibleAttached && ourName != oldPopupName) {
333 // The user set Accessible.name on the Popup. Since the Popup and its popup item
334 // have different accessible attached properties, the popup item doesn't know that
335 // a name was set on the Popup by the user, and that it should use that, rather than
336 // whatever QQuickPage sets. That's why we need to do it here.
337 // To avoid it being overridden by the call to accessibilityActiveChanged() below,
338 // we set it explicitly. It's safe to do this as the popup item is an internal implementation detail.
339 accessibleAttached->setName(oldPopupName);
340 }
341
342 // This allows the different popup types to set a name on their popup item accordingly.
343 // For example: Dialog uses its title and ToolTip uses its text.
344 d->popup->accessibilityActiveChanged(active);
345}
346#endif
347
349
350#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:470
\reentrant
Definition qfont.h:22
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtCore
Definition qmargins.h:270
\inmodule QtGui
Definition qevent.h:196
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:63
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:144
friend class QQuickAccessibleAttached
Definition qquickitem.h:479
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
static QQuickPopupItemPrivate * get(QQuickPopupItem *popupItem)
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
static QQuickPopupPrivate * get(QQuickPopup *popup)
void implicitWidthChanged()
void implicitHeightChanged()
static QFont font(Scope scope)
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
Combined button and popup list for selecting options.
@ AllButtons
Definition qnamespace.h:90
@ 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:159