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
qquickmenuitem.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
4#include "qquickmenuitem_p.h"
6#include "qquickmenu_p.h"
8
9#include <QtGui/qpa/qplatformtheme.h>
10#include <QtQuick/private/qquickevents_p_p.h>
11
13
18
60{
61 Q_Q(QQuickMenuItem);
62 if (menu == newMenu)
63 return;
64
65 menu = newMenu;
66 emit q->menuChanged();
67}
68
70{
71 Q_Q(QQuickMenuItem);
72 if (subMenu == newSubMenu)
73 return;
74
75 if (subMenu) {
77 QObject::disconnect(subMenu, &QQuickMenu::iconChanged, q, &QQuickAbstractButton::setIcon);
78 QObjectPrivate::disconnect(subMenu, &QQuickPopup::enabledChanged, this, &QQuickMenuItemPrivate::updateEnabled);
79 }
80
81 if (newSubMenu) {
83 QObject::connect(newSubMenu, &QQuickMenu::iconChanged, q, &QQuickAbstractButton::setIcon);
84 QObjectPrivate::connect(newSubMenu, &QQuickPopup::enabledChanged, this, &QQuickMenuItemPrivate::updateEnabled);
85 q->setText(newSubMenu->title());
86 q->setIcon(newSubMenu->icon());
87 }
88
89 subMenu = newSubMenu;
91 emit q->subMenuChanged();
92}
93
95{
96 Q_Q(QQuickMenuItem);
97 q->setEnabled(subMenu && subMenu->isEnabled());
98}
99
100static inline QString arrowName() { return QStringLiteral("arrow"); }
101
107
109{
110 Q_Q(QQuickMenuItem);
111 if (arrow.wasExecuted())
112 return;
113
114 if (!arrow || complete)
116 if (complete)
118}
119
125
130
142
155{
156 Q_D(const QQuickMenuItem);
157 return d->highlighted;
158}
159
160void QQuickMenuItem::setHighlighted(bool highlighted)
161{
162 Q_D(QQuickMenuItem);
163 if (highlighted == d->highlighted)
164 return;
165
166 d->highlighted = highlighted;
168}
169
179{
180 QQuickMenuItemPrivate *d = const_cast<QQuickMenuItemPrivate *>(d_func());
181 if (!d->arrow)
182 d->executeArrow();
183 return d->arrow;
184}
185
187{
188 Q_D(QQuickMenuItem);
189 if (d->arrow == arrow)
190 return;
191
192 if (!d->arrow.isExecuting())
193 d->cancelArrow();
194
196 d->arrow = arrow;
197 if (arrow && !arrow->parentItem())
198 arrow->setParentItem(this);
199 if (!d->arrow.isExecuting())
200 emit arrowChanged();
201}
202
212{
213 Q_D(const QQuickMenuItem);
214 return d->menu;
215}
216
226{
227 Q_D(const QQuickMenuItem);
228 return d->subMenu;
229}
230
232{
233 Q_D(QQuickMenuItem);
234 d->executeArrow(true);
236}
237
242
243#if QT_CONFIG(accessibility)
244QAccessible::Role QQuickMenuItem::accessibleRole() const
245{
246 return QAccessible::MenuItem;
247}
248#endif
249
251
252#include "moc_qquickmenuitem_p.cpp"
\reentrant
Definition qfont.h:22
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
Definition qobject_p.h:328
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
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
virtual bool acceptKeyClick(Qt::Key key) const
void setIcon(const QQuickIcon &icon)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setText(const QString &text)
static void hideOldItem(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setParentItem(QQuickItem *parent)
QQuickItem * parentItem() const
QPalette defaultPalette() const override
void setMenu(QQuickMenu *menu)
Presents an item within a Menu.
void setSubMenu(QQuickMenu *subMenu)
void executeArrow(bool complete=false)
QQuickDeferredPointer< QQuickItem > arrow
bool acceptKeyClick(Qt::Key key) const override
void setHighlighted(bool highlighted)
QFont defaultFont() const override
bool isHighlighted() const
\qmlproperty bool QtQuick.Controls::MenuItem::highlighted
QQuickMenuItem(QQuickItem *parent=nullptr)
\qmlsignal void QtQuick.Controls::MenuItem::triggered()
QQuickItem * arrow
void setArrow(QQuickItem *arrow)
QQuickMenu * menu
void highlightedChanged()
QQuickMenu * subMenu
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void titleChanged(const QString &title)
static QPalette palette(Scope scope)
static QFont font(Scope scope)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
@ Key_Return
Definition qnamespace.h:667
@ Key_Enter
Definition qnamespace.h:668
GLuint64 key
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
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 arrowName()
#define QStringLiteral(str)
#define emit
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)