1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "layoutinfo_p.h"
31
#include <QtDesigner/QtDesigner>
33
#include <QtGui/QHBoxLayout>
34
#include <QtGui/QSplitter>
36
#include <QtCore/QMap>
37
#include <QtCore/qdebug.h>
39
LayoutInfo::Type LayoutInfo::layoutType(QDesignerFormEditorInterface *core, QWidget *w, QLayout *&layout)
43
if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), w))
44
w = container->widget(container->currentIndex());
46
if (qobject_cast<QSplitter*>(w))
47
return static_cast<QSplitter*>(w)->orientation() == Qt::Horizontal ? HBox : VBox;
49
if (!w || !w->layout())
52
QLayout *lay = w->layout();
54
if (lay && core->metaDataBase()->item(lay) == 0) {
55
lay = qFindChild<QLayout*>(lay);
60
Q_ASSERT (lay == 0 || core->metaDataBase()->item(lay) != 0);
63
return layoutType(core, lay);
69
LayoutInfo::Type LayoutInfo::layoutType(QDesignerFormEditorInterface *core, QLayout *layout)
73
if (qobject_cast<QHBoxLayout*>(layout))
75
else if (qobject_cast<QVBoxLayout*>(layout))
77
else if (qobject_cast<QGridLayout*>(layout))
85
LayoutInfo::Type LayoutInfo::layoutType(QDesignerFormEditorInterface *core, QWidget *w)
88
return layoutType(core, w, l);
91
QWidget *LayoutInfo::layoutParent(QDesignerFormEditorInterface *core, QLayout *layout)
97
if (QWidget *widget = qobject_cast<QWidget*>(o))
105
void LayoutInfo::deleteLayout(QDesignerFormEditorInterface *core, QWidget *widget)
107
if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), widget))
108
widget = container->widget(container->currentIndex());
110
Q_ASSERT(widget != 0);
112
QLayout *layout = managedLayout(core, widget);
114
if (layout == 0 || core->metaDataBase()->item(layout) != 0) {
119
qWarning() << "trying to delete an unmanaged layout:" << "widget:" << widget << "layout:" << layout;
122
void LayoutInfo::cells(QLayout *layout, IntervalList *rows, IntervalList *columns)
124
QMap<Interval, int> rowDict;
125
QMap<Interval, int> columnDict;
128
while (QLayoutItem *item = layout->itemAt(i)) {
131
QRect g = item->geometry();
132
columnDict.insert(Interval(g.left(), g.right()), 1);
133
rowDict.insert(Interval(g.top(), g.bottom()), 1);
137
*columns = columnDict.keys();
140
*rows = rowDict.keys();
143
bool LayoutInfo::isWidgetLaidout(QDesignerFormEditorInterface *core, QWidget *widget)
147
QWidget *parent = widget->parentWidget();
149
if (qobject_cast<QSplitter*>(parent)) { // ### generalize
153
if (parent && parent->layout()) {
154
if (parent->layout()->indexOf(widget) != -1)
157
QList<QLayout*> childLayouts = qFindChildren<QLayout*>(parent->layout());
158
foreach (QLayout *childLayout, childLayouts) {
159
if (childLayout->indexOf(widget) != -1)
167
QLayout *LayoutInfo::managedLayout(QDesignerFormEditorInterface *core, QWidget *widget)
172
QLayout *layout = widget->layout();
173
QDesignerMetaDataBaseItemInterface *item = core->metaDataBase()->item(layout);
174
if (layout != 0 && item == 0) {
175
layout = qFindChild<QLayout*>(layout);
176
item = core->metaDataBase()->item(layout);
179
return item != 0 ? layout : 0;