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
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"
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
22static constexpr bool debugToolWindow = false;
23
24QT_BEGIN_NAMESPACE
25
26using namespace Qt::StringLiterals;
27
28static constexpr int margin = 20;
29
30// ---------------- QDesignerToolWindow
31QDesignerToolWindow::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
56void 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
66void 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
75void 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
84QAction *QDesignerToolWindow::action() const
85{
86 return m_action;
87}
88
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
105{
106 return m_workbench;
107}
108
109// ---------------------- PropertyEditorToolWindow
110
111static 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
119{
120public:
122
123 QRect geometryHint(const QRect &) const override;
124
125protected:
126 void showEvent(QShowEvent *event) override;
127};
128
132 u"qt_designer_propertyeditor"_s,
133 QDesignerToolWindow::tr("Property Editor"),
134 u"__qt_property_editor_action"_s,
136{
137 action()->setShortcut(Qt::CTRL | Qt::Key_I);
138
139}
140
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
154void 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
166static 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
174{
175public:
177
178 QRect geometryHint(const QRect &g) const override;
179};
180
184 u"qt_designer_actioneditor"_s,
185 QDesignerToolWindow::tr("Action Editor"),
186 u"__qt_action_editor_tool_action"_s,
188{
189}
190
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
205static 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
213{
214public:
216
217 QRect geometryHint(const QRect &g) const override;
218};
219
223 u"qt_designer_objectinspector"_s,
224 QDesignerToolWindow::tr("Object Inspector"),
225 u"__qt_object_inspector_tool_action"_s,
227{
228}
229
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
245{
246public:
248
249 QRect geometryHint(const QRect &g) const override;
250};
251
255 u"qt_designer_resourceeditor"_s,
256 QDesignerToolWindow::tr("Resource Browser"),
257 u"__qt_resource_editor_tool_action"_s,
259{
260}
261
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
276{
277public:
279
280 QRect geometryHint(const QRect &g) const override;
281};
282
286 u"qt_designer_signalsloteditor"_s,
287 QDesignerToolWindow::tr("Signal/Slot Editor"),
288 u"__qt_signal_slot_editor_tool_action"_s,
290{
291}
292
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
306static 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
314{
315public:
317
318 QRect geometryHint(const QRect &g) const override;
319};
320
324 u"qt_designer_widgetbox"_s,
325 QDesignerToolWindow::tr("Widget Box"),
326 u"__qt_widget_box_tool_action"_s,
328{
329}
330
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
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
365QT_END_NAMESPACE
QRect geometryHint(const QRect &g) const override
ActionEditorToolWindow(QDesignerWorkbench *workbench)
QRect geometryHint(const QRect &g) const override
ObjectInspectorToolWindow(QDesignerWorkbench *workbench)
PropertyEditorToolWindow(QDesignerWorkbench *workbench)
QRect geometryHint(const QRect &) const override
void showEvent(QShowEvent *event) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
static QDesignerToolWindow * createStandardToolWindow(StandardToolWindow which, QDesignerWorkbench *workbench)
void hideEvent(QHideEvent *e) override
This event handler can be reimplemented in a subclass to receive widget hide events.
QDesignerWorkbench * workbench() const
void changeEvent(QEvent *e) override
This event handler can be reimplemented to handle state changes.
void showEvent(QShowEvent *e) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
friend class QWidget
Definition qpainter.h:432
QRect geometryHint(const QRect &g) const override
ResourceEditorToolWindow(QDesignerWorkbench *workbench)
QRect geometryHint(const QRect &g) const override
SignalSlotEditorToolWindow(QDesignerWorkbench *workbench)
QRect geometryHint(const QRect &g) const override
WidgetBoxToolWindow(QDesignerWorkbench *workbench)
static QWidget * createWidgetBox(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
static QWidget * createObjectInspector(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
static constexpr bool debugToolWindow
static QWidget * createActionEditor(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)
static constexpr int margin
static QWidget * createPropertyEditor(QDesignerFormEditorInterface *core, QWidget *parent=nullptr)