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
qquickmenubaritem.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 "qquickmenubar_p.h"
7#include "qquickmenu_p.h"
8
10
15
40{
42 if (menuBar == newMenuBar)
43 return;
44
45 menuBar = newMenuBar;
46 emit q->menuBarChanged();
47}
48
50{
52 const bool handled = QQuickAbstractButtonPrivate::handlePress(point, timestamp);
53 if (!handled)
54 return false;
55
56 const bool wasTouchPress = touchId != -1;
57 if (!wasTouchPress) {
58 // Open the menu when it's a mouse press.
59 emit q->triggered();
60 }
61
62 return true;
63}
64
66{
68 const bool wasTouchPress = touchId != -1;
69 const bool handled = QQuickAbstractButtonPrivate::handleRelease(point, timestamp);
70 if (!handled)
71 return false;
72
73 if (wasDoubleClick || !wasTouchPress) {
74 // Don't open the menu on mouse release, as it should be done on press.
75 return handled;
76 }
77
78 if (wasTouchPress) {
79 // Open the menu.
80 emit q->triggered();
81 }
82
83 return true;
84}
85
90
97
106{
107 Q_D(const QQuickMenuBarItem);
108 return d->menuBar;
109}
110
118{
119 Q_D(const QQuickMenuBarItem);
120 return d->menu;
121}
122
124{
126 if (d->menu == menu)
127 return;
128
129 if (d->menu)
131
132 if (menu) {
133 setText(menu->title());
134 menu->setY(height());
135 menu->setParentItem(this);
136 menu->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent | QQuickPopup::CloseOnReleaseOutsideParent);
138 }
139
140 d->menu = menu;
142}
143
154{
155 Q_D(const QQuickMenuBarItem);
156 return d->highlighted;
157}
158
160{
162 if (highlighted == d->highlighted)
163 return;
164
165 d->highlighted = highlighted;
167}
168
170{
171#if QT_CONFIG(shortcut)
173 if (event->type() == QEvent::Shortcut) {
174 auto *shortcutEvent = static_cast<QShortcutEvent *>(event);
175 if (shortcutEvent->shortcutId() == d->shortcutId) {
176 d->trigger();
177 emit triggered();
178 return true;
179 }
180 }
181#endif
183}
184
186{
189 if (d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
190 d->setPressPoint(d->centerPressPoint());
191 setPressed(true);
192 emit pressed();
193 event->accept();
194 }
195}
196
198{
201 if (d->pressed && d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
202 setPressed(false);
203 emit released();
204 d->trigger();
205 // We override these event functions so that we can emit triggered here.
206 // We can't just connect clicked to triggered, because that would cause mouse clicks
207 // to open the menu, when only presses should.
208 emit triggered();
209 event->accept();
210 }
211}
212
213void QQuickMenuBarItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
214{
216 QQuickAbstractButton::geometryChange(newGeometry, oldGeometry);
217 if (d->menu)
218 d->menu->setY(newGeometry.height());
219}
220
225
226#if QT_CONFIG(accessibility)
227QAccessible::Role QQuickMenuBarItem::accessibleRole() const
228{
229 return QAccessible::MenuBar;
230}
231#endif
232
234
235#include "moc_qquickmenubaritem_p.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
\reentrant
Definition qfont.h:22
The QKeyEvent class describes a key event.
Definition qevent.h:424
static constexpr Policy Fixed
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:217
bool handlePress(const QPointF &point, ulong timestamp) override
bool handleRelease(const QPointF &point, ulong timestamp) override
void setText(const QString &text)
void setPressed(bool pressed)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
void setFocusPolicy(Qt::FocusPolicy policy)
Sets the focus policy of this item to policy.
bool handleRelease(const QPointF &point, ulong timestamp) override
QPalette defaultPalette() const override
void setMenuBar(QQuickMenuBar *menuBar)
Presents a drop-down menu within a MenuBar.
bool handlePress(const QPointF &point, ulong timestamp) override
bool isHighlighted() const
\qmlproperty bool QtQuick.Controls::MenuBarItem::highlighted
QQuickMenuBarItem(QQuickItem *parent=nullptr)
void setHighlighted(bool highlighted)
QFont defaultFont() const override
void highlightedChanged()
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
QQuickMenuBar * menuBar
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void setMenu(QQuickMenu *menu)
QString title
void titleChanged(const QString &title)
static QPalette palette(Scope scope)
static QFont font(Scope scope)
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
Combined button and popup list for selecting options.
@ NoFocus
Definition qnamespace.h:107
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
unsigned long ulong
Definition qtypes.h:35
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
QMenu menu
[5]