18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "QtWidgets/qmenu.h"
21#include "QtWidgets/qmenubar.h"
23#include "QtWidgets/qstyleoption.h"
24#include "QtCore/qdatetime.h"
25#include "QtCore/qmap.h"
26#include "QtCore/qhash.h"
27#include "QtCore/qbasictimer.h"
28#include "private/qwidget_p.h"
30#include <qpa/qplatformmenu.h>
95 , m_uni_directional(
false)
96 , m_select_other_actions(
false)
97 , m_use_reset_action(true)
126 m_time.
start(m_timeout, m_menu);
180 m_reset_action =
nullptr;
181 m_use_reset_action =
true;
182 }
else if (m_reset_action != resetAction) {
183 if (m_use_reset_action && resetAction) {
185 const int resetIdx = actions.
indexOf(resetAction);
186 const int originIdx = actions.
indexOf(m_origin_action);
187 if (resetIdx > -1 && originIdx > -1 &&
qAbs(resetIdx - originIdx) > 1)
188 m_use_reset_action =
false;
190 m_reset_action = resetAction;
193 if (m_action_rect.
contains(mousePos)) {
198 if (m_uni_directional && !m_first_mouse && resetAction != m_origin_action) {
205 qreal prev_slope_top =
slope(m_previous_point, sub_menu_top);
206 qreal prev_slope_bottom =
slope(m_previous_point, sub_menu_bottom);
208 qreal current_slope_top =
slope(mousePos, sub_menu_top);
209 qreal current_slope_bottom =
slope(mousePos, sub_menu_bottom);
211 bool slopeTop =
checkSlope(prev_slope_top, current_slope_top, sub_menu_top.
y() < mousePos.
y());
212 bool slopeBottom =
checkSlope(prev_slope_bottom, current_slope_bottom, sub_menu_bottom.
y() > mousePos.
y());
213 bool rightDirection =
false;
214 int mouseDir = int(m_previous_point.
y() - mousePos.
y());
216 rightDirection = rightDirection || slopeTop;
219 rightDirection = rightDirection || slopeBottom;
222 if (m_uni_dir_discarded_count >= m_uni_dir_fail_at_count && !rightDirection) {
223 m_uni_dir_discarded_count = 0;
228 m_uni_dir_discarded_count++;
230 m_uni_dir_discarded_count = 0;
246 QMenu *m_menu =
nullptr;
247 QAction *m_reset_action =
nullptr;
248 QAction *m_origin_action =
nullptr;
254 short m_uni_dir_discarded_count = 0;
255 short m_uni_dir_fail_at_count = 0;
257 bool m_init_guard =
false;
258 bool m_first_mouse =
true;
261 bool m_uni_directional : 1;
262 bool m_select_other_actions : 1;
263 bool m_discard_state_when_entering_parent : 1;
264 bool m_dont_start_time_on_leave : 1;
265 bool m_use_reset_action : 1;
270 Q_DECLARE_PUBLIC(
QMenu)
330#ifdef QT_KEYPAD_NAVIGATION
331 QAction *selectAction =
nullptr;
332 QAction *cancelAction =
nullptr;
411 inline int indexOf(
QAction *act)
const {
return q_func()->actions().indexOf(act); }
450 QWidget *
parent =
nullptr, Qt::WindowFlags
f = Qt::WindowFlags());
The QAction class provides an abstraction for user commands that can be added to different user inter...
ActionEvent
This enum type is used when calling QAction::activate()
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
int timerId() const noexcept
Returns the timer's ID.
void stop()
Stops the timer.
bool isActive() const noexcept
Returns true if the timer is running and has not been stopped; otherwise returns false.
QObject * parent() const
Returns a pointer to the parent object.
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
\inmodule QtCore\reentrant
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr int y() const noexcept
Returns the y coordinate of this point.
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
\inmodule QtCore\reentrant
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
constexpr QPoint bottomLeft() const noexcept
Returns the position of the rectangle's bottom-left corner.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr QPoint topRight() const noexcept
Returns the position of the rectangle's top-right corner.
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
The QScreen class is used to query screen properties. \inmodule QtGui.
QSetValueOnDestroy(T &toSet, T value)
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
constexpr Policy verticalPolicy() const noexcept
Returns the vertical component of the size policy.
constexpr Policy horizontalPolicy() const noexcept
Returns the horizontal component of the size policy.
Policy
This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.
\macro QT_RESTRICTED_CAST_FROM_ASCII
@ SH_Menu_SubMenuUniDirectionFailCount
@ SH_Menu_SubMenuUniDirection
@ SH_Menu_SubMenuResetWhenReenteringParent
@ SH_Menu_SubMenuSloppySelectOtherActions
@ SH_Menu_SubMenuDontStartSloppyOnLeave
@ SH_Menu_SubMenuSloppyCloseTimeout
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyIsNull(qfloat16 f) noexcept
constexpr T qAbs(const T &t)
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
#define QT_REQUIRE_CONFIG(feature)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept