Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
actionprovider_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
5#ifndef ACTIONPROVIDER_H
6#define ACTIONPROVIDER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtDesigner/extension.h>
20#include <QtCore/qpoint.h>
21#include <QtCore/qrect.h>
22#include <QtWidgets/qapplication.h>
23
24QT_BEGIN_NAMESPACE
25
26class QAction;
27
29{
30public:
32
33 virtual QRect actionGeometry(QAction *action) const = 0;
34 virtual QAction *actionAt(const QPoint &pos) const = 0;
35
36 virtual void adjustIndicator(const QPoint &pos) = 0;
37};
38
39// Find action at the given position for a widget that has actionGeometry() (QToolBar,
40// QMenuBar, QMenu). They usually have actionAt(), but that fails since Designer usually sets
41// WA_TransparentForMouseEvents on the widgets.
42template <class Widget>
43 int actionIndexAt(const Widget *w, const QPoint &pos, Qt::Orientation orientation)
44{
45 const auto actions = w->actions();
46 if (actions.isEmpty())
47 return -1;
48 // actionGeometry() can be wrong sometimes; it returns a geometry that
49 // stretches to the end of the toolbar/menu bar. So, check from the beginning
50 // in the case of a horizontal right-to-left orientation.
51 const bool checkTopRight = orientation == Qt::Horizontal && w->layoutDirection() == Qt::RightToLeft;
52 const QPoint topRight = QPoint(w->rect().width(), 0);
53 for (qsizetype index = 0, actionCount = actions.size(); index < actionCount; ++index) {
54 QRect g = w->actionGeometry(actions.at(index));
55 if (checkTopRight)
56 g.setTopRight(topRight);
57 else
58 g.setTopLeft(QPoint(0, 0));
59
60 if (g.contains(pos))
61 return int(index);
62 }
63 return -1;
64}
65
66Q_DECLARE_EXTENSION_INTERFACE(QDesignerActionProviderExtension, "org.qt-project.Qt.Designer.ActionProvider")
67
68QT_END_NAMESPACE
69
70#endif // ACTIONPROVIDER_H
int actionIndexAt(const Widget *w, const QPoint &pos, Qt::Orientation orientation)
virtual ~QDesignerActionProviderExtension()=default
virtual QRect actionGeometry(QAction *action) const =0
virtual QAction * actionAt(const QPoint &pos) const =0
virtual void adjustIndicator(const QPoint &pos)=0
#define QT_FORMEDITOR_EXPORT
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QRect verticalIndicatorRect(const QRect &rect)
static QRect horizontalIndicatorRect(const QRect &rect, Qt::LayoutDirection layoutDirection)