~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/lib/shared/layout_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
//
 
30
//  W A R N I N G
 
31
//  -------------
 
32
//
 
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.
 
36
//
 
37
// We mean it.
 
38
//
 
39
 
 
40
#ifndef LAYOUT_H
 
41
#define LAYOUT_H
 
42
 
 
43
#include "shared_global_p.h"
 
44
#include "layoutinfo_p.h"
 
45
 
 
46
#include <QtCore/QPointer>
 
47
#include <QtCore/QObject>
 
48
#include <QtCore/QMap>
 
49
 
 
50
#include <QtGui/QLayout>
 
51
#include <QtGui/QGridLayout>
 
52
#include <QtGui/QWidget>
 
53
 
 
54
class QDesignerFormWindowInterface;
 
55
 
 
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);
 
59
 
 
60
class QT_SHARED_EXPORT Layout : public QObject
 
61
{
 
62
    Q_OBJECT
 
63
public:
 
64
    Layout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
 
65
    virtual ~Layout();
 
66
 
 
67
    int margin() const;
 
68
    int spacing() const;
 
69
 
 
70
    virtual void sort() = 0;
 
71
    virtual void doLayout() = 0;
 
72
 
 
73
    virtual void setup();
 
74
    virtual void undoLayout();
 
75
    virtual void breakLayout();
 
76
    virtual bool prepareLayout(bool &needMove, bool &needReparent);
 
77
    virtual void finishLayout(bool needMove, QLayout *layout);
 
78
 
 
79
    QList<QWidget*> widgets() const { return m_widgets; }
 
80
    QWidget *parentWidget() const { return m_parentWidget; }
 
81
    QWidget *layoutBaseWidget() const { return layoutBase; }
 
82
 
 
83
protected:
 
84
    QList<QWidget*> m_widgets;
 
85
    QWidget *m_parentWidget;
 
86
    QPoint startPoint;
 
87
    QMap<QPointer<QWidget>, QRect> geometries;
 
88
    QWidget *layoutBase;
 
89
    QDesignerFormWindowInterface *formWindow;
 
90
    QRect oldGeometry;
 
91
    bool isBreak;
 
92
    bool useSplitter;
 
93
 
 
94
 
 
95
protected slots:
 
96
    void widgetDestroyed();
 
97
 
 
98
};
 
99
 
 
100
class QT_SHARED_EXPORT HorizontalLayout : public Layout
 
101
{
 
102
public:
 
103
    HorizontalLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
 
104
 
 
105
    virtual void doLayout();
 
106
    virtual void sort();
 
107
};
 
108
 
 
109
class QT_SHARED_EXPORT VerticalLayout : public Layout
 
110
{
 
111
public:
 
112
    VerticalLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
 
113
 
 
114
    virtual void doLayout();
 
115
    virtual void sort();
 
116
};
 
117
 
 
118
class QT_SHARED_EXPORT StackedLayout : public Layout
 
119
{
 
120
public:
 
121
    StackedLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, bool splitter = false);
 
122
 
 
123
    virtual void doLayout();
 
124
    virtual void sort();
 
125
};
 
126
 
 
127
 
 
128
class Grid;
 
129
 
 
130
class QT_SHARED_EXPORT GridLayout : public Layout
 
131
{
 
132
public:
 
133
    GridLayout(const QList<QWidget*> &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb, const QSize &res);
 
134
    ~GridLayout();
 
135
 
 
136
    virtual void doLayout();
 
137
    virtual void sort();
 
138
 
 
139
protected:
 
140
    QWidget *widgetAt(QGridLayout *layout, int row, int column) const;
 
141
 
 
142
protected:
 
143
    void buildGrid();
 
144
    QSize resolution;
 
145
    Grid* grid;
 
146
 
 
147
};
 
148
 
 
149
class QT_SHARED_EXPORT WidgetVerticalSorter
 
150
{
 
151
public:
 
152
    bool operator()(const QWidget *a, const QWidget *b) const
 
153
    { return a->y() < b->y(); }
 
154
};
 
155
 
 
156
class QT_SHARED_EXPORT WidgetHorizontalSorter
 
157
{
 
158
public:
 
159
    bool operator()(const QWidget *a, const QWidget *b) const
 
160
    { return a->x() < b->x(); }
 
161
};
 
162
 
 
163
class VerticalLayoutList: public QList<QWidget*>
 
164
{
 
165
public:
 
166
    VerticalLayoutList(const QList<QWidget*> &l)
 
167
        : QList<QWidget*>(l) {}
 
168
 
 
169
    static bool lessThan(const QWidget *a, const QWidget *b)
 
170
    {  return a->y() < b->y(); }
 
171
 
 
172
    void sort()
 
173
    { qSort(this->begin(), this->end(), WidgetVerticalSorter()); }
 
174
};
 
175
 
 
176
class HorizontalLayoutList : public QList<QWidget*>
 
177
{
 
178
public:
 
179
    HorizontalLayoutList(const QList<QWidget*> &l)
 
180
        : QList<QWidget*>(l) {}
 
181
 
 
182
    static bool hLessThan(const QWidget *a, const QWidget *b)
 
183
    { return a->x() < b->x(); }
 
184
 
 
185
    void sort()
 
186
    { qSort(this->begin(), this->end(), WidgetHorizontalSorter()); }
 
187
};
 
188
 
 
189
namespace Utils
 
190
{
 
191
 
 
192
inline int indexOfWidget(QLayout *layout, QWidget *widget)
 
193
{
 
194
    int index = 0;
 
195
    while (QLayoutItem *item = layout->itemAt(index)) {
 
196
        if (item->widget() == widget)
 
197
            return index;
 
198
 
 
199
        ++index;
 
200
    }
 
201
 
 
202
    return -1;
 
203
}
 
204
 
 
205
} // namespace Utils
 
206
 
 
207
#endif // LAYOUT_H