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
5
#
include
"default_actionprovider.h"
6
#
include
"invisible_widget_p.h"
7
#
include
"qdesigner_toolbar_p.h"
8
9
#
include
<
QtWidgets
/
qapplication
.
h
>
10
11
#
include
<
QtGui
/
qaction
.
h
>
12
13
#
include
<
QtCore
/
qrect
.
h
>
14
#
include
<
QtCore
/
qdebug
.
h
>
15
16
QT_BEGIN_NAMESPACE
17
18
namespace
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.
23
ActionProviderBase
::
ActionProviderBase
(
QWidget
*
widget
) :
24
m_indicator
(
new
InvisibleWidget
(
widget
))
25
{
26
Q_ASSERT
(
widget
!=
nullptr
);
27
28
m_indicator
->
setAutoFillBackground
(
true
);
29
m_indicator
->
setBackgroundRole
(
QPalette
::
Window
);
30
31
QPalette
p
;
32
p
.
setColor
(
m_indicator
->
backgroundRole
(),
Qt
::
red
);
33
m_indicator
->
setPalette
(
p
);
34
m_indicator
->
hide
();
35
}
36
37
enum
{
indicatorSize
= 2 };
38
39
// Position an indicator horizontally over the rectangle, indicating
40
// 'Insert before' (left or right according to layout direction)
41
static
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)
51
static
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.
58
QRect
ActionProviderBase
::
indicatorGeometry
(
const
QPoint
&
pos
,
Qt
::
LayoutDirection
layoutDirection
)
const
59
{
60
QAction
*
action
=
actionAt
(
pos
);
61
if
(!
action
)
62
return
QRect
();
63
QRect
rc
=
actionGeometry
(
action
);
64
return
orientation
() ==
Qt
::
Horizontal
?
horizontalIndicatorRect
(
rc
,
layoutDirection
) :
verticalIndicatorRect
(
rc
);
65
}
66
67
// Adjust the indicator while dragging. (-1,1) is called to finish a DND operation
68
void
ActionProviderBase
::
adjustIndicator
(
const
QPoint
&
pos
)
69
{
70
if
(
pos
==
QPoint
(-1, -1)) {
71
m_indicator
->
hide
();
72
return
;
73
}
74
const
QRect
ig
=
indicatorGeometry
(
pos
,
m_indicator
->
layoutDirection
());
75
if
(
ig
.
isValid
()) {
76
m_indicator
->
setGeometry
(
ig
);
77
QPalette
p
=
m_indicator
->
palette
();
78
if
(
p
.
color
(
m_indicator
->
backgroundRole
()) !=
Qt
::
red
) {
79
p
.
setColor
(
m_indicator
->
backgroundRole
(),
Qt
::
red
);
80
m_indicator
->
setPalette
(
p
);
81
}
82
m_indicator
->
show
();
83
m_indicator
->
raise
();
84
}
else
{
85
m_indicator
->
hide
();
86
}
87
}
88
89
// ------------- QToolBarActionProvider
90
QToolBarActionProvider
::
QToolBarActionProvider
(
QToolBar
*
widget
,
QObject
*
parent
) :
91
QObject
(
parent
),
92
ActionProviderBase
(
widget
),
93
m_widget
(
widget
)
94
{
95
}
96
97
QRect
QToolBarActionProvider
::
actionGeometry
(
QAction
*
action
)
const
98
{
99
return
m_widget
->
actionGeometry
(
action
);
100
}
101
102
QAction
*
QToolBarActionProvider
::
actionAt
(
const
QPoint
&
pos
)
const
103
{
104
return
ToolBarEventFilter
::
actionAt
(
m_widget
,
pos
);
105
}
106
107
Qt
::
Orientation
QToolBarActionProvider
::
orientation
()
const
108
{
109
return
m_widget
->
orientation
();
110
}
111
112
QRect
QToolBarActionProvider
::
indicatorGeometry
(
const
QPoint
&
pos
,
Qt
::
LayoutDirection
layoutDirection
)
const
113
{
114
const
QRect
actionRect
=
ActionProviderBase
::
indicatorGeometry
(
pos
,
layoutDirection
);
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.
119
const
QRect
freeArea
=
ToolBarEventFilter
::
freeArea
(
m_widget
);
120
if
(!
freeArea
.
contains
(
pos
))
121
return
QRect
();
122
return
orientation
() ==
Qt
::
Horizontal
?
horizontalIndicatorRect
(
freeArea
,
layoutDirection
) :
verticalIndicatorRect
(
freeArea
);
123
}
124
125
// ------------- QMenuBarActionProvider
126
QMenuBarActionProvider
::
QMenuBarActionProvider
(
QMenuBar
*
widget
,
QObject
*
parent
) :
127
QObject
(
parent
),
128
ActionProviderBase
(
widget
),
129
m_widget
(
widget
)
130
{
131
}
132
133
QRect
QMenuBarActionProvider
::
actionGeometry
(
QAction
*
action
)
const
134
{
135
return
m_widget
->
actionGeometry
(
action
);
136
}
137
138
QAction
*
QMenuBarActionProvider
::
actionAt
(
const
QPoint
&
pos
)
const
139
{
140
return
m_widget
->
actionAt
(
pos
);
141
}
142
143
Qt
::
Orientation
QMenuBarActionProvider
::
orientation
()
const
144
{
145
return
Qt
::
Horizontal
;
146
}
147
148
// ------------- QMenuActionProvider
149
QMenuActionProvider
::
QMenuActionProvider
(
QMenu
*
widget
,
QObject
*
parent
) :
150
QObject
(
parent
),
151
ActionProviderBase
(
widget
),
152
m_widget
(
widget
)
153
{
154
}
155
156
QRect
QMenuActionProvider
::
actionGeometry
(
QAction
*
action
)
const
157
{
158
return
m_widget
->
actionGeometry
(
action
);
159
}
160
161
QAction
*
QMenuActionProvider
::
actionAt
(
const
QPoint
&
pos
)
const
162
{
163
return
m_widget
->
actionAt
(
pos
);
164
}
165
166
Qt
::
Orientation
QMenuActionProvider
::
orientation
()
const
167
{
168
return
Qt
::
Vertical
;
169
}
170
}
171
172
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qdesigner_internal::verticalIndicatorRect
static QRect verticalIndicatorRect(const QRect &rect)
Definition
default_actionprovider.cpp:51
qdesigner_internal::horizontalIndicatorRect
static QRect horizontalIndicatorRect(const QRect &rect, Qt::LayoutDirection layoutDirection)
Definition
default_actionprovider.cpp:41
qdesigner_internal::indicatorSize
@ indicatorSize
Definition
default_actionprovider.cpp:37
qttools
src
designer
src
components
formeditor
default_actionprovider.cpp
Generated on
for Qt by
1.16.1