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