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
4#ifndef ACTIONPROVIDER_H
5#define ACTIONPROVIDER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtDesigner/extension.h>
19#include <QtCore/qpoint.h>
20#include <QtCore/qrect.h>
21#include <QtWidgets/qapplication.h>
22
23QT_BEGIN_NAMESPACE
24
25class QAction;
26
28{
29public:
31
32 virtual QRect actionGeometry(QAction *action) const = 0;
33 virtual QAction *actionAt(const QPoint &pos) const = 0;
34
35 virtual void adjustIndicator(const QPoint &pos) = 0;
36};
37
38// Find action at the given position for a widget that has actionGeometry() (QToolBar,
39// QMenuBar, QMenu). They usually have actionAt(), but that fails since Designer usually sets
40// WA_TransparentForMouseEvents on the widgets.
41template <class Widget>
42 int actionIndexAt(const Widget *w, const QPoint &pos, Qt::Orientation orientation)
43{
44 const auto actions = w->actions();
45 if (actions.isEmpty())
46 return -1;
47 // actionGeometry() can be wrong sometimes; it returns a geometry that
48 // stretches to the end of the toolbar/menu bar. So, check from the beginning
49 // in the case of a horizontal right-to-left orientation.
50 const bool checkTopRight = orientation == Qt::Horizontal && w->layoutDirection() == Qt::RightToLeft;
51 const QPoint topRight = QPoint(w->rect().width(), 0);
52 for (qsizetype index = 0, actionCount = actions.size(); index < actionCount; ++index) {
53 QRect g = w->actionGeometry(actions.at(index));
54 if (checkTopRight)
55 g.setTopRight(topRight);
56 else
57 g.setTopLeft(QPoint(0, 0));
58
59 if (g.contains(pos))
60 return int(index);
61 }
62 return -1;
63}
64
65Q_DECLARE_EXTENSION_INTERFACE(QDesignerActionProviderExtension, "org.qt-project.Qt.Designer.ActionProvider")
66
67QT_END_NAMESPACE
68
69#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)