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