annotate examples/layouts/borderlayout/borderlayout.d @ 322:7c2cf27391c4 signals

A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
author eldar_ins@eldar-laptop
date Sun, 27 Dec 2009 21:13:38 +0500
parents 6aeaf24018d7
children 778ef7374fb5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
1 /****************************************************************************
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
2 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
4 ** Contact: Qt Software Information (qt-info@nokia.com)
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
5 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
6 ** This file is part of the examples of the Qt Toolkit.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
7 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
8 ** $QT_BEGIN_LICENSE:LGPL$
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
9 ** Commercial Usage
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
10 ** Licensees holding valid Qt Commercial licenses may use this file in
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
11 ** accordance with the Qt Commercial License Agreement provided with the
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
12 ** Software or, alternatively, in accordance with the terms contained in
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
13 ** a written agreement between you and Nokia.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
14 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
15 ** GNU Lesser General Public License Usage
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
17 ** General Public License version 2.1 as published by the Free Software
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
19 ** packaging of this file. Please review the following information to
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
22 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
23 ** In addition, as a special exception, Nokia gives you certain
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
24 ** additional rights. These rights are described in the Nokia Qt LGPL
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
26 ** package.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
27 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
28 ** GNU General Public License Usage
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
29 ** Alternatively, this file may be used under the terms of the GNU
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
30 ** General Public License version 3.0 as published by the Free Software
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
31 ** Foundation and appearing in the file LICENSE.GPL included in the
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
32 ** packaging of this file. Please review the following information to
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
33 ** ensure the GNU General Public License version 3.0 requirements will be
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
34 ** met: http://www.gnu.org/copyleft/gpl.html.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
35 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
36 ** If you are unsure which license is appropriate for your use, please
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
37 ** contact the sales department at qt-sales@nokia.com.
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
38 ** $QT_END_LICENSE$
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
39 **
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
40 ****************************************************************************/
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
41 module borderlayout;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
42
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
43
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
44 import qt.gui.QLayout;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
45 import qt.gui.QWidgetItem;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
46 import qt.gui.QTextBrowser;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
47 import qt.core.QSize;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
48 import qt.core.QRect;
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
49
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
50
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
51 class BorderLayout : public QLayout
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
52 {
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
53 public:
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
54
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
55 enum Position { West, North, South, East, Center };
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
56
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
57 this(QWidget parent, int margin = 0, int spacing = -1)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
58 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
59 super(parent);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
60 setMargin(margin);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
61 setWidgetSpacing(spacing);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
62 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
63
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
64 this(int spacing = -1)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
65 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
66 setWidgetSpacing(spacing);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
67 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
68
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
69 ~this()
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
70 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
71 QLayoutItem l = takeAt(0);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
72 while (l) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
73 delete l;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
74 l = takeAt(0);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
75 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
76 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
77
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
78 void addWidget(QWidget widget, Position position)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
79 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
80 add(cast(IQLayoutItem) new QWidgetItem(widget), position);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
81 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
82
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
83 void add(IQLayoutItem item, Position position)
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
84 {
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
85 list ~= new ItemWrapper(item, position);
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
86 }
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
87
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
88 override
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
89 {
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
90 void addItem(IQLayoutItem item)
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
91 {
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
92 add(item, Position.West);
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
93 }
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
94
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
95 int expandingDirections() const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
96 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
97 return Qt.Horizontal | Qt.Vertical;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
98 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
99
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
100 bool hasHeightForWidth() const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
101 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
102 return false;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
103 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
104
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
105 int count() const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
106 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
107 return list.length;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
108 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
109
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
110 IQLayoutItem itemAt(int index) const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
111 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
112 if(index >= 0 && index < list.length)
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
113 return cast(IQLayoutItem) list[index].item;
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
114 else
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
115 return null;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
116 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
117
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
118 QSize minimumSize() const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
119 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
120 return calculateSize(SizeType.MinimumSize);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
121 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
122
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
123 void setGeometry(const QRect rect)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
124 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
125 ItemWrapper center = null;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
126 int eastWidth = 0;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
127 int westWidth = 0;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
128 int northHeight = 0;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
129 int southHeight = 0;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
130 int centerHeight = 0;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
131 int i;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
132
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
133 super.setGeometry(rect);
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
134
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
135 for (i = 0; i < list.length; ++i) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
136 ItemWrapper wrapper = list[i];
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
137 IQLayoutItem item = wrapper.item;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
138 Position position = wrapper.position;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
139
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
140 if (position == Position.North) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
141 item.setGeometry(QRect(rect.x(), northHeight, rect.width(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
142 item.sizeHint().height()));
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
143
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
144 northHeight += item.geometry().height() + widgetSpacing();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
145 } else if (position == Position.South) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
146 item.setGeometry(QRect(item.geometry().x(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
147 item.geometry().y(), rect.width(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
148 item.sizeHint().height()));
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
149
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
150 southHeight += item.geometry().height() + widgetSpacing();
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
151
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
152 item.setGeometry(QRect(rect.x(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
153 rect.y() + rect.height() - southHeight + widgetSpacing(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
154 item.geometry().width(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
155 item.geometry().height()));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
156 } else if (position == Position.Center) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
157 center = wrapper;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
158 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
159 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
160
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
161 centerHeight = rect.height() - northHeight - southHeight;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
162
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
163 for (i = 0; i < list.length; ++i) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
164 ItemWrapper wrapper = list[i];
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
165 IQLayoutItem item = wrapper.item;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
166 Position position = wrapper.position;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
167
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
168 if (position == Position.West) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
169 item.setGeometry(QRect(rect.x() + westWidth, northHeight,
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
170 item.sizeHint().width(), centerHeight));
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
171
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
172 westWidth += item.geometry().width() + widgetSpacing();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
173 } else if (position == Position.East) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
174 item.setGeometry(QRect(item.geometry().x(), item.geometry().y(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
175 item.sizeHint().width(), centerHeight));
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
176
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
177 eastWidth += item.geometry().width() + widgetSpacing();
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
178
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
179 item.setGeometry(QRect(
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
180 rect.x() + rect.width() - eastWidth + widgetSpacing(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
181 northHeight, item.geometry().width(),
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
182 item.geometry().height()));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
183 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
184 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
185
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
186 if (center)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
187 center.item.setGeometry(QRect(westWidth, northHeight,
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
188 rect.width() - eastWidth - westWidth,
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
189 centerHeight));
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
190 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
191
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
192 QSize sizeHint() const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
193 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
194 return calculateSize(SizeType.SizeHint);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
195 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
196
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
197 QLayoutItem takeAt(int index)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
198 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
199 if (index >= 0 && index < list.length) {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
200 ItemWrapper layoutStruct = list[index];
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
201 return layoutStruct.item;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
202 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
203 return null;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
204 }
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
205 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
206
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
207 private:
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
208
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
209 class ItemWrapper
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
210 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
211 this(IQLayoutItem i, Position p)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
212 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
213 item = i;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
214 position = p;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
215 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
216
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
217 IQLayoutItem item;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
218 Position position;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
219 };
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
220
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
221 enum SizeType { MinimumSize, SizeHint };
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
222
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
223 QSize calculateSize(SizeType sizeType) const
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
224 {
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
225 QSize totalSize;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
226
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
227 for (int i = 0; i < list.length; ++i) {
322
7c2cf27391c4 A slight change of the connect syntax. More sofisticated signals/slots lookup. Some fixes in examples.
eldar_ins@eldar-laptop
parents: 204
diff changeset
228 const ItemWrapper wrapper = list[i];
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
229 Position position = wrapper.position;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
230 QSize itemSize;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
231
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
232 if (sizeType == SizeType.MinimumSize)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
233 itemSize = wrapper.item.minimumSize();
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
234 else // (sizeType == SizeHint)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
235 itemSize = wrapper.item.sizeHint();
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
236
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
237 if (position == Position.North || position == Position.South || position == Position.Center)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
238 totalSize.setHeight(totalSize.height + itemSize.height);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
239
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
240 if (position == Position.West || position == Position.East || position == Position.Center)
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
241 totalSize.setWidth(totalSize.width + itemSize.width);
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
242 }
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
243 return totalSize;
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
244 }
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
245
204
6aeaf24018d7 more D2 examples fixes
eldar
parents: 118
diff changeset
246 ItemWrapper[] list;
118
c28c0340fdf3 add borderlayout example
mandel
parents:
diff changeset
247 }