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_dockwidget.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
5#include "layoutinfo_p.h"
6
7#include <QtDesigner/abstractformwindow.h>
8#include <QtDesigner/abstractformeditor.h>
9#include <QtDesigner/container.h>
10#include <QtDesigner/qextensionmanager.h>
11#include <QtDesigner/abstractformwindowcursor.h>
12
13#include <qdesigner_propertysheet_p.h>
14
15#include <QtWidgets/qmainwindow.h>
16#include <QtWidgets/qlayout.h>
17
19
20using namespace Qt::StringLiterals;
21
22bool QDockWidgetPropertySheet::isEnabled(int index) const
23{
24 const QString &name = propertyName(index);
25 if (name == "dockWidgetArea"_L1)
26 return static_cast<const QDesignerDockWidget *>(object())->docked();
27 if (name == "docked"_L1)
28 return static_cast<const QDesignerDockWidget *>(object())->inMainWindow();
29 return QDesignerPropertySheet::isEnabled(index);
30}
31
32QDesignerDockWidget::QDesignerDockWidget(QWidget *parent)
33 : QDockWidget(parent)
34{
35}
36
37QDesignerDockWidget::~QDesignerDockWidget() = default;
38
39bool QDesignerDockWidget::docked() const
40{
41 return qobject_cast<QMainWindow*>(parentWidget()) != 0;
42}
43
44void QDesignerDockWidget::setDocked(bool b)
45{
46 if (QMainWindow *mainWindow = findMainWindow()) {
47 QDesignerFormEditorInterface *core = formWindow()->core();
48 QDesignerContainerExtension *c;
49 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), mainWindow);
50 if (b && !docked()) {
51 // Dock it
52 // ### undo/redo stack
53 setParent(nullptr);
54 c->addWidget(this);
55 formWindow()->selectWidget(this, formWindow()->cursor()->isWidgetSelected(this));
56 } else if (!b && docked()) {
57 // Undock it
58 for (int i = 0; i < c->count(); ++i) {
59 if (c->widget(i) == this) {
60 c->remove(i);
61 break;
62 }
63 }
64 // #### restore the position
65 setParent(mainWindow->centralWidget());
66 show();
67 formWindow()->selectWidget(this, formWindow()->cursor()->isWidgetSelected(this));
68 }
69 }
70}
71
72Qt::DockWidgetArea QDesignerDockWidget::dockWidgetArea() const
73{
74 if (QMainWindow *mainWindow = qobject_cast<QMainWindow*>(parentWidget()))
75 return mainWindow->dockWidgetArea(const_cast<QDesignerDockWidget*>(this));
76
77 return Qt::LeftDockWidgetArea;
78}
79
80void QDesignerDockWidget::setDockWidgetArea(Qt::DockWidgetArea dockWidgetArea)
81{
82 if (QMainWindow *mainWindow = qobject_cast<QMainWindow*>(parentWidget())) {
83 if ((dockWidgetArea != Qt::NoDockWidgetArea)
84 && isAreaAllowed(dockWidgetArea)) {
85 mainWindow->addDockWidget(dockWidgetArea, this);
86 }
87 }
88}
89
90bool QDesignerDockWidget::inMainWindow() const
91{
92 QMainWindow *mw = findMainWindow();
93 if (mw && !mw->centralWidget()->layout()) {
94 if (mw == parentWidget())
95 return true;
96 if (mw->centralWidget() == parentWidget())
97 return true;
98 }
99 return false;
100}
101
102QDesignerFormWindowInterface *QDesignerDockWidget::formWindow() const
103{
104 return QDesignerFormWindowInterface::findFormWindow(const_cast<QDesignerDockWidget*>(this));
105}
106
107QMainWindow *QDesignerDockWidget::findMainWindow() const
108{
109 if (QDesignerFormWindowInterface *fw = formWindow())
110 return qobject_cast<QMainWindow*>(fw->mainContainer());
111 return nullptr;
112}
113
114QT_END_NAMESPACE
Combined button and popup list for selecting options.