|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qdesigner_dockwidget_p.h" |
|
43 #include "layoutinfo_p.h" |
|
44 |
|
45 #include <QtDesigner/QDesignerFormWindowInterface> |
|
46 #include <QtDesigner/QDesignerFormEditorInterface> |
|
47 #include <QtDesigner/QDesignerContainerExtension> |
|
48 #include <QtDesigner/QExtensionManager> |
|
49 #include <QtDesigner/QDesignerFormWindowCursorInterface> |
|
50 |
|
51 #include <QtGui/QMainWindow> |
|
52 #include <QtGui/QLayout> |
|
53 |
|
54 QT_BEGIN_NAMESPACE |
|
55 |
|
56 QDesignerDockWidget::QDesignerDockWidget(QWidget *parent) |
|
57 : QDockWidget(parent) |
|
58 { |
|
59 } |
|
60 |
|
61 QDesignerDockWidget::~QDesignerDockWidget() |
|
62 { |
|
63 } |
|
64 |
|
65 bool QDesignerDockWidget::docked() const |
|
66 { |
|
67 return qobject_cast<QMainWindow*>(parentWidget()) != 0; |
|
68 } |
|
69 |
|
70 void QDesignerDockWidget::setDocked(bool b) |
|
71 { |
|
72 if (QMainWindow *mainWindow = findMainWindow()) { |
|
73 QDesignerFormEditorInterface *core = formWindow()->core(); |
|
74 QDesignerContainerExtension *c; |
|
75 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), mainWindow); |
|
76 if (b && !docked()) { |
|
77 // Dock it |
|
78 // ### undo/redo stack |
|
79 setParent(0); |
|
80 c->addWidget(this); |
|
81 formWindow()->selectWidget(this, formWindow()->cursor()->isWidgetSelected(this)); |
|
82 } else if (!b && docked()) { |
|
83 // Undock it |
|
84 for (int i = 0; i < c->count(); ++i) { |
|
85 if (c->widget(i) == this) { |
|
86 c->remove(i); |
|
87 break; |
|
88 } |
|
89 } |
|
90 // #### restore the position |
|
91 setParent(mainWindow->centralWidget()); |
|
92 show(); |
|
93 formWindow()->selectWidget(this, formWindow()->cursor()->isWidgetSelected(this)); |
|
94 } |
|
95 } |
|
96 } |
|
97 |
|
98 Qt::DockWidgetArea QDesignerDockWidget::dockWidgetArea() const |
|
99 { |
|
100 if (QMainWindow *mainWindow = qobject_cast<QMainWindow*>(parentWidget())) |
|
101 return mainWindow->dockWidgetArea(const_cast<QDesignerDockWidget*>(this)); |
|
102 |
|
103 return Qt::LeftDockWidgetArea; |
|
104 } |
|
105 |
|
106 void QDesignerDockWidget::setDockWidgetArea(Qt::DockWidgetArea dockWidgetArea) |
|
107 { |
|
108 if (QMainWindow *mainWindow = qobject_cast<QMainWindow*>(parentWidget())) { |
|
109 if ((dockWidgetArea != Qt::NoDockWidgetArea) |
|
110 && isAreaAllowed(dockWidgetArea)) { |
|
111 mainWindow->addDockWidget(dockWidgetArea, this); |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 bool QDesignerDockWidget::inMainWindow() const |
|
117 { |
|
118 QMainWindow *mw = findMainWindow(); |
|
119 if (mw && !mw->centralWidget()->layout()) { |
|
120 if (mw == parentWidget()) |
|
121 return true; |
|
122 if (mw->centralWidget() == parentWidget()) |
|
123 return true; |
|
124 } |
|
125 return false; |
|
126 } |
|
127 |
|
128 QDesignerFormWindowInterface *QDesignerDockWidget::formWindow() const |
|
129 { |
|
130 return QDesignerFormWindowInterface::findFormWindow(const_cast<QDesignerDockWidget*>(this)); |
|
131 } |
|
132 |
|
133 QMainWindow *QDesignerDockWidget::findMainWindow() const |
|
134 { |
|
135 if (QDesignerFormWindowInterface *fw = formWindow()) |
|
136 return qobject_cast<QMainWindow*>(fw->mainContainer()); |
|
137 return 0; |
|
138 } |
|
139 |
|
140 QT_END_NAMESPACE |