source: trunk/tools/designer/src/lib/shared/qdesigner_dockwidget.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 4.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
54QT_BEGIN_NAMESPACE
55
56QDesignerDockWidget::QDesignerDockWidget(QWidget *parent)
57 : QDockWidget(parent)
58{
59}
60
61QDesignerDockWidget::~QDesignerDockWidget()
62{
63}
64
65bool QDesignerDockWidget::docked() const
66{
67 return qobject_cast<QMainWindow*>(parentWidget()) != 0;
68}
69
70void 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
98Qt::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
106void 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
116bool 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
128QDesignerFormWindowInterface *QDesignerDockWidget::formWindow() const
129{
130 return QDesignerFormWindowInterface::findFormWindow(const_cast<QDesignerDockWidget*>(this));
131}
132
133QMainWindow *QDesignerDockWidget::findMainWindow() const
134{
135 if (QDesignerFormWindowInterface *fw = formWindow())
136 return qobject_cast<QMainWindow*>(fw->mainContainer());
137 return 0;
138}
139
140QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.