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
default_actionprovider.cpp
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
8
9#include <QtWidgets/qapplication.h>
10
11#include <QtGui/qaction.h>
12
13#include <QtCore/qrect.h>
14#include <QtCore/qdebug.h>
15
17
18namespace qdesigner_internal {
19
20// ------------ ActionProviderBase:
21// Draws the drag indicator when dragging an action over a widget
22// that receives action Dnd, such as ToolBar, Menu or MenuBar.
36
37enum { indicatorSize = 2 };
38
39// Position an indicator horizontally over the rectangle, indicating
40// 'Insert before' (left or right according to layout direction)
41static inline QRect horizontalIndicatorRect(const QRect &rect, Qt::LayoutDirection layoutDirection)
42{
43 // Position right?
44 QRect rc = QRect(rect.x(), 0, indicatorSize, rect.height() - 1);
45 if (layoutDirection == Qt::RightToLeft)
46 rc.moveLeft(rc.x() + rect.width() - indicatorSize);
47 return rc;
48}
49
50// Position an indicator vertically over the rectangle, indicating 'Insert before' (top)
51static inline QRect verticalIndicatorRect(const QRect &rect)
52{
53 return QRect(0, rect.top(), rect.width() - 1, indicatorSize);
54}
55
56// Determine the geometry of the indicator by retrieving
57// the action under mouse and positioning the bar within its geometry.
66
67// Adjust the indicator while dragging. (-1,1) is called to finish a DND operation
69{
70 if (pos == QPoint(-1, -1)) {
72 return;
73 }
75 if (ig.isValid()) {
78 if (p.color(m_indicator->backgroundRole()) != Qt::red) {
81 }
84 } else {
86 }
87}
88
89// ------------- QToolBarActionProvider
96
101
106
111
113{
115 if (actionRect.isValid())
116 return actionRect;
117 // Toolbar differs in that is has no dummy placeholder to 'insert before'
118 // when intending to append. Check the free area.
120 if (!freeArea.contains(pos))
121 return QRect();
123}
124
125// ------------- QMenuBarActionProvider
132
137
139{
140 return m_widget->actionAt(pos);
141}
142
147
148// ------------- QMenuActionProvider
155
160
162{
163 return m_widget->actionAt(pos);
164}
165
167{
168 return Qt::Vertical;
169}
170}
171
172QT_END_NAMESPACE
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)