Qt 6.x
The Qt SDK
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
87{
89}
90
93{
95}
96
105{
106 Q_D(const QQuickMenuBarItem);
107 return d->menuBar;
108}
109
117{
118 Q_D(const QQuickMenuBarItem);
119 return d->menu;
120}
121
123{
125 if (d->menu == menu)
126 return;
127
128 if (d->menu)
130
131 if (menu) {
132 setText(menu->title());
133 menu->setY(height());
134 menu->setParentItem(this);
135 menu->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent | QQuickPopup::CloseOnReleaseOutsideParent);
137 }
138
139 d->menu = menu;
141}
142
153{
154 Q_D(const QQuickMenuBarItem);
155 return d->highlighted;
156}
157
159{
161 if (highlighted == d->highlighted)
162 return;
163
164 d->highlighted = highlighted;
166}
167
169{
170#if QT_CONFIG(shortcut)
172 if (event->type() == QEvent::Shortcut) {
173 auto *shortcutEvent = static_cast<QShortcutEvent *>(event);
174 if (shortcutEvent->shortcutId() == d->shortcutId) {
175 d->trigger();
176 emit triggered();
177 return true;
178 }
179 }
180#endif
182}
183
185{
188 if (d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
189 d->setPressPoint(d->centerPressPoint());
190 setPressed(true);
191 emit pressed();
192 event->accept();
193 }
194}
195
197{
200 if (d->pressed && d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
201 setPressed(false);
202 emit released();
203 d->trigger();
204 // We override these event functions so that we can emit triggered here.
205 // We can't just connect clicked to triggered, because that would cause mouse clicks
206 // to open the menu, when only presses should.
207 emit triggered();
208 event->accept();
209 }
210}
211
212void QQuickMenuBarItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
213{
215 QQuickAbstractButton::geometryChange(newGeometry, oldGeometry);
216 if (d->menu)
217 d->menu->setY(newGeometry.height());
218}
219
221{
223}
224
225#if QT_CONFIG(accessibility)
226QAccessible::Role QQuickMenuBarItem::accessibleRole() const
227{
228 return QAccessible::MenuBar;
229}
230#endif
231
233
234#include "moc_qquickmenubaritem_p.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
\reentrant
Definition qfont.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:423
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:1363
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:214
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)
void setFocusPolicy(Qt::FocusPolicy policy)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
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:77
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
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:483
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
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:106
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
unsigned long ulong
Definition qtypes.h:30
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
QMenu menu
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent