Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdesigner_toolwindow.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
"qdesigner.h"
6
#
include
"qdesigner_toolwindow.h"
7
#
include
"qdesigner_settings.h"
8
#
include
"qdesigner_workbench.h"
9
10
#
include
<
QtDesigner
/
abstractpropertyeditor
.
h
>
11
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
12
#
include
<
QtDesigner
/
abstractactioneditor
.
h
>
13
#
include
<
QtDesigner
/
abstractobjectinspector
.
h
>
14
#
include
<
QtDesigner
/
abstractwidgetbox
.
h
>
15
#
include
<
QtDesigner
/
QDesignerComponents
>
16
17
#
include
<
QtGui
/
qaction
.
h
>
18
#
include
<
QtGui
/
qevent
.
h
>
19
20
#
include
<
QtCore
/
qdebug
.
h
>
21
22
static
constexpr
bool
debugToolWindow
=
false
;
23
24
QT_BEGIN_NAMESPACE
25
26
using
namespace
Qt::StringLiterals;
27
28
static
constexpr
int
margin
= 20;
29
30
// ---------------- QDesignerToolWindow
31
QDesignerToolWindow
::QDesignerToolWindow(
QDesignerWorkbench
*workbench,
32
QWidget
*w,
33
const
QString &objectName,
34
const
QString &title,
35
const
QString &actionObjectName,
36
Qt::DockWidgetArea dockAreaHint,
37
QWidget
*parent,
38
Qt::WindowFlags flags) :
39
MainWindowBase
(parent, flags),
40
m_dockAreaHint(dockAreaHint),
41
m_workbench(workbench),
42
m_action(
new
QAction(
this
))
43
{
44
setObjectName(objectName);
45
setCentralWidget(w);
46
47
setWindowTitle(title);
48
49
m_action->setObjectName(actionObjectName);
50
m_action->setShortcutContext(Qt::ApplicationShortcut);
51
m_action->setText(title);
52
m_action->setCheckable(
true
);
53
connect(m_action, &QAction::triggered,
this
, &QDesignerToolWindow::showMe);
54
}
55
56
void
QDesignerToolWindow
::showMe(
bool
v)
57
{
58
// Access the QMdiSubWindow in MDI mode.
59
if
(
QWidget
*target = m_workbench
->
mode
(
)
==
DockedMode
? parentWidget() :
this
) {
60
if
(v)
61
target->setWindowState(target->windowState() & ~Qt::WindowMinimized);
62
target->setVisible(v);
63
}
64
}
65
66
void
QDesignerToolWindow
::
showEvent
(QShowEvent *e)
67
{
68
Q_UNUSED(e);
69
70
bool
blocked = m_action->blockSignals(
true
);
71
m_action->setChecked(
true
);
72
m_action->blockSignals(blocked);
73
}
74
75
void
QDesignerToolWindow
::
hideEvent
(QHideEvent *e)
76
{
77
Q_UNUSED(e);
78
79
bool
blocked = m_action->blockSignals(
true
);
80
m_action->setChecked(
false
);
81
m_action->blockSignals(blocked);
82
}
83
84
QAction *
QDesignerToolWindow
::
action
()
const
85
{
86
return
m_action;
87
}
88
89
void
QDesignerToolWindow
::
changeEvent
(QEvent *e)
90
{
91
switch
(e->type()) {
92
case
QEvent::WindowTitleChange:
93
m_action->setText(windowTitle());
94
break
;
95
case
QEvent::WindowIconChange:
96
m_action->setIcon(windowIcon());
97
break
;
98
default
:
99
break
;
100
}
101
QMainWindow::changeEvent(e);
102
}
103
104
QDesignerWorkbench
*
QDesignerToolWindow
::
workbench
()
const
105
{
106
return
m_workbench;
107
}
108
109
// ---------------------- PropertyEditorToolWindow
110
111
static
inline
QWidget
*
createPropertyEditor
(QDesignerFormEditorInterface *core,
QWidget
*parent =
nullptr
)
112
{
113
QDesignerPropertyEditorInterface *widget = QDesignerComponents::createPropertyEditor(core, parent);
114
core->setPropertyEditor(widget);
115
return
widget;
116
}
117
118
class
PropertyEditorToolWindow
:
public
QDesignerToolWindow
119
{
120
public
:
121
explicit
PropertyEditorToolWindow
(
QDesignerWorkbench
*workbench);
122
123
QRect
geometryHint
(
const
QRect &)
const
override
;
124
125
protected
:
126
void
showEvent
(QShowEvent *event)
override
;
127
};
128
129
PropertyEditorToolWindow
::
PropertyEditorToolWindow
(
QDesignerWorkbench
*workbench) :
130
QDesignerToolWindow
(
workbench
,
131
createPropertyEditor
(
workbench
->
core
()),
132
u"qt_designer_propertyeditor"_s,
133
QDesignerToolWindow
::
tr
(
"Property Editor"
),
134
u"__qt_property_editor_action"_s,
135
Qt
::
RightDockWidgetArea
)
136
{
137
action()->setShortcut(Qt::CTRL | Qt::Key_I);
138
139
}
140
141
QRect
PropertyEditorToolWindow
::
geometryHint
(
const
QRect &g)
const
142
{
143
const
int
spacing = 40;
144
const
QSize sz(g.width() * 1/4, g.height() * 4/6);
145
146
const
QRect rc = QRect((g.right() + 1 - sz.width() -
margin
),
147
(g.top() +
margin
+ g.height() * 1/6) + spacing,
148
sz.width(), sz.height());
149
if
(debugToolWindow)
150
qDebug() << Q_FUNC_INFO << rc;
151
return
rc;
152
}
153
154
void
PropertyEditorToolWindow
::
showEvent
(QShowEvent *event)
155
{
156
if
(QDesignerPropertyEditorInterface *e = workbench()->core()->propertyEditor()) {
157
// workaround to update the propertyeditor when it is not visible!
158
e->setObject(e->object());
// ### remove me
159
}
160
161
QDesignerToolWindow::showEvent(event);
162
}
163
164
// ---------------------- ActionEditorToolWindow
165
166
static
inline
QWidget
*
createActionEditor
(QDesignerFormEditorInterface *core,
QWidget
*parent =
nullptr
)
167
{
168
QDesignerActionEditorInterface *widget = QDesignerComponents::createActionEditor(core, parent);
169
core->setActionEditor(widget);
170
return
widget;
171
}
172
173
class
ActionEditorToolWindow
:
public
QDesignerToolWindow
174
{
175
public
:
176
explicit
ActionEditorToolWindow
(
QDesignerWorkbench
*workbench);
177
178
QRect
geometryHint
(
const
QRect &g)
const
override
;
179
};
180
181
ActionEditorToolWindow
::
ActionEditorToolWindow
(
QDesignerWorkbench
*workbench) :
182
QDesignerToolWindow
(
workbench
,
183
createActionEditor
(
workbench
->
core
()),
184
u"qt_designer_actioneditor"_s,
185
QDesignerToolWindow
::
tr
(
"Action Editor"
),
186
u"__qt_action_editor_tool_action"_s,
187
Qt
::
RightDockWidgetArea
)
188
{
189
}
190
191
QRect
ActionEditorToolWindow
::
geometryHint
(
const
QRect &g)
const
192
{
193
const
QSize sz(g.width() * 1/4, g.height() * 1/6);
194
195
const
QRect rc = QRect((g.right() + 1 - sz.width() -
margin
),
196
g.top() +
margin
,
197
sz.width(), sz.height());
198
if
(debugToolWindow)
199
qDebug() << Q_FUNC_INFO << rc;
200
return
rc;
201
}
202
203
// ---------------------- ObjectInspectorToolWindow
204
205
static
inline
QWidget
*
createObjectInspector
(QDesignerFormEditorInterface *core,
QWidget
*parent =
nullptr
)
206
{
207
QDesignerObjectInspectorInterface *widget = QDesignerComponents::createObjectInspector(core, parent);
208
core->setObjectInspector(widget);
209
return
widget;
210
}
211
212
class
ObjectInspectorToolWindow
:
public
QDesignerToolWindow
213
{
214
public
:
215
explicit
ObjectInspectorToolWindow
(
QDesignerWorkbench
*workbench);
216
217
QRect
geometryHint
(
const
QRect &g)
const
override
;
218
};
219
220
ObjectInspectorToolWindow
::
ObjectInspectorToolWindow
(
QDesignerWorkbench
*workbench) :
221
QDesignerToolWindow
(
workbench
,
222
createObjectInspector
(
workbench
->
core
()),
223
u"qt_designer_objectinspector"_s,
224
QDesignerToolWindow
::
tr
(
"Object Inspector"
),
225
u"__qt_object_inspector_tool_action"_s,
226
Qt
::
RightDockWidgetArea
)
227
{
228
}
229
230
QRect
ObjectInspectorToolWindow
::
geometryHint
(
const
QRect &g)
const
231
{
232
const
QSize sz(g.width() * 1/4, g.height() * 1/6);
233
234
const
QRect rc = QRect((g.right() + 1 - sz.width() -
margin
),
235
g.top() +
margin
,
236
sz.width(), sz.height());
237
if
(debugToolWindow)
238
qDebug() << Q_FUNC_INFO << rc;
239
return
rc;
240
}
241
242
// ---------------------- ResourceEditorToolWindow
243
244
class
ResourceEditorToolWindow
:
public
QDesignerToolWindow
245
{
246
public
:
247
explicit
ResourceEditorToolWindow
(
QDesignerWorkbench
*workbench);
248
249
QRect
geometryHint
(
const
QRect &g)
const
override
;
250
};
251
252
ResourceEditorToolWindow
::
ResourceEditorToolWindow
(
QDesignerWorkbench
*workbench) :
253
QDesignerToolWindow
(
workbench
,
254
QDesignerComponents
::
createResourceEditor
(
workbench
->
core
(),
nullptr
),
255
u"qt_designer_resourceeditor"_s,
256
QDesignerToolWindow
::
tr
(
"Resource Browser"
),
257
u"__qt_resource_editor_tool_action"_s,
258
Qt
::
RightDockWidgetArea
)
259
{
260
}
261
262
QRect
ResourceEditorToolWindow
::
geometryHint
(
const
QRect &g)
const
263
{
264
const
QSize sz(g.width() * 1/3, g.height() * 1/6);
265
QRect r(QPoint(0, 0), sz);
266
r.moveCenter(g.center());
267
r.moveBottom(g.bottom() -
margin
);
268
if
(debugToolWindow)
269
qDebug() << Q_FUNC_INFO << r;
270
return
r;
271
}
272
273
// ---------------------- SignalSlotEditorToolWindow
274
275
class
SignalSlotEditorToolWindow
:
public
QDesignerToolWindow
276
{
277
public
:
278
explicit
SignalSlotEditorToolWindow
(
QDesignerWorkbench
*workbench);
279
280
QRect
geometryHint
(
const
QRect &g)
const
override
;
281
};
282
283
SignalSlotEditorToolWindow
::
SignalSlotEditorToolWindow
(
QDesignerWorkbench
*workbench) :
284
QDesignerToolWindow
(
workbench
,
285
QDesignerComponents
::
createSignalSlotEditor
(
workbench
->
core
(),
nullptr
),
286
u"qt_designer_signalsloteditor"_s,
287
QDesignerToolWindow
::
tr
(
"Signal/Slot Editor"
),
288
u"__qt_signal_slot_editor_tool_action"_s,
289
Qt
::
RightDockWidgetArea
)
290
{
291
}
292
293
QRect
SignalSlotEditorToolWindow
::
geometryHint
(
const
QRect &g)
const
294
{
295
const
QSize sz(g.width() * 1/3, g.height() * 1/6);
296
QRect r(QPoint(0, 0), sz);
297
r.moveCenter(g.center());
298
r.moveTop(
margin
+ g.top());
299
if
(debugToolWindow)
300
qDebug() << Q_FUNC_INFO << r;
301
return
r;
302
}
303
304
// ---------------------- WidgetBoxToolWindow
305
306
static
inline
QWidget
*
createWidgetBox
(QDesignerFormEditorInterface *core,
QWidget
*parent =
nullptr
)
307
{
308
QDesignerWidgetBoxInterface *widget = QDesignerComponents::createWidgetBox(core, parent);
309
core->setWidgetBox(widget);
310
return
widget;
311
}
312
313
class
WidgetBoxToolWindow
:
public
QDesignerToolWindow
314
{
315
public
:
316
explicit
WidgetBoxToolWindow
(
QDesignerWorkbench
*workbench);
317
318
QRect
geometryHint
(
const
QRect &g)
const
override
;
319
};
320
321
WidgetBoxToolWindow
::
WidgetBoxToolWindow
(
QDesignerWorkbench
*workbench) :
322
QDesignerToolWindow
(
workbench
,
323
createWidgetBox
(
workbench
->
core
()),
324
u"qt_designer_widgetbox"_s,
325
QDesignerToolWindow
::
tr
(
"Widget Box"
),
326
u"__qt_widget_box_tool_action"_s,
327
Qt
::
LeftDockWidgetArea
)
328
{
329
}
330
331
QRect
WidgetBoxToolWindow
::
geometryHint
(
const
QRect &g)
const
332
{
333
const
QRect rc = QRect(g.left() +
margin
,
334
g.top() +
margin
,
335
g.width() * 1/4, g.height() * 5/6);
336
if
(debugToolWindow)
337
qDebug() << Q_FUNC_INFO << rc;
338
return
rc;
339
}
340
341
// -- Factory
342
QDesignerToolWindow
*
QDesignerToolWindow
::
createStandardToolWindow
(
StandardToolWindow
which,
343
QDesignerWorkbench
*workbench)
344
{
345
switch
(which) {
346
case
ActionEditor
:
347
return
new
ActionEditorToolWindow
(
workbench
)
;
348
case
ResourceEditor
:
349
return
new
ResourceEditorToolWindow
(
workbench
)
;
350
case
SignalSlotEditor
:
351
return
new
SignalSlotEditorToolWindow
(
workbench
)
;
352
case
PropertyEditor
:
353
return
new
PropertyEditorToolWindow
(
workbench
)
;
354
case
ObjectInspector
:
355
return
new
ObjectInspectorToolWindow
(
workbench
)
;
356
case
WidgetBox
:
357
return
new
WidgetBoxToolWindow
(
workbench
)
;
358
default
:
359
break
;
360
}
361
return
nullptr
;
362
}
363
364
365
QT_END_NAMESPACE
ActionEditorToolWindow
Definition
qdesigner_toolwindow.cpp:174
ActionEditorToolWindow::geometryHint
QRect geometryHint(const QRect &g) const override
Definition
qdesigner_toolwindow.cpp:191
ActionEditorToolWindow::ActionEditorToolWindow
ActionEditorToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:181
MainWindowBase
Definition
mainwindow.h:34
ObjectInspectorToolWindow
Definition
qdesigner_toolwindow.cpp:213
ObjectInspectorToolWindow::geometryHint
QRect geometryHint(const QRect &g) const override
Definition
qdesigner_toolwindow.cpp:230
ObjectInspectorToolWindow::ObjectInspectorToolWindow
ObjectInspectorToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:220
PropertyEditorToolWindow
Definition
qdesigner_toolwindow.cpp:119
PropertyEditorToolWindow::PropertyEditorToolWindow
PropertyEditorToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:129
PropertyEditorToolWindow::geometryHint
QRect geometryHint(const QRect &) const override
Definition
qdesigner_toolwindow.cpp:141
PropertyEditorToolWindow::showEvent
void showEvent(QShowEvent *event) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition
qdesigner_toolwindow.cpp:154
QDesignerToolWindow
Definition
qdesigner_toolwindow.h:40
QDesignerToolWindow::createStandardToolWindow
static QDesignerToolWindow * createStandardToolWindow(StandardToolWindow which, QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:342
QDesignerToolWindow::StandardToolWindow
StandardToolWindow
Definition
qdesigner_toolwindow.h:54
QDesignerToolWindow::PropertyEditor
@ PropertyEditor
Definition
qdesigner_toolwindow.h:54
QDesignerToolWindow::ResourceEditor
@ ResourceEditor
Definition
qdesigner_toolwindow.h:55
QDesignerToolWindow::SignalSlotEditor
@ SignalSlotEditor
Definition
qdesigner_toolwindow.h:55
QDesignerToolWindow::ActionEditor
@ ActionEditor
Definition
qdesigner_toolwindow.h:55
QDesignerToolWindow::WidgetBox
@ WidgetBox
Definition
qdesigner_toolwindow.h:54
QDesignerToolWindow::ObjectInspector
@ ObjectInspector
Definition
qdesigner_toolwindow.h:54
QDesignerToolWindow::hideEvent
void hideEvent(QHideEvent *e) override
This event handler can be reimplemented in a subclass to receive widget hide events.
Definition
qdesigner_toolwindow.cpp:75
QDesignerToolWindow::workbench
QDesignerWorkbench * workbench() const
Definition
qdesigner_toolwindow.cpp:104
QDesignerToolWindow::changeEvent
void changeEvent(QEvent *e) override
This event handler can be reimplemented to handle state changes.
Definition
qdesigner_toolwindow.cpp:89
QDesignerToolWindow::action
QAction * action() const
Definition
qdesigner_toolwindow.cpp:84
QDesignerToolWindow::showEvent
void showEvent(QShowEvent *e) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition
qdesigner_toolwindow.cpp:66
QDesignerWorkbench
Definition
qdesigner_workbench.h:44
QDesignerWorkbench::mode
UIMode mode() const
Definition
qdesigner_workbench.cpp:267
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
ResourceEditorToolWindow
Definition
qdesigner_toolwindow.cpp:245
ResourceEditorToolWindow::geometryHint
QRect geometryHint(const QRect &g) const override
Definition
qdesigner_toolwindow.cpp:262
ResourceEditorToolWindow::ResourceEditorToolWindow
ResourceEditorToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:252
SignalSlotEditorToolWindow
Definition
qdesigner_toolwindow.cpp:276
SignalSlotEditorToolWindow::geometryHint
QRect geometryHint(const QRect &g) const override
Definition
qdesigner_toolwindow.cpp:293
SignalSlotEditorToolWindow::SignalSlotEditorToolWindow
SignalSlotEditorToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:283
WidgetBoxToolWindow
Definition
qdesigner_toolwindow.cpp:314
WidgetBoxToolWindow::geometryHint
QRect geometryHint(const QRect &g) const override
Definition
qdesigner_toolwindow.cpp:331
WidgetBoxToolWindow::WidgetBoxToolWindow
WidgetBoxToolWindow(QDesignerWorkbench *workbench)
Definition
qdesigner_toolwindow.cpp:321
DockedMode
@ DockedMode
Definition
designer_enums.h:12
createWidgetBox
static QWidget * createWidgetBox(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
Definition
qdesigner_toolwindow.cpp:306
createObjectInspector
static QWidget * createObjectInspector(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
Definition
qdesigner_toolwindow.cpp:205
debugToolWindow
static constexpr bool debugToolWindow
Definition
qdesigner_toolwindow.cpp:22
createActionEditor
static QWidget * createActionEditor(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
Definition
qdesigner_toolwindow.cpp:166
margin
static constexpr int margin
Definition
qdesigner_toolwindow.cpp:28
createPropertyEditor
static QWidget * createPropertyEditor(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
Definition
qdesigner_toolwindow.cpp:111
qttools
src
designer
src
designer
qdesigner_toolwindow.cpp
Generated on
for Qt by
1.18.0