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
****************************************************************************/
33
// This file is not part of the Qt API. It exists for the convenience
34
// of Qt Designer. This header
35
// file may change from version to version without notice, or even be removed.
43
#include "shared_global_p.h"
44
#include "layoutinfo_p.h"
46
#include <QtCore/QPointer>
47
#include <QtCore/QObject>
48
#include <QtCore/QMap>
50
#include <QtGui/QLayout>
51
#include <QtGui/QGridLayout>
52
#include <QtGui/QWidget>
54
class QDesignerFormWindowInterface;
56
void QT_SHARED_EXPORT add_to_box_layout(QBoxLayout *box, QWidget *widget);
57
void QT_SHARED_EXPORT insert_into_box_layout(QBoxLayout *box, int index, QWidget *widget);
58
void QT_SHARED_EXPORT add_to_grid_layout(QGridLayout *grid, QWidget *widget, int r, int c, int rs, int cs, Qt::Alignment align = 0);
60
class QT_SHARED_EXPORT Layout : public QObject
64
Layout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
70
virtual void sort() = 0;
71
virtual void doLayout() = 0;
74
virtual void undoLayout();
75
virtual void breakLayout();
76
virtual bool prepareLayout(bool &needMove, bool &needReparent);
77
virtual void finishLayout(bool needMove, QLayout *layout);
79
QList<QWidget*> widgets() const { return m_widgets; }
80
QWidget *parentWidget() const { return m_parentWidget; }
81
QWidget *layoutBaseWidget() const { return layoutBase; }
84
QList<QWidget*> m_widgets;
85
QWidget *m_parentWidget;
87
QMap<QPointer<QWidget>, QRect> geometries;
89
QDesignerFormWindowInterface *formWindow;
96
void widgetDestroyed();
100
class QT_SHARED_EXPORT HorizontalLayout : public Layout
103
HorizontalLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
105
virtual void doLayout();
109
class QT_SHARED_EXPORT VerticalLayout : public Layout
112
VerticalLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
114
virtual void doLayout();
118
class QT_SHARED_EXPORT StackedLayout : public Layout
121
StackedLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
123
virtual void doLayout();
130
class QT_SHARED_EXPORT GridLayout : public Layout
133
GridLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, const QSize &res);
136
virtual void doLayout();
140
QWidget *widgetAt(QGridLayout *layout, int row, int column) const;
149
class QT_SHARED_EXPORT WidgetVerticalSorter
152
bool operator()(const QWidget *a, const QWidget *b) const
153
{ return a->y() < b->y(); }
156
class QT_SHARED_EXPORT WidgetHorizontalSorter
159
bool operator()(const QWidget *a, const QWidget *b) const
160
{ return a->x() < b->x(); }
163
class VerticalLayoutList: public QList<QWidget*>
166
VerticalLayoutList(const QList<QWidget*> &l)
167
: QList<QWidget*>(l) {}
169
static bool lessThan(const QWidget *a, const QWidget *b)
170
{ return a->y() < b->y(); }
173
{ qSort(this->begin(), this->end(), WidgetVerticalSorter()); }
176
class HorizontalLayoutList : public QList<QWidget*>
179
HorizontalLayoutList(const QList<QWidget*> &l)
180
: QList<QWidget*>(l) {}
182
static bool hLessThan(const QWidget *a, const QWidget *b)
183
{ return a->x() < b->x(); }
186
{ qSort(this->begin(), this->end(), WidgetHorizontalSorter()); }
192
inline int indexOfWidget(QLayout *layout, QWidget *widget)
195
while (QLayoutItem *item = layout->itemAt(index)) {
196
if (item->widget() == widget)