author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 19 | fcece45ef507 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "QtGui/qapplication.h" |
|
43 |
#include "QtGui/qwidget.h" |
|
44 |
#include "QtGui/qtabbar.h" |
|
45 |
#include "QtGui/qstyle.h" |
|
46 |
#include "QtGui/qdesktopwidget.h" |
|
47 |
#include "QtCore/qvariant.h" |
|
48 |
#include "qdockarealayout_p.h" |
|
49 |
#include "qdockwidget.h" |
|
50 |
#include "qmainwindow.h" |
|
51 |
#include "qwidgetanimator_p.h" |
|
52 |
#include "qmainwindowlayout_p.h" |
|
53 |
#include "qdockwidget_p.h" |
|
54 |
#include <private/qlayoutengine_p.h> |
|
55 |
||
56 |
#include <qpainter.h> |
|
57 |
#include <qstyleoption.h> |
|
58 |
||
59 |
#ifndef QT_NO_DOCKWIDGET |
|
60 |
||
61 |
QT_BEGIN_NAMESPACE |
|
62 |
||
63 |
enum { StateFlagVisible = 1, StateFlagFloating = 2 }; |
|
64 |
||
65 |
/****************************************************************************** |
|
66 |
** QPlaceHolderItem |
|
67 |
*/ |
|
68 |
||
69 |
QPlaceHolderItem::QPlaceHolderItem(QWidget *w) |
|
70 |
{ |
|
71 |
objectName = w->objectName(); |
|
72 |
hidden = w->isHidden(); |
|
73 |
window = w->isWindow(); |
|
74 |
if (window) |
|
75 |
topLevelRect = w->geometry(); |
|
76 |
} |
|
77 |
||
78 |
/****************************************************************************** |
|
79 |
** QDockAreaLayoutItem |
|
80 |
*/ |
|
81 |
||
82 |
QDockAreaLayoutItem::QDockAreaLayoutItem(QLayoutItem *_widgetItem) |
|
83 |
: widgetItem(_widgetItem), subinfo(0), placeHolderItem(0), pos(0), size(-1), flags(NoFlags) |
|
84 |
{ |
|
85 |
} |
|
86 |
||
87 |
QDockAreaLayoutItem::QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo) |
|
88 |
: widgetItem(0), subinfo(_subinfo), placeHolderItem(0), pos(0), size(-1), flags(NoFlags) |
|
89 |
{ |
|
90 |
} |
|
91 |
||
92 |
QDockAreaLayoutItem::QDockAreaLayoutItem(QPlaceHolderItem *_placeHolderItem) |
|
93 |
: widgetItem(0), subinfo(0), placeHolderItem(_placeHolderItem), pos(0), size(-1), flags(NoFlags) |
|
94 |
{ |
|
95 |
} |
|
96 |
||
97 |
QDockAreaLayoutItem::QDockAreaLayoutItem(const QDockAreaLayoutItem &other) |
|
98 |
: widgetItem(other.widgetItem), subinfo(0), placeHolderItem(0), pos(other.pos), |
|
99 |
size(other.size), flags(other.flags) |
|
100 |
{ |
|
101 |
if (other.subinfo != 0) |
|
102 |
subinfo = new QDockAreaLayoutInfo(*other.subinfo); |
|
103 |
else if (other.placeHolderItem != 0) |
|
104 |
placeHolderItem = new QPlaceHolderItem(*other.placeHolderItem); |
|
105 |
} |
|
106 |
||
107 |
QDockAreaLayoutItem::~QDockAreaLayoutItem() |
|
108 |
{ |
|
109 |
delete subinfo; |
|
110 |
delete placeHolderItem; |
|
111 |
} |
|
112 |
||
113 |
bool QDockAreaLayoutItem::skip() const |
|
114 |
{ |
|
115 |
if (placeHolderItem != 0) |
|
116 |
return true; |
|
117 |
||
118 |
if (flags & GapItem) |
|
119 |
return false; |
|
120 |
||
121 |
if (widgetItem != 0) |
|
122 |
return widgetItem->isEmpty(); |
|
123 |
||
124 |
if (subinfo != 0) { |
|
125 |
for (int i = 0; i < subinfo->item_list.count(); ++i) { |
|
126 |
if (!subinfo->item_list.at(i).skip()) |
|
127 |
return false; |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
return true; |
|
132 |
} |
|
133 |
||
134 |
QSize QDockAreaLayoutItem::minimumSize() const |
|
135 |
{ |
|
136 |
if (widgetItem != 0) { |
|
137 |
int left, top, right, bottom; |
|
138 |
widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); |
|
139 |
return widgetItem->minimumSize() + QSize(left+right, top+bottom); |
|
140 |
} |
|
141 |
if (subinfo != 0) |
|
142 |
return subinfo->minimumSize(); |
|
143 |
return QSize(0, 0); |
|
144 |
} |
|
145 |
||
146 |
QSize QDockAreaLayoutItem::maximumSize() const |
|
147 |
{ |
|
148 |
if (widgetItem != 0) { |
|
149 |
int left, top, right, bottom; |
|
150 |
widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); |
|
151 |
return widgetItem->maximumSize()+ QSize(left+right, top+bottom); |
|
152 |
} |
|
153 |
if (subinfo != 0) |
|
154 |
return subinfo->maximumSize(); |
|
155 |
return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); |
|
156 |
} |
|
157 |
||
158 |
bool QDockAreaLayoutItem::hasFixedSize(Qt::Orientation o) const |
|
159 |
{ |
|
160 |
return perp(o, minimumSize()) == perp(o, maximumSize()); |
|
161 |
} |
|
162 |
||
163 |
bool QDockAreaLayoutItem::expansive(Qt::Orientation o) const |
|
164 |
{ |
|
165 |
if ((flags & GapItem) || placeHolderItem != 0) |
|
166 |
return false; |
|
167 |
if (widgetItem != 0) |
|
168 |
return ((widgetItem->expandingDirections() & o) == o); |
|
169 |
if (subinfo != 0) |
|
170 |
return subinfo->expansive(o); |
|
171 |
return false; |
|
172 |
} |
|
173 |
||
174 |
QSize QDockAreaLayoutItem::sizeHint() const |
|
175 |
{ |
|
176 |
if (placeHolderItem != 0) |
|
177 |
return QSize(0, 0); |
|
178 |
if (widgetItem != 0) { |
|
179 |
int left, top, right, bottom; |
|
180 |
widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); |
|
181 |
return widgetItem->sizeHint() + QSize(left+right, top+bottom); |
|
182 |
} |
|
183 |
if (subinfo != 0) |
|
184 |
return subinfo->sizeHint(); |
|
185 |
return QSize(-1, -1); |
|
186 |
} |
|
187 |
||
188 |
QDockAreaLayoutItem |
|
189 |
&QDockAreaLayoutItem::operator = (const QDockAreaLayoutItem &other) |
|
190 |
{ |
|
191 |
widgetItem = other.widgetItem; |
|
192 |
if (other.subinfo == 0) |
|
193 |
subinfo = 0; |
|
194 |
else |
|
195 |
subinfo = new QDockAreaLayoutInfo(*other.subinfo); |
|
196 |
||
197 |
delete placeHolderItem; |
|
198 |
if (other.placeHolderItem == 0) |
|
199 |
placeHolderItem = 0; |
|
200 |
else |
|
201 |
placeHolderItem = new QPlaceHolderItem(*other.placeHolderItem); |
|
202 |
||
203 |
pos = other.pos; |
|
204 |
size = other.size; |
|
205 |
flags = other.flags; |
|
206 |
||
207 |
return *this; |
|
208 |
} |
|
209 |
||
210 |
/****************************************************************************** |
|
211 |
** QDockAreaLayoutInfo |
|
212 |
*/ |
|
213 |
||
214 |
#ifndef QT_NO_TABBAR |
|
215 |
static quintptr tabId(const QDockAreaLayoutItem &item) |
|
216 |
{ |
|
217 |
if (item.widgetItem == 0) |
|
218 |
return 0; |
|
219 |
return reinterpret_cast<quintptr>(item.widgetItem->widget()); |
|
220 |
} |
|
221 |
#endif |
|
222 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
223 |
static const int zero = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
224 |
|
0 | 225 |
QDockAreaLayoutInfo::QDockAreaLayoutInfo() |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
226 |
: sep(&zero), dockPos(QInternal::LeftDock), o(Qt::Horizontal), mainWindow(0) |
0 | 227 |
#ifndef QT_NO_TABBAR |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
228 |
, tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth) |
0 | 229 |
#endif |
230 |
{ |
|
231 |
} |
|
232 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
233 |
QDockAreaLayoutInfo::QDockAreaLayoutInfo(const int *_sep, QInternal::DockPosition _dockPos, |
0 | 234 |
Qt::Orientation _o, int tbshape, |
235 |
QMainWindow *window) |
|
236 |
: sep(_sep), dockPos(_dockPos), o(_o), mainWindow(window) |
|
237 |
#ifndef QT_NO_TABBAR |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
238 |
, tabbed(false), tabBar(0), tabBarShape(static_cast<QTabBar::Shape>(tbshape)) |
0 | 239 |
#endif |
240 |
{ |
|
241 |
#ifdef QT_NO_TABBAR |
|
242 |
Q_UNUSED(tbshape); |
|
243 |
#endif |
|
244 |
} |
|
245 |
||
246 |
QSize QDockAreaLayoutInfo::size() const |
|
247 |
{ |
|
248 |
return isEmpty() ? QSize(0, 0) : rect.size(); |
|
249 |
} |
|
250 |
||
251 |
void QDockAreaLayoutInfo::clear() |
|
252 |
{ |
|
253 |
item_list.clear(); |
|
254 |
rect = QRect(); |
|
255 |
#ifndef QT_NO_TABBAR |
|
256 |
tabbed = false; |
|
257 |
tabBar = 0; |
|
258 |
#endif |
|
259 |
} |
|
260 |
||
261 |
bool QDockAreaLayoutInfo::isEmpty() const |
|
262 |
{ |
|
263 |
return next(-1) == -1; |
|
264 |
} |
|
265 |
||
266 |
QSize QDockAreaLayoutInfo::minimumSize() const |
|
267 |
{ |
|
268 |
if (isEmpty()) |
|
269 |
return QSize(0, 0); |
|
270 |
||
271 |
int a = 0, b = 0; |
|
272 |
bool first = true; |
|
273 |
for (int i = 0; i < item_list.size(); ++i) { |
|
274 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
275 |
if (item.skip()) |
|
276 |
continue; |
|
277 |
||
278 |
QSize min_size = item.minimumSize(); |
|
279 |
#ifndef QT_NO_TABBAR |
|
280 |
if (tabbed) { |
|
281 |
a = qMax(a, pick(o, min_size)); |
|
282 |
} else |
|
283 |
#endif |
|
284 |
{ |
|
285 |
if (!first) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
286 |
a += *sep; |
0 | 287 |
a += pick(o, min_size); |
288 |
} |
|
289 |
b = qMax(b, perp(o, min_size)); |
|
290 |
||
291 |
first = false; |
|
292 |
} |
|
293 |
||
294 |
QSize result; |
|
295 |
rpick(o, result) = a; |
|
296 |
rperp(o, result) = b; |
|
297 |
||
298 |
#ifndef QT_NO_TABBAR |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
299 |
QSize tbm = tabBarMinimumSize(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
300 |
if (!tbm.isNull()) { |
0 | 301 |
switch (tabBarShape) { |
302 |
case QTabBar::RoundedNorth: |
|
303 |
case QTabBar::RoundedSouth: |
|
304 |
case QTabBar::TriangularNorth: |
|
305 |
case QTabBar::TriangularSouth: |
|
306 |
result.rheight() += tbm.height(); |
|
307 |
result.rwidth() = qMax(tbm.width(), result.width()); |
|
308 |
break; |
|
309 |
case QTabBar::RoundedEast: |
|
310 |
case QTabBar::RoundedWest: |
|
311 |
case QTabBar::TriangularEast: |
|
312 |
case QTabBar::TriangularWest: |
|
313 |
result.rheight() = qMax(tbm.height(), result.height()); |
|
314 |
result.rwidth() += tbm.width(); |
|
315 |
break; |
|
316 |
default: |
|
317 |
break; |
|
318 |
} |
|
319 |
} |
|
320 |
#endif // QT_NO_TABBAR |
|
321 |
||
322 |
return result; |
|
323 |
} |
|
324 |
||
325 |
QSize QDockAreaLayoutInfo::maximumSize() const |
|
326 |
{ |
|
327 |
if (isEmpty()) |
|
328 |
return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); |
|
329 |
||
330 |
int a = 0, b = QWIDGETSIZE_MAX; |
|
331 |
#ifndef QT_NO_TABBAR |
|
332 |
if (tabbed) |
|
333 |
a = QWIDGETSIZE_MAX; |
|
334 |
#endif |
|
335 |
||
336 |
int min_perp = 0; |
|
337 |
||
338 |
bool first = true; |
|
339 |
for (int i = 0; i < item_list.size(); ++i) { |
|
340 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
341 |
if (item.skip()) |
|
342 |
continue; |
|
343 |
||
344 |
QSize max_size = item.maximumSize(); |
|
345 |
min_perp = qMax(min_perp, perp(o, item.minimumSize())); |
|
346 |
||
347 |
#ifndef QT_NO_TABBAR |
|
348 |
if (tabbed) { |
|
349 |
a = qMin(a, pick(o, max_size)); |
|
350 |
} else |
|
351 |
#endif |
|
352 |
{ |
|
353 |
if (!first) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
354 |
a += *sep; |
0 | 355 |
a += pick(o, max_size); |
356 |
} |
|
357 |
b = qMin(b, perp(o, max_size)); |
|
358 |
||
359 |
a = qMin(a, int(QWIDGETSIZE_MAX)); |
|
360 |
b = qMin(b, int(QWIDGETSIZE_MAX)); |
|
361 |
||
362 |
first = false; |
|
363 |
} |
|
364 |
||
365 |
b = qMax(b, min_perp); |
|
366 |
||
367 |
QSize result; |
|
368 |
rpick(o, result) = a; |
|
369 |
rperp(o, result) = b; |
|
370 |
||
371 |
#ifndef QT_NO_TABBAR |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
372 |
QSize tbh = tabBarSizeHint(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
373 |
if (!tbh.isNull()) { |
0 | 374 |
switch (tabBarShape) { |
375 |
case QTabBar::RoundedNorth: |
|
376 |
case QTabBar::RoundedSouth: |
|
377 |
result.rheight() += tbh.height(); |
|
378 |
break; |
|
379 |
case QTabBar::RoundedEast: |
|
380 |
case QTabBar::RoundedWest: |
|
381 |
result.rwidth() += tbh.width(); |
|
382 |
break; |
|
383 |
default: |
|
384 |
break; |
|
385 |
} |
|
386 |
} |
|
387 |
#endif // QT_NO_TABBAR |
|
388 |
||
389 |
return result; |
|
390 |
} |
|
391 |
||
392 |
QSize QDockAreaLayoutInfo::sizeHint() const |
|
393 |
{ |
|
394 |
if (isEmpty()) |
|
395 |
return QSize(0, 0); |
|
396 |
||
397 |
int a = 0, b = 0; |
|
398 |
int min_perp = 0; |
|
399 |
int max_perp = QWIDGETSIZE_MAX; |
|
400 |
const QDockAreaLayoutItem *previous = 0; |
|
401 |
for (int i = 0; i < item_list.size(); ++i) { |
|
402 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
403 |
if (item.skip()) |
|
404 |
continue; |
|
405 |
||
406 |
bool gap = item.flags & QDockAreaLayoutItem::GapItem; |
|
407 |
||
408 |
QSize size_hint = item.sizeHint(); |
|
409 |
min_perp = qMax(min_perp, perp(o, item.minimumSize())); |
|
410 |
max_perp = qMin(max_perp, perp(o, item.maximumSize())); |
|
411 |
||
412 |
#ifndef QT_NO_TABBAR |
|
413 |
if (tabbed) { |
|
414 |
a = qMax(a, gap ? item.size : pick(o, size_hint)); |
|
415 |
} else |
|
416 |
#endif |
|
417 |
{ |
|
418 |
if (previous && !gap && !(previous->flags & QDockAreaLayoutItem::GapItem) |
|
419 |
&& !previous->hasFixedSize(o)) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
420 |
a += *sep; |
0 | 421 |
} |
422 |
a += gap ? item.size : pick(o, size_hint); |
|
423 |
} |
|
424 |
b = qMax(b, perp(o, size_hint)); |
|
425 |
||
426 |
previous = &item; |
|
427 |
} |
|
428 |
||
429 |
max_perp = qMax(max_perp, min_perp); |
|
430 |
b = qMax(b, min_perp); |
|
431 |
b = qMin(b, max_perp); |
|
432 |
||
433 |
QSize result; |
|
434 |
rpick(o, result) = a; |
|
435 |
rperp(o, result) = b; |
|
436 |
||
437 |
#ifndef QT_NO_TABBAR |
|
438 |
if (tabbed) { |
|
439 |
QSize tbh = tabBarSizeHint(); |
|
440 |
switch (tabBarShape) { |
|
441 |
case QTabBar::RoundedNorth: |
|
442 |
case QTabBar::RoundedSouth: |
|
443 |
case QTabBar::TriangularNorth: |
|
444 |
case QTabBar::TriangularSouth: |
|
445 |
result.rheight() += tbh.height(); |
|
446 |
result.rwidth() = qMax(tbh.width(), result.width()); |
|
447 |
break; |
|
448 |
case QTabBar::RoundedEast: |
|
449 |
case QTabBar::RoundedWest: |
|
450 |
case QTabBar::TriangularEast: |
|
451 |
case QTabBar::TriangularWest: |
|
452 |
result.rheight() = qMax(tbh.height(), result.height()); |
|
453 |
result.rwidth() += tbh.width(); |
|
454 |
break; |
|
455 |
default: |
|
456 |
break; |
|
457 |
} |
|
458 |
} |
|
459 |
#endif // QT_NO_TABBAR |
|
460 |
||
461 |
return result; |
|
462 |
} |
|
463 |
||
464 |
bool QDockAreaLayoutInfo::expansive(Qt::Orientation o) const |
|
465 |
{ |
|
466 |
for (int i = 0; i < item_list.size(); ++i) { |
|
467 |
if (item_list.at(i).expansive(o)) |
|
468 |
return true; |
|
469 |
} |
|
470 |
return false; |
|
471 |
} |
|
472 |
||
473 |
/* QDockAreaLayoutInfo::maximumSize() doesn't return the real max size. For example, |
|
474 |
if the layout is empty, it returns QWIDGETSIZE_MAX. This is so that empty dock areas |
|
475 |
don't constrain the size of the QMainWindow, but sometimes we really need to know the |
|
476 |
maximum size. Also, these functions take into account widgets that want to keep their |
|
477 |
size (f.ex. when they are hidden and then shown, they should not change size). |
|
478 |
*/ |
|
479 |
||
480 |
static int realMinSize(const QDockAreaLayoutInfo &info) |
|
481 |
{ |
|
482 |
int result = 0; |
|
483 |
bool first = true; |
|
484 |
for (int i = 0; i < info.item_list.size(); ++i) { |
|
485 |
const QDockAreaLayoutItem &item = info.item_list.at(i); |
|
486 |
if (item.skip()) |
|
487 |
continue; |
|
488 |
||
489 |
int min = 0; |
|
490 |
if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1) |
|
491 |
min = item.size; |
|
492 |
else |
|
493 |
min = pick(info.o, item.minimumSize()); |
|
494 |
||
495 |
if (!first) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
496 |
result += *info.sep; |
0 | 497 |
result += min; |
498 |
||
499 |
first = false; |
|
500 |
} |
|
501 |
||
502 |
return result; |
|
503 |
} |
|
504 |
||
505 |
static int realMaxSize(const QDockAreaLayoutInfo &info) |
|
506 |
{ |
|
507 |
int result = 0; |
|
508 |
bool first = true; |
|
509 |
for (int i = 0; i < info.item_list.size(); ++i) { |
|
510 |
const QDockAreaLayoutItem &item = info.item_list.at(i); |
|
511 |
if (item.skip()) |
|
512 |
continue; |
|
513 |
||
514 |
int max = 0; |
|
515 |
if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1) |
|
516 |
max = item.size; |
|
517 |
else |
|
518 |
max = pick(info.o, item.maximumSize()); |
|
519 |
||
520 |
if (!first) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
521 |
result += *info.sep; |
0 | 522 |
result += max; |
523 |
||
524 |
if (result >= QWIDGETSIZE_MAX) |
|
525 |
return QWIDGETSIZE_MAX; |
|
526 |
||
527 |
first = false; |
|
528 |
} |
|
529 |
||
530 |
return result; |
|
531 |
} |
|
532 |
||
533 |
void QDockAreaLayoutInfo::fitItems() |
|
534 |
{ |
|
535 |
#ifndef QT_NO_TABBAR |
|
536 |
if (tabbed) { |
|
537 |
return; |
|
538 |
} |
|
539 |
#endif |
|
540 |
||
541 |
QVector<QLayoutStruct> layout_struct_list(item_list.size()*2); |
|
542 |
int j = 0; |
|
543 |
||
544 |
int size = pick(o, rect.size()); |
|
545 |
int min_size = realMinSize(*this); |
|
546 |
int max_size = realMaxSize(*this); |
|
547 |
int last_index = -1; |
|
548 |
||
549 |
const QDockAreaLayoutItem *previous = 0; |
|
550 |
for (int i = 0; i < item_list.size(); ++i) { |
|
551 |
QDockAreaLayoutItem &item = item_list[i]; |
|
552 |
if (item.skip()) |
|
553 |
continue; |
|
554 |
||
555 |
bool gap = item.flags & QDockAreaLayoutItem::GapItem; |
|
556 |
if (previous && !gap) { |
|
557 |
if (!(previous->flags & QDockAreaLayoutItem::GapItem)) { |
|
558 |
QLayoutStruct &ls = layout_struct_list[j++]; |
|
559 |
ls.init(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
560 |
ls.minimumSize = ls.maximumSize = ls.sizeHint = previous->hasFixedSize(o) ? 0 : *sep; |
0 | 561 |
ls.empty = false; |
562 |
} |
|
563 |
} |
|
564 |
||
565 |
if (item.flags & QDockAreaLayoutItem::KeepSize) { |
|
566 |
// Check if the item can keep its size, without violating size constraints |
|
567 |
// of other items. |
|
568 |
||
569 |
if (size < min_size) { |
|
570 |
// There is too little space to keep this widget's size |
|
571 |
item.flags &= ~QDockAreaLayoutItem::KeepSize; |
|
572 |
min_size -= item.size; |
|
573 |
min_size += pick(o, item.minimumSize()); |
|
574 |
min_size = qMax(0, min_size); |
|
575 |
} else if (size > max_size) { |
|
576 |
// There is too much space to keep this widget's size |
|
577 |
item.flags &= ~QDockAreaLayoutItem::KeepSize; |
|
578 |
max_size -= item.size; |
|
579 |
max_size += pick(o, item.maximumSize()); |
|
580 |
max_size = qMin<int>(QWIDGETSIZE_MAX, max_size); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
last_index = j; |
|
585 |
QLayoutStruct &ls = layout_struct_list[j++]; |
|
586 |
ls.init(); |
|
587 |
ls.empty = false; |
|
588 |
if (item.flags & QDockAreaLayoutItem::KeepSize) { |
|
589 |
ls.minimumSize = ls.maximumSize = ls.sizeHint = item.size; |
|
590 |
ls.expansive = false; |
|
591 |
ls.stretch = 0; |
|
592 |
} else { |
|
593 |
ls.maximumSize = pick(o, item.maximumSize()); |
|
594 |
ls.expansive = item.expansive(o); |
|
595 |
ls.minimumSize = pick(o, item.minimumSize()); |
|
596 |
ls.sizeHint = item.size == -1 ? pick(o, item.sizeHint()) : item.size; |
|
597 |
ls.stretch = ls.expansive ? ls.sizeHint : 0; |
|
598 |
} |
|
599 |
||
600 |
item.flags &= ~QDockAreaLayoutItem::KeepSize; |
|
601 |
previous = &item; |
|
602 |
} |
|
603 |
layout_struct_list.resize(j); |
|
604 |
||
605 |
// If there is more space than the widgets can take (due to maximum size constraints), |
|
606 |
// we detect it here and stretch the last widget to take up the rest of the space. |
|
607 |
if (size > max_size && last_index != -1) { |
|
608 |
layout_struct_list[last_index].maximumSize = QWIDGETSIZE_MAX; |
|
609 |
layout_struct_list[last_index].expansive = true; |
|
610 |
} |
|
611 |
||
612 |
qGeomCalc(layout_struct_list, 0, j, pick(o, rect.topLeft()), size, 0); |
|
613 |
||
614 |
j = 0; |
|
615 |
bool prev_gap = false; |
|
616 |
bool first = true; |
|
617 |
for (int i = 0; i < item_list.size(); ++i) { |
|
618 |
QDockAreaLayoutItem &item = item_list[i]; |
|
619 |
if (item.skip()) |
|
620 |
continue; |
|
621 |
||
622 |
bool gap = item.flags & QDockAreaLayoutItem::GapItem; |
|
623 |
if (!first && !gap && !prev_gap) |
|
624 |
++j; |
|
625 |
||
626 |
const QLayoutStruct &ls = layout_struct_list.at(j++); |
|
627 |
item.size = ls.size; |
|
628 |
item.pos = ls.pos; |
|
629 |
||
630 |
if (item.subinfo != 0) { |
|
631 |
item.subinfo->rect = itemRect(i); |
|
632 |
item.subinfo->fitItems(); |
|
633 |
} |
|
634 |
||
635 |
prev_gap = gap; |
|
636 |
first = false; |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_pos, |
|
641 |
Qt::Orientation o, |
|
642 |
bool nestingEnabled, |
|
643 |
QDockAreaLayoutInfo::TabMode tabMode) |
|
644 |
{ |
|
645 |
if (tabMode == QDockAreaLayoutInfo::ForceTabs) |
|
646 |
return QInternal::DockCount; |
|
647 |
||
648 |
QPoint pos = _pos - rect.topLeft(); |
|
649 |
||
650 |
int x = pos.x(); |
|
651 |
int y = pos.y(); |
|
652 |
int w = rect.width(); |
|
653 |
int h = rect.height(); |
|
654 |
||
655 |
if (tabMode != QDockAreaLayoutInfo::NoTabs) { |
|
656 |
// is it in the center? |
|
657 |
if (nestingEnabled) { |
|
658 |
/* 2/3 |
|
659 |
+--------------+ |
|
660 |
| | |
|
661 |
| CCCCCCCC | |
|
662 |
2/3 | CCCCCCCC | |
|
663 |
| CCCCCCCC | |
|
664 |
| | |
|
665 |
+--------------+ */ |
|
666 |
||
667 |
QRect center(w/6, h/6, 2*w/3, 2*h/3); |
|
668 |
if (center.contains(pos)) |
|
669 |
return QInternal::DockCount; |
|
670 |
} else if (o == Qt::Horizontal) { |
|
671 |
/* 2/3 |
|
672 |
+--------------+ |
|
673 |
| CCCCCCCC | |
|
674 |
| CCCCCCCC | |
|
675 |
| CCCCCCCC | |
|
676 |
| CCCCCCCC | |
|
677 |
| CCCCCCCC | |
|
678 |
+--------------+ */ |
|
679 |
||
680 |
if (x > w/6 && x < w*5/6) |
|
681 |
return QInternal::DockCount; |
|
682 |
} else { |
|
683 |
/* |
|
684 |
+--------------+ |
|
685 |
| | |
|
686 |
2/3 |CCCCCCCCCCCCCC| |
|
687 |
|CCCCCCCCCCCCCC| |
|
688 |
| | |
|
689 |
+--------------+ */ |
|
690 |
if (y > h/6 && y < 5*h/6) |
|
691 |
return QInternal::DockCount; |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
// not in the center. which edge? |
|
696 |
if (nestingEnabled) { |
|
697 |
if (o == Qt::Horizontal) { |
|
698 |
/* 1/3 1/3 1/3 |
|
699 |
+------------+ (we've already ruled out the center) |
|
700 |
|LLLLTTTTRRRR| |
|
701 |
|LLLLTTTTRRRR| |
|
702 |
|LLLLBBBBRRRR| |
|
703 |
|LLLLBBBBRRRR| |
|
704 |
+------------+ */ |
|
705 |
||
706 |
if (x < w/3) |
|
707 |
return QInternal::LeftDock; |
|
708 |
if (x > 2*w/3) |
|
709 |
return QInternal::RightDock; |
|
710 |
if (y < h/2) |
|
711 |
return QInternal::TopDock; |
|
712 |
return QInternal::BottomDock; |
|
713 |
} else { |
|
714 |
/* +------------+ (we've already ruled out the center) |
|
715 |
1/3 |TTTTTTTTTTTT| |
|
716 |
|LLLLLLRRRRRR| |
|
717 |
1/3 |LLLLLLRRRRRR| |
|
718 |
1/3 |BBBBBBBBBBBB| |
|
719 |
+------------+ */ |
|
720 |
||
721 |
if (y < h/3) |
|
722 |
return QInternal::TopDock; |
|
723 |
if (y > 2*h/3) |
|
724 |
return QInternal::BottomDock; |
|
725 |
if (x < w/2) |
|
726 |
return QInternal::LeftDock; |
|
727 |
return QInternal::RightDock; |
|
728 |
} |
|
729 |
} else { |
|
730 |
if (o == Qt::Horizontal) { |
|
731 |
return x < w/2 |
|
732 |
? QInternal::LeftDock |
|
733 |
: QInternal::RightDock; |
|
734 |
} else { |
|
735 |
return y < h/2 |
|
736 |
? QInternal::TopDock |
|
737 |
: QInternal::BottomDock; |
|
738 |
} |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
QList<int> QDockAreaLayoutInfo::gapIndex(const QPoint& _pos, |
|
743 |
bool nestingEnabled, TabMode tabMode) const |
|
744 |
{ |
|
745 |
QList<int> result; |
|
746 |
QRect item_rect; |
|
747 |
int item_index = 0; |
|
748 |
||
749 |
#ifndef QT_NO_TABBAR |
|
750 |
if (tabbed) { |
|
751 |
item_rect = tabContentRect(); |
|
752 |
} else |
|
753 |
#endif |
|
754 |
{ |
|
755 |
int pos = pick(o, _pos); |
|
756 |
||
757 |
int last = -1; |
|
758 |
for (int i = 0; i < item_list.size(); ++i) { |
|
759 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
760 |
if (item.skip()) |
|
761 |
continue; |
|
762 |
||
763 |
last = i; |
|
764 |
||
765 |
if (item.pos + item.size < pos) |
|
766 |
continue; |
|
767 |
||
768 |
if (item.subinfo != 0 |
|
769 |
#ifndef QT_NO_TABBAR |
|
770 |
&& !item.subinfo->tabbed |
|
771 |
#endif |
|
772 |
) { |
|
773 |
result = item.subinfo->gapIndex(_pos, nestingEnabled, |
|
774 |
tabMode); |
|
775 |
result.prepend(i); |
|
776 |
return result; |
|
777 |
} |
|
778 |
||
779 |
item_rect = itemRect(i); |
|
780 |
item_index = i; |
|
781 |
break; |
|
782 |
} |
|
783 |
||
784 |
if (item_rect.isNull()) { |
|
785 |
result.append(last + 1); |
|
786 |
return result; |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
Q_ASSERT(!item_rect.isNull()); |
|
791 |
||
792 |
QInternal::DockPosition dock_pos |
|
793 |
= dockPosHelper(item_rect, _pos, o, nestingEnabled, tabMode); |
|
794 |
||
795 |
switch (dock_pos) { |
|
796 |
case QInternal::LeftDock: |
|
797 |
if (o == Qt::Horizontal) |
|
798 |
result << item_index; |
|
799 |
else |
|
800 |
result << item_index << 0; // this subinfo doesn't exist yet, but insertGap() |
|
801 |
// handles this by inserting it |
|
802 |
break; |
|
803 |
case QInternal::RightDock: |
|
804 |
if (o == Qt::Horizontal) |
|
805 |
result << item_index + 1; |
|
806 |
else |
|
807 |
result << item_index << 1; |
|
808 |
break; |
|
809 |
case QInternal::TopDock: |
|
810 |
if (o == Qt::Horizontal) |
|
811 |
result << item_index << 0; |
|
812 |
else |
|
813 |
result << item_index; |
|
814 |
break; |
|
815 |
case QInternal::BottomDock: |
|
816 |
if (o == Qt::Horizontal) |
|
817 |
result << item_index << 1; |
|
818 |
else |
|
819 |
result << item_index + 1; |
|
820 |
break; |
|
821 |
case QInternal::DockCount: |
|
822 |
result << (-item_index - 1) << 0; // negative item_index means "on top of" |
|
823 |
// -item_index - 1, insertGap() |
|
824 |
// will insert a tabbed subinfo |
|
825 |
break; |
|
826 |
default: |
|
827 |
break; |
|
828 |
} |
|
829 |
||
830 |
return result; |
|
831 |
} |
|
832 |
||
833 |
static inline int shrink(QLayoutStruct &ls, int delta) |
|
834 |
{ |
|
835 |
if (ls.empty) |
|
836 |
return 0; |
|
837 |
int old_size = ls.size; |
|
838 |
ls.size = qMax(ls.size - delta, ls.minimumSize); |
|
839 |
return old_size - ls.size; |
|
840 |
} |
|
841 |
||
842 |
static inline int grow(QLayoutStruct &ls, int delta) |
|
843 |
{ |
|
844 |
if (ls.empty) |
|
845 |
return 0; |
|
846 |
int old_size = ls.size; |
|
847 |
ls.size = qMin(ls.size + delta, ls.maximumSize); |
|
848 |
return ls.size - old_size; |
|
849 |
} |
|
850 |
||
851 |
static int separatorMoveHelper(QVector<QLayoutStruct> &list, int index, int delta, int sep) |
|
852 |
{ |
|
853 |
// adjust sizes |
|
854 |
int pos = -1; |
|
855 |
for (int i = 0; i < list.size(); ++i) { |
|
856 |
const QLayoutStruct &ls = list.at(i); |
|
857 |
if (!ls.empty) { |
|
858 |
pos = ls.pos; |
|
859 |
break; |
|
860 |
} |
|
861 |
} |
|
862 |
if (pos == -1) |
|
863 |
return 0; |
|
864 |
||
865 |
if (delta > 0) { |
|
866 |
int growlimit = 0; |
|
867 |
for (int i = 0; i<=index; ++i) { |
|
868 |
const QLayoutStruct &ls = list.at(i); |
|
869 |
if (ls.empty) |
|
870 |
continue; |
|
871 |
if (ls.maximumSize == QLAYOUTSIZE_MAX) { |
|
872 |
growlimit = QLAYOUTSIZE_MAX; |
|
873 |
break; |
|
874 |
} |
|
875 |
growlimit += ls.maximumSize - ls.size; |
|
876 |
} |
|
877 |
if (delta > growlimit) |
|
878 |
delta = growlimit; |
|
879 |
||
880 |
int d = 0; |
|
881 |
for (int i = index + 1; d < delta && i < list.count(); ++i) |
|
882 |
d += shrink(list[i], delta - d); |
|
883 |
delta = d; |
|
884 |
d = 0; |
|
885 |
for (int i = index; d < delta && i >= 0; --i) |
|
886 |
d += grow(list[i], delta - d); |
|
887 |
} else if (delta < 0) { |
|
888 |
int growlimit = 0; |
|
889 |
for (int i = index + 1; i < list.count(); ++i) { |
|
890 |
const QLayoutStruct &ls = list.at(i); |
|
891 |
if (ls.empty) |
|
892 |
continue; |
|
893 |
if (ls.maximumSize == QLAYOUTSIZE_MAX) { |
|
894 |
growlimit = QLAYOUTSIZE_MAX; |
|
895 |
break; |
|
896 |
} |
|
897 |
growlimit += ls.maximumSize - ls.size; |
|
898 |
} |
|
899 |
if (-delta > growlimit) |
|
900 |
delta = -growlimit; |
|
901 |
||
902 |
int d = 0; |
|
903 |
for (int i = index; d < -delta && i >= 0; --i) |
|
904 |
d += shrink(list[i], -delta - d); |
|
905 |
delta = -d; |
|
906 |
d = 0; |
|
907 |
for (int i = index + 1; d < -delta && i < list.count(); ++i) |
|
908 |
d += grow(list[i], -delta - d); |
|
909 |
} |
|
910 |
||
911 |
// adjust positions |
|
912 |
bool first = true; |
|
913 |
for (int i = 0; i < list.size(); ++i) { |
|
914 |
QLayoutStruct &ls = list[i]; |
|
915 |
if (ls.empty) { |
|
916 |
ls.pos = pos + (first ? 0 : sep); |
|
917 |
continue; |
|
918 |
} |
|
919 |
if (!first) |
|
920 |
pos += sep; |
|
921 |
ls.pos = pos; |
|
922 |
pos += ls.size; |
|
923 |
first = false; |
|
924 |
} |
|
925 |
||
926 |
return delta; |
|
927 |
} |
|
928 |
||
929 |
int QDockAreaLayoutInfo::separatorMove(int index, int delta) |
|
930 |
{ |
|
931 |
#ifndef QT_NO_TABBAR |
|
932 |
Q_ASSERT(!tabbed); |
|
933 |
#endif |
|
934 |
||
935 |
QVector<QLayoutStruct> list(item_list.size()); |
|
936 |
for (int i = 0; i < list.size(); ++i) { |
|
937 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
938 |
QLayoutStruct &ls = list[i]; |
|
939 |
Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); |
|
940 |
if (item.skip()) { |
|
941 |
ls.empty = true; |
|
942 |
} else { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
943 |
const int separatorSpace = item.hasFixedSize(o) ? 0 : *sep; |
0 | 944 |
ls.empty = false; |
945 |
ls.pos = item.pos; |
|
946 |
ls.size = item.size + separatorSpace; |
|
947 |
ls.minimumSize = pick(o, item.minimumSize()) + separatorSpace; |
|
948 |
ls.maximumSize = pick(o, item.maximumSize()) + separatorSpace; |
|
949 |
||
950 |
} |
|
951 |
} |
|
952 |
||
953 |
//the separator space has been added to the size, so we pass 0 as a parameter |
|
954 |
delta = separatorMoveHelper(list, index, delta, 0 /*separator*/); |
|
955 |
||
956 |
for (int i = 0; i < list.size(); ++i) { |
|
957 |
QDockAreaLayoutItem &item = item_list[i]; |
|
958 |
if (item.skip()) |
|
959 |
continue; |
|
960 |
QLayoutStruct &ls = list[i]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
961 |
const int separatorSpace = item.hasFixedSize(o) ? 0 : *sep; |
0 | 962 |
item.size = ls.size - separatorSpace; |
963 |
item.pos = ls.pos; |
|
964 |
if (item.subinfo != 0) { |
|
965 |
item.subinfo->rect = itemRect(i); |
|
966 |
item.subinfo->fitItems(); |
|
967 |
} |
|
968 |
} |
|
969 |
||
970 |
return delta; |
|
971 |
} |
|
972 |
||
973 |
void QDockAreaLayoutInfo::unnest(int index) |
|
974 |
{ |
|
975 |
QDockAreaLayoutItem &item = item_list[index]; |
|
976 |
if (item.subinfo == 0) |
|
977 |
return; |
|
978 |
if (item.subinfo->item_list.count() > 1) |
|
979 |
return; |
|
980 |
||
981 |
if (item.subinfo->item_list.count() == 0) { |
|
982 |
item_list.removeAt(index); |
|
983 |
} else if (item.subinfo->item_list.count() == 1) { |
|
984 |
QDockAreaLayoutItem &child = item.subinfo->item_list.first(); |
|
985 |
if (child.widgetItem != 0) { |
|
986 |
item.widgetItem = child.widgetItem; |
|
987 |
delete item.subinfo; |
|
988 |
item.subinfo = 0; |
|
989 |
} else if (child.subinfo != 0) { |
|
990 |
QDockAreaLayoutInfo *tmp = item.subinfo; |
|
991 |
item.subinfo = child.subinfo; |
|
992 |
child.subinfo = 0; |
|
993 |
tmp->item_list.clear(); |
|
994 |
delete tmp; |
|
995 |
} |
|
996 |
} |
|
997 |
} |
|
998 |
||
999 |
void QDockAreaLayoutInfo::remove(const QList<int> &path) |
|
1000 |
{ |
|
1001 |
Q_ASSERT(!path.isEmpty()); |
|
1002 |
||
1003 |
if (path.count() > 1) { |
|
1004 |
const int index = path.first(); |
|
1005 |
QDockAreaLayoutItem &item = item_list[index]; |
|
1006 |
Q_ASSERT(item.subinfo != 0); |
|
1007 |
item.subinfo->remove(path.mid(1)); |
|
1008 |
unnest(index); |
|
1009 |
} else { |
|
1010 |
int index = path.first(); |
|
1011 |
item_list.removeAt(index); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) |
|
1016 |
{ |
|
1017 |
Q_ASSERT(!path.isEmpty()); |
|
1018 |
||
1019 |
int index = path.first(); |
|
1020 |
if (index < 0) |
|
1021 |
index = -index - 1; |
|
1022 |
||
1023 |
if (path.count() > 1) { |
|
1024 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1025 |
Q_ASSERT(item.subinfo != 0); |
|
1026 |
return item.subinfo->plug(path.mid(1)); |
|
1027 |
} |
|
1028 |
||
1029 |
QDockAreaLayoutItem &item = item_list[index]; |
|
1030 |
||
1031 |
Q_ASSERT(item.widgetItem != 0); |
|
1032 |
Q_ASSERT(item.flags & QDockAreaLayoutItem::GapItem); |
|
1033 |
item.flags &= ~QDockAreaLayoutItem::GapItem; |
|
1034 |
||
1035 |
QRect result; |
|
1036 |
||
1037 |
#ifndef QT_NO_TABBAR |
|
1038 |
if (tabbed) { |
|
1039 |
} else |
|
1040 |
#endif |
|
1041 |
{ |
|
1042 |
int prev = this->prev(index); |
|
1043 |
int next = this->next(index); |
|
1044 |
||
1045 |
if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1046 |
item.pos += *sep; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1047 |
item.size -= *sep; |
0 | 1048 |
} |
1049 |
if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1050 |
item.size -= *sep; |
0 | 1051 |
|
1052 |
QPoint pos; |
|
1053 |
rpick(o, pos) = item.pos; |
|
1054 |
rperp(o, pos) = perp(o, rect.topLeft()); |
|
1055 |
QSize s; |
|
1056 |
rpick(o, s) = item.size; |
|
1057 |
rperp(o, s) = perp(o, rect.size()); |
|
1058 |
result = QRect(pos, s); |
|
1059 |
} |
|
1060 |
||
1061 |
return item.widgetItem; |
|
1062 |
} |
|
1063 |
||
1064 |
QLayoutItem *QDockAreaLayoutInfo::unplug(const QList<int> &path) |
|
1065 |
{ |
|
1066 |
Q_ASSERT(!path.isEmpty()); |
|
1067 |
||
1068 |
const int index = path.first(); |
|
1069 |
if (path.count() > 1) { |
|
1070 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1071 |
Q_ASSERT(item.subinfo != 0); |
|
1072 |
return item.subinfo->unplug(path.mid(1)); |
|
1073 |
} |
|
1074 |
||
1075 |
QDockAreaLayoutItem &item = item_list[index]; |
|
1076 |
int prev = this->prev(index); |
|
1077 |
int next = this->next(index); |
|
1078 |
||
1079 |
Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); |
|
1080 |
item.flags |= QDockAreaLayoutItem::GapItem; |
|
1081 |
||
1082 |
#ifndef QT_NO_TABBAR |
|
1083 |
if (tabbed) { |
|
1084 |
} else |
|
1085 |
#endif |
|
1086 |
{ |
|
1087 |
if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1088 |
item.pos -= *sep; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1089 |
item.size += *sep; |
0 | 1090 |
} |
1091 |
if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1092 |
item.size += *sep; |
0 | 1093 |
} |
1094 |
||
1095 |
return item.widgetItem; |
|
1096 |
} |
|
1097 |
||
1098 |
#ifndef QT_NO_TABBAR |
|
1099 |
||
1100 |
quintptr QDockAreaLayoutInfo::currentTabId() const |
|
1101 |
{ |
|
1102 |
if (!tabbed || tabBar == 0) |
|
1103 |
return 0; |
|
1104 |
||
1105 |
int index = tabBar->currentIndex(); |
|
1106 |
if (index == -1) |
|
1107 |
return 0; |
|
1108 |
||
1109 |
return qvariant_cast<quintptr>(tabBar->tabData(index)); |
|
1110 |
} |
|
1111 |
||
1112 |
void QDockAreaLayoutInfo::setCurrentTab(QWidget *widget) |
|
1113 |
{ |
|
1114 |
setCurrentTabId(reinterpret_cast<quintptr>(widget)); |
|
1115 |
} |
|
1116 |
||
1117 |
void QDockAreaLayoutInfo::setCurrentTabId(quintptr id) |
|
1118 |
{ |
|
1119 |
if (!tabbed || tabBar == 0) |
|
1120 |
return; |
|
1121 |
||
1122 |
for (int i = 0; i < tabBar->count(); ++i) { |
|
1123 |
if (qvariant_cast<quintptr>(tabBar->tabData(i)) == id) { |
|
1124 |
tabBar->setCurrentIndex(i); |
|
1125 |
return; |
|
1126 |
} |
|
1127 |
} |
|
1128 |
} |
|
1129 |
||
1130 |
#endif // QT_NO_TABBAR |
|
1131 |
||
1132 |
static QRect dockedGeometry(QWidget *widget) |
|
1133 |
{ |
|
1134 |
int titleHeight = 0; |
|
1135 |
||
1136 |
QDockWidgetLayout *layout |
|
1137 |
= qobject_cast<QDockWidgetLayout*>(widget->layout()); |
|
1138 |
if(layout != 0 && layout->nativeWindowDeco()) |
|
1139 |
titleHeight = layout->titleHeight(); |
|
1140 |
||
1141 |
QRect result = widget->geometry(); |
|
1142 |
result.adjust(0, -titleHeight, 0, 0); |
|
1143 |
return result; |
|
1144 |
} |
|
1145 |
||
1146 |
bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem) |
|
1147 |
{ |
|
1148 |
Q_ASSERT(!path.isEmpty()); |
|
1149 |
||
1150 |
bool insert_tabbed = false; |
|
1151 |
int index = path.first(); |
|
1152 |
if (index < 0) { |
|
1153 |
insert_tabbed = true; |
|
1154 |
index = -index - 1; |
|
1155 |
} |
|
1156 |
||
1157 |
// dump(qDebug() << "insertGap() before:" << index << tabIndex, *this, QString()); |
|
1158 |
||
1159 |
if (path.count() > 1) { |
|
1160 |
QDockAreaLayoutItem &item = item_list[index]; |
|
1161 |
||
1162 |
if (item.subinfo == 0 |
|
1163 |
#ifndef QT_NO_TABBAR |
|
1164 |
|| (item.subinfo->tabbed && !insert_tabbed) |
|
1165 |
#endif |
|
1166 |
) { |
|
1167 |
||
1168 |
// this is not yet a nested layout - make it |
|
1169 |
||
1170 |
QDockAreaLayoutInfo *subinfo = item.subinfo; |
|
1171 |
QLayoutItem *widgetItem = item.widgetItem; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
QPlaceHolderItem *placeHolderItem = item.placeHolderItem; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1173 |
QRect r = subinfo == 0 ? widgetItem ? dockedGeometry(widgetItem->widget()) : placeHolderItem->topLevelRect : subinfo->rect; |
0 | 1174 |
|
1175 |
Qt::Orientation opposite = o == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal; |
|
1176 |
#ifdef QT_NO_TABBAR |
|
1177 |
const int tabBarShape = 0; |
|
1178 |
#endif |
|
1179 |
QDockAreaLayoutInfo *new_info |
|
1180 |
= new QDockAreaLayoutInfo(sep, dockPos, opposite, tabBarShape, mainWindow); |
|
1181 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
//item become a new top-level |
0 | 1183 |
item.subinfo = new_info; |
1184 |
item.widgetItem = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
item.placeHolderItem = 0; |
0 | 1186 |
|
1187 |
QDockAreaLayoutItem new_item |
|
1188 |
= widgetItem == 0 |
|
1189 |
? QDockAreaLayoutItem(subinfo) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
: widgetItem ? QDockAreaLayoutItem(widgetItem) : QDockAreaLayoutItem(placeHolderItem); |
0 | 1191 |
new_item.size = pick(opposite, r.size()); |
1192 |
new_item.pos = pick(opposite, r.topLeft()); |
|
1193 |
new_info->item_list.append(new_item); |
|
1194 |
#ifndef QT_NO_TABBAR |
|
1195 |
if (insert_tabbed) { |
|
1196 |
new_info->tabbed = true; |
|
1197 |
} |
|
1198 |
#endif |
|
1199 |
} |
|
1200 |
||
1201 |
return item.subinfo->insertGap(path.mid(1), dockWidgetItem); |
|
1202 |
} |
|
1203 |
||
1204 |
// create the gap item |
|
1205 |
QDockAreaLayoutItem gap_item; |
|
1206 |
gap_item.flags |= QDockAreaLayoutItem::GapItem; |
|
1207 |
gap_item.widgetItem = dockWidgetItem; // so minimumSize(), maximumSize() and |
|
1208 |
// sizeHint() will work |
|
1209 |
#ifndef QT_NO_TABBAR |
|
1210 |
if (!tabbed) |
|
1211 |
#endif |
|
1212 |
{ |
|
1213 |
int prev = this->prev(index); |
|
1214 |
int next = this->next(index - 1); |
|
1215 |
// find out how much space we have in the layout |
|
1216 |
int space = 0; |
|
1217 |
if (isEmpty()) { |
|
1218 |
// I am an empty dock area, therefore I am a top-level dock area. |
|
1219 |
switch (dockPos) { |
|
1220 |
case QInternal::LeftDock: |
|
1221 |
case QInternal::RightDock: |
|
1222 |
if (o == Qt::Vertical) { |
|
1223 |
// the "size" is the height of the dock area (remember we are empty) |
|
1224 |
space = pick(Qt::Vertical, rect.size()); |
|
1225 |
} else { |
|
1226 |
space = pick(Qt::Horizontal, dockWidgetItem->widget()->size()); |
|
1227 |
} |
|
1228 |
break; |
|
1229 |
case QInternal::TopDock: |
|
1230 |
case QInternal::BottomDock: |
|
1231 |
default: |
|
1232 |
if (o == Qt::Horizontal) { |
|
1233 |
// the "size" is width of the dock area |
|
1234 |
space = pick(Qt::Horizontal, rect.size()); |
|
1235 |
} else { |
|
1236 |
space = pick(Qt::Vertical, dockWidgetItem->widget()->size()); |
|
1237 |
} |
|
1238 |
break; |
|
1239 |
} |
|
1240 |
} else { |
|
1241 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1242 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1243 |
if (item.skip()) |
|
1244 |
continue; |
|
1245 |
Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); |
|
1246 |
space += item.size - pick(o, item.minimumSize()); |
|
1247 |
} |
|
1248 |
} |
|
1249 |
||
1250 |
// find the actual size of the gap |
|
1251 |
int gap_size = 0; |
|
1252 |
int sep_size = 0; |
|
1253 |
if (isEmpty()) { |
|
1254 |
gap_size = space; |
|
1255 |
sep_size = 0; |
|
1256 |
} else { |
|
1257 |
QRect r = dockedGeometry(dockWidgetItem->widget()); |
|
1258 |
gap_size = pick(o, r.size()); |
|
1259 |
if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1260 |
sep_size += *sep; |
0 | 1261 |
if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1262 |
sep_size += *sep; |
0 | 1263 |
} |
1264 |
if (gap_size + sep_size > space) |
|
1265 |
gap_size = pick(o, gap_item.minimumSize()); |
|
1266 |
gap_item.size = gap_size + sep_size; |
|
1267 |
} |
|
1268 |
||
1269 |
// finally, insert the gap |
|
1270 |
item_list.insert(index, gap_item); |
|
1271 |
||
1272 |
// dump(qDebug() << "insertGap() after:" << index << tabIndex, *this, QString()); |
|
1273 |
||
1274 |
return true; |
|
1275 |
} |
|
1276 |
||
1277 |
QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(QWidget *widget) |
|
1278 |
{ |
|
1279 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1280 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1281 |
if (item.skip()) |
|
1282 |
continue; |
|
1283 |
||
1284 |
#ifndef QT_NO_TABBAR |
|
1285 |
if (tabbed && widget == tabBar) |
|
1286 |
return this; |
|
1287 |
#endif |
|
1288 |
||
1289 |
if (item.widgetItem != 0 && item.widgetItem->widget() == widget) |
|
1290 |
return this; |
|
1291 |
||
1292 |
if (item.subinfo != 0) { |
|
1293 |
if (QDockAreaLayoutInfo *result = item.subinfo->info(widget)) |
|
1294 |
return result; |
|
1295 |
} |
|
1296 |
} |
|
1297 |
||
1298 |
return 0; |
|
1299 |
} |
|
1300 |
||
1301 |
QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(const QList<int> &path) |
|
1302 |
{ |
|
1303 |
int index = path.first(); |
|
1304 |
if (index < 0) |
|
1305 |
index = -index - 1; |
|
1306 |
if (index >= item_list.count()) |
|
1307 |
return this; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
if (path.count() == 1 || item_list[index].subinfo == 0) |
0 | 1309 |
return this; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
return item_list[index].subinfo->info(path.mid(1)); |
0 | 1311 |
} |
1312 |
||
1313 |
QRect QDockAreaLayoutInfo::itemRect(int index) const |
|
1314 |
{ |
|
1315 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1316 |
||
1317 |
if (item.skip()) |
|
1318 |
return QRect(); |
|
1319 |
||
1320 |
QRect result; |
|
1321 |
||
1322 |
#ifndef QT_NO_TABBAR |
|
1323 |
if (tabbed) { |
|
1324 |
if (tabId(item) == currentTabId()) |
|
1325 |
result = tabContentRect(); |
|
1326 |
} else |
|
1327 |
#endif |
|
1328 |
{ |
|
1329 |
QPoint pos; |
|
1330 |
rpick(o, pos) = item.pos; |
|
1331 |
rperp(o, pos) = perp(o, rect.topLeft()); |
|
1332 |
QSize s; |
|
1333 |
rpick(o, s) = item.size; |
|
1334 |
rperp(o, s) = perp(o, rect.size()); |
|
1335 |
result = QRect(pos, s); |
|
1336 |
} |
|
1337 |
||
1338 |
return result; |
|
1339 |
} |
|
1340 |
||
1341 |
QRect QDockAreaLayoutInfo::itemRect(const QList<int> &path) const |
|
1342 |
{ |
|
1343 |
Q_ASSERT(!path.isEmpty()); |
|
1344 |
||
1345 |
const int index = path.first(); |
|
1346 |
if (path.count() > 1) { |
|
1347 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1348 |
Q_ASSERT(item.subinfo != 0); |
|
1349 |
return item.subinfo->itemRect(path.mid(1)); |
|
1350 |
} |
|
1351 |
||
1352 |
return itemRect(index); |
|
1353 |
} |
|
1354 |
||
1355 |
QRect QDockAreaLayoutInfo::separatorRect(int index) const |
|
1356 |
{ |
|
1357 |
#ifndef QT_NO_TABBAR |
|
1358 |
if (tabbed) |
|
1359 |
return QRect(); |
|
1360 |
#endif |
|
1361 |
||
1362 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1363 |
if (item.skip()) |
|
1364 |
return QRect(); |
|
1365 |
||
1366 |
QPoint pos = rect.topLeft(); |
|
1367 |
rpick(o, pos) = item.pos + item.size; |
|
1368 |
QSize s = rect.size(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1369 |
rpick(o, s) = *sep; |
0 | 1370 |
|
1371 |
return QRect(pos, s); |
|
1372 |
} |
|
1373 |
||
1374 |
QRect QDockAreaLayoutInfo::separatorRect(const QList<int> &path) const |
|
1375 |
{ |
|
1376 |
Q_ASSERT(!path.isEmpty()); |
|
1377 |
||
1378 |
const int index = path.first(); |
|
1379 |
if (path.count() > 1) { |
|
1380 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
1381 |
Q_ASSERT(item.subinfo != 0); |
|
1382 |
return item.subinfo->separatorRect(path.mid(1)); |
|
1383 |
} |
|
1384 |
return separatorRect(index); |
|
1385 |
} |
|
1386 |
||
1387 |
QList<int> QDockAreaLayoutInfo::findSeparator(const QPoint &_pos) const |
|
1388 |
{ |
|
1389 |
#ifndef QT_NO_TABBAR |
|
1390 |
if (tabbed) |
|
1391 |
return QList<int>(); |
|
1392 |
#endif |
|
1393 |
||
1394 |
int pos = pick(o, _pos); |
|
1395 |
||
1396 |
for (int i = 0; i < item_list.size(); ++i) { |
|
1397 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1398 |
if (item.skip() || (item.flags & QDockAreaLayoutItem::GapItem)) |
|
1399 |
continue; |
|
1400 |
||
1401 |
if (item.pos + item.size > pos) { |
|
1402 |
if (item.subinfo != 0) { |
|
1403 |
QList<int> result = item.subinfo->findSeparator(_pos); |
|
1404 |
if (!result.isEmpty()) { |
|
1405 |
result.prepend(i); |
|
1406 |
return result; |
|
1407 |
} else { |
|
1408 |
return QList<int>(); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
} |
|
1412 |
||
1413 |
int next = this->next(i); |
|
1414 |
if (next == -1 || (item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) |
|
1415 |
continue; |
|
1416 |
||
1417 |
QRect sepRect = separatorRect(i); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1418 |
if (!sepRect.isNull() && *sep == 1) |
0 | 1419 |
sepRect.adjust(-2, -2, 2, 2); |
1420 |
//we also make sure we don't find a separator that's not there |
|
1421 |
if (sepRect.contains(_pos) && !item.hasFixedSize(o)) { |
|
1422 |
return QList<int>() << i; |
|
1423 |
} |
|
1424 |
||
1425 |
} |
|
1426 |
||
1427 |
return QList<int>(); |
|
1428 |
} |
|
1429 |
||
1430 |
QList<int> QDockAreaLayoutInfo::indexOfPlaceHolder(const QString &objectName) const |
|
1431 |
{ |
|
1432 |
for (int i = 0; i < item_list.size(); ++i) { |
|
1433 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1434 |
||
1435 |
if (item.subinfo != 0) { |
|
1436 |
QList<int> result = item.subinfo->indexOfPlaceHolder(objectName); |
|
1437 |
if (!result.isEmpty()) { |
|
1438 |
result.prepend(i); |
|
1439 |
return result; |
|
1440 |
} |
|
1441 |
continue; |
|
1442 |
} |
|
1443 |
||
1444 |
if (item.placeHolderItem != 0 && item.placeHolderItem->objectName == objectName) { |
|
1445 |
QList<int> result; |
|
1446 |
result << i; |
|
1447 |
return result; |
|
1448 |
} |
|
1449 |
} |
|
1450 |
||
1451 |
return QList<int>(); |
|
1452 |
} |
|
1453 |
||
1454 |
QList<int> QDockAreaLayoutInfo::indexOf(QWidget *widget) const |
|
1455 |
{ |
|
1456 |
for (int i = 0; i < item_list.size(); ++i) { |
|
1457 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1458 |
||
1459 |
if (item.placeHolderItem != 0) |
|
1460 |
continue; |
|
1461 |
||
1462 |
if (item.subinfo != 0) { |
|
1463 |
QList<int> result = item.subinfo->indexOf(widget); |
|
1464 |
if (!result.isEmpty()) { |
|
1465 |
result.prepend(i); |
|
1466 |
return result; |
|
1467 |
} |
|
1468 |
continue; |
|
1469 |
} |
|
1470 |
||
1471 |
if (!(item.flags & QDockAreaLayoutItem::GapItem) && item.widgetItem->widget() == widget) { |
|
1472 |
QList<int> result; |
|
1473 |
result << i; |
|
1474 |
return result; |
|
1475 |
} |
|
1476 |
} |
|
1477 |
||
1478 |
return QList<int>(); |
|
1479 |
} |
|
1480 |
||
1481 |
QMainWindowLayout *QDockAreaLayoutInfo::mainWindowLayout() const |
|
1482 |
{ |
|
1483 |
QMainWindowLayout *result = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); |
|
1484 |
Q_ASSERT(result != 0); |
|
1485 |
return result; |
|
1486 |
} |
|
1487 |
||
1488 |
bool QDockAreaLayoutInfo::hasFixedSize() const |
|
1489 |
{ |
|
1490 |
return perp(o, minimumSize()) == perp(o, maximumSize()); |
|
1491 |
} |
|
1492 |
||
1493 |
||
1494 |
void QDockAreaLayoutInfo::apply(bool animate) |
|
1495 |
{ |
|
1496 |
QWidgetAnimator &widgetAnimator = mainWindowLayout()->widgetAnimator; |
|
1497 |
||
1498 |
#ifndef QT_NO_TABBAR |
|
1499 |
if (tabbed) { |
|
1500 |
QRect tab_rect; |
|
1501 |
QSize tbh = tabBarSizeHint(); |
|
1502 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1503 |
if (!tbh.isNull()) { |
0 | 1504 |
switch (tabBarShape) { |
1505 |
case QTabBar::RoundedNorth: |
|
1506 |
case QTabBar::TriangularNorth: |
|
1507 |
tab_rect = QRect(rect.left(), rect.top(), rect.width(), tbh.height()); |
|
1508 |
break; |
|
1509 |
case QTabBar::RoundedSouth: |
|
1510 |
case QTabBar::TriangularSouth: |
|
1511 |
tab_rect = QRect(rect.left(), rect.bottom() - tbh.height() + 1, |
|
1512 |
rect.width(), tbh.height()); |
|
1513 |
break; |
|
1514 |
case QTabBar::RoundedEast: |
|
1515 |
case QTabBar::TriangularEast: |
|
1516 |
tab_rect = QRect(rect.right() - tbh.width() + 1, rect.top(), |
|
1517 |
tbh.width(), rect.height()); |
|
1518 |
break; |
|
1519 |
case QTabBar::RoundedWest: |
|
1520 |
case QTabBar::TriangularWest: |
|
1521 |
tab_rect = QRect(rect.left(), rect.top(), |
|
1522 |
tbh.width(), rect.height()); |
|
1523 |
break; |
|
1524 |
default: |
|
1525 |
break; |
|
1526 |
} |
|
1527 |
} |
|
1528 |
||
1529 |
widgetAnimator.animate(tabBar, tab_rect, animate); |
|
1530 |
} |
|
1531 |
#endif // QT_NO_TABBAR |
|
1532 |
||
1533 |
for (int i = 0; i < item_list.size(); ++i) { |
|
1534 |
QDockAreaLayoutItem &item = item_list[i]; |
|
1535 |
||
1536 |
if (item.flags & QDockAreaLayoutItem::GapItem) |
|
1537 |
continue; |
|
1538 |
||
1539 |
if (item.subinfo != 0) { |
|
1540 |
item.subinfo->apply(animate); |
|
1541 |
continue; |
|
1542 |
} |
|
1543 |
||
1544 |
if (item.skip()) |
|
1545 |
continue; |
|
1546 |
||
1547 |
Q_ASSERT(item.widgetItem); |
|
1548 |
QRect r = itemRect(i); |
|
1549 |
QWidget *w = item.widgetItem->widget(); |
|
1550 |
||
1551 |
QRect geo = w->geometry(); |
|
1552 |
widgetAnimator.animate(w, r, animate); |
|
1553 |
if (!w->isHidden() && w->window()->isVisible()) { |
|
1554 |
QDockWidget *dw = qobject_cast<QDockWidget*>(w); |
|
1555 |
if (!r.isValid() && geo.right() >= 0 && geo.bottom() >= 0) { |
|
1556 |
dw->lower(); |
|
1557 |
emit dw->visibilityChanged(false); |
|
1558 |
} else if (r.isValid() |
|
1559 |
&& (geo.right() < 0 || geo.bottom() < 0)) { |
|
1560 |
emit dw->visibilityChanged(true); |
|
1561 |
} |
|
1562 |
} |
|
1563 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1564 |
#ifndef QT_NO_TABBAR |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1565 |
if (*sep == 1) |
0 | 1566 |
updateSeparatorWidgets(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1567 |
#endif //QT_NO_TABBAR |
0 | 1568 |
} |
1569 |
||
1570 |
static void paintSep(QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over) |
|
1571 |
{ |
|
1572 |
QStyleOption opt(0); |
|
1573 |
opt.state = QStyle::State_None; |
|
1574 |
if (w->isEnabled()) |
|
1575 |
opt.state |= QStyle::State_Enabled; |
|
1576 |
if (o != Qt::Horizontal) |
|
1577 |
opt.state |= QStyle::State_Horizontal; |
|
1578 |
if (mouse_over) |
|
1579 |
opt.state |= QStyle::State_MouseOver; |
|
1580 |
opt.rect = r; |
|
1581 |
opt.palette = w->palette(); |
|
1582 |
||
1583 |
w->style()->drawPrimitive(QStyle::PE_IndicatorDockWidgetResizeHandle, &opt, p, w); |
|
1584 |
} |
|
1585 |
||
1586 |
QRegion QDockAreaLayoutInfo::separatorRegion() const |
|
1587 |
{ |
|
1588 |
QRegion result; |
|
1589 |
||
1590 |
if (isEmpty()) |
|
1591 |
return result; |
|
1592 |
#ifndef QT_NO_TABBAR |
|
1593 |
if (tabbed) |
|
1594 |
return result; |
|
1595 |
#endif |
|
1596 |
||
1597 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1598 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1599 |
||
1600 |
if (item.skip()) |
|
1601 |
continue; |
|
1602 |
||
1603 |
int next = this->next(i); |
|
1604 |
||
1605 |
if (item.subinfo) |
|
1606 |
result |= item.subinfo->separatorRegion(); |
|
1607 |
||
1608 |
if (next == -1) |
|
1609 |
break; |
|
1610 |
result |= separatorRect(i); |
|
1611 |
} |
|
1612 |
||
1613 |
return result; |
|
1614 |
} |
|
1615 |
||
1616 |
void QDockAreaLayoutInfo::paintSeparators(QPainter *p, QWidget *widget, |
|
1617 |
const QRegion &clip, |
|
1618 |
const QPoint &mouse) const |
|
1619 |
{ |
|
1620 |
if (isEmpty()) |
|
1621 |
return; |
|
1622 |
#ifndef QT_NO_TABBAR |
|
1623 |
if (tabbed) |
|
1624 |
return; |
|
1625 |
#endif |
|
1626 |
||
1627 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1628 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1629 |
||
1630 |
if (item.skip()) |
|
1631 |
continue; |
|
1632 |
||
1633 |
int next = this->next(i); |
|
1634 |
if ((item.flags & QDockAreaLayoutItem::GapItem) |
|
1635 |
|| (next != -1 && (item_list.at(next).flags & QDockAreaLayoutItem::GapItem))) |
|
1636 |
continue; |
|
1637 |
||
1638 |
if (item.subinfo) { |
|
1639 |
if (clip.contains(item.subinfo->rect)) |
|
1640 |
item.subinfo->paintSeparators(p, widget, clip, mouse); |
|
1641 |
} |
|
1642 |
||
1643 |
if (next == -1) |
|
1644 |
break; |
|
1645 |
QRect r = separatorRect(i); |
|
1646 |
if (clip.contains(r) && !item.hasFixedSize(o)) |
|
1647 |
paintSep(p, widget, r, o, r.contains(mouse)); |
|
1648 |
} |
|
1649 |
} |
|
1650 |
||
1651 |
int QDockAreaLayoutInfo::next(int index) const |
|
1652 |
{ |
|
1653 |
for (int i = index + 1; i < item_list.size(); ++i) { |
|
1654 |
if (!item_list.at(i).skip()) |
|
1655 |
return i; |
|
1656 |
} |
|
1657 |
return -1; |
|
1658 |
} |
|
1659 |
||
1660 |
int QDockAreaLayoutInfo::prev(int index) const |
|
1661 |
{ |
|
1662 |
for (int i = index - 1; i >= 0; --i) { |
|
1663 |
if (!item_list.at(i).skip()) |
|
1664 |
return i; |
|
1665 |
} |
|
1666 |
return -1; |
|
1667 |
} |
|
1668 |
||
1669 |
void QDockAreaLayoutInfo::tab(int index, QLayoutItem *dockWidgetItem) |
|
1670 |
{ |
|
1671 |
#ifdef QT_NO_TABBAR |
|
1672 |
Q_UNUSED(index); |
|
1673 |
Q_UNUSED(dockWidgetItem); |
|
1674 |
#else |
|
1675 |
if (tabbed) { |
|
1676 |
item_list.append(QDockAreaLayoutItem(dockWidgetItem)); |
|
1677 |
updateTabBar(); |
|
1678 |
setCurrentTab(dockWidgetItem->widget()); |
|
1679 |
} else { |
|
1680 |
QDockAreaLayoutInfo *new_info |
|
1681 |
= new QDockAreaLayoutInfo(sep, dockPos, o, tabBarShape, mainWindow); |
|
1682 |
item_list[index].subinfo = new_info; |
|
1683 |
new_info->item_list.append(item_list.at(index).widgetItem); |
|
1684 |
item_list[index].widgetItem = 0; |
|
1685 |
new_info->item_list.append(dockWidgetItem); |
|
1686 |
new_info->tabbed = true; |
|
1687 |
new_info->updateTabBar(); |
|
1688 |
new_info->setCurrentTab(dockWidgetItem->widget()); |
|
1689 |
} |
|
1690 |
#endif // QT_NO_TABBAR |
|
1691 |
} |
|
1692 |
||
1693 |
void QDockAreaLayoutInfo::split(int index, Qt::Orientation orientation, |
|
1694 |
QLayoutItem *dockWidgetItem) |
|
1695 |
{ |
|
1696 |
if (orientation == o) { |
|
1697 |
item_list.insert(index + 1, QDockAreaLayoutItem(dockWidgetItem)); |
|
1698 |
} else { |
|
1699 |
#ifdef QT_NO_TABBAR |
|
1700 |
const int tabBarShape = 0; |
|
1701 |
#endif |
|
1702 |
QDockAreaLayoutInfo *new_info |
|
1703 |
= new QDockAreaLayoutInfo(sep, dockPos, orientation, tabBarShape, mainWindow); |
|
1704 |
item_list[index].subinfo = new_info; |
|
1705 |
new_info->item_list.append(item_list.at(index).widgetItem); |
|
1706 |
item_list[index].widgetItem = 0; |
|
1707 |
new_info->item_list.append(dockWidgetItem); |
|
1708 |
} |
|
1709 |
} |
|
1710 |
||
1711 |
QDockAreaLayoutItem &QDockAreaLayoutInfo::item(const QList<int> &path) |
|
1712 |
{ |
|
1713 |
Q_ASSERT(!path.isEmpty()); |
|
1714 |
const int index = path.first(); |
|
1715 |
if (path.count() > 1) { |
|
1716 |
const QDockAreaLayoutItem &item = item_list[index]; |
|
1717 |
Q_ASSERT(item.subinfo != 0); |
|
1718 |
return item.subinfo->item(path.mid(1)); |
|
1719 |
} |
|
1720 |
return item_list[index]; |
|
1721 |
} |
|
1722 |
||
1723 |
QLayoutItem *QDockAreaLayoutInfo::itemAt(int *x, int index) const |
|
1724 |
{ |
|
1725 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1726 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1727 |
if (item.placeHolderItem != 0) |
|
1728 |
continue; |
|
1729 |
if (item.subinfo) { |
|
1730 |
if (QLayoutItem *ret = item.subinfo->itemAt(x, index)) |
|
1731 |
return ret; |
|
1732 |
} else if (item.widgetItem) { |
|
1733 |
if ((*x)++ == index) |
|
1734 |
return item.widgetItem; |
|
1735 |
} |
|
1736 |
} |
|
1737 |
return 0; |
|
1738 |
} |
|
1739 |
||
1740 |
QLayoutItem *QDockAreaLayoutInfo::takeAt(int *x, int index) |
|
1741 |
{ |
|
1742 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1743 |
QDockAreaLayoutItem &item = item_list[i]; |
|
1744 |
if (item.placeHolderItem != 0) |
|
1745 |
continue; |
|
1746 |
else if (item.subinfo) { |
|
1747 |
if (QLayoutItem *ret = item.subinfo->takeAt(x, index)) { |
|
1748 |
unnest(i); |
|
1749 |
return ret; |
|
1750 |
} |
|
1751 |
} else if (item.widgetItem) { |
|
1752 |
if ((*x)++ == index) { |
|
1753 |
item.placeHolderItem = new QPlaceHolderItem(item.widgetItem->widget()); |
|
1754 |
QLayoutItem *ret = item.widgetItem; |
|
1755 |
item.widgetItem = 0; |
|
1756 |
if (item.size != -1) |
|
1757 |
item.flags |= QDockAreaLayoutItem::KeepSize; |
|
1758 |
return ret; |
|
1759 |
} |
|
1760 |
} |
|
1761 |
} |
|
1762 |
return 0; |
|
1763 |
} |
|
1764 |
||
1765 |
void QDockAreaLayoutInfo::deleteAllLayoutItems() |
|
1766 |
{ |
|
1767 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1768 |
QDockAreaLayoutItem &item= item_list[i]; |
|
1769 |
if (item.subinfo) { |
|
1770 |
item.subinfo->deleteAllLayoutItems(); |
|
1771 |
} else { |
|
1772 |
delete item.widgetItem; |
|
1773 |
item.widgetItem = 0; |
|
1774 |
} |
|
1775 |
} |
|
1776 |
} |
|
1777 |
||
1778 |
void QDockAreaLayoutInfo::saveState(QDataStream &stream) const |
|
1779 |
{ |
|
1780 |
#ifndef QT_NO_TABBAR |
|
1781 |
if (tabbed) { |
|
1782 |
stream << (uchar) TabMarker; |
|
1783 |
||
1784 |
// write the index in item_list of the widget that's currently on top. |
|
1785 |
quintptr id = currentTabId(); |
|
1786 |
int index = -1; |
|
1787 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1788 |
if (tabId(item_list.at(i)) == id) { |
|
1789 |
index = i; |
|
1790 |
break; |
|
1791 |
} |
|
1792 |
} |
|
1793 |
stream << index; |
|
1794 |
} else |
|
1795 |
#endif // QT_NO_TABBAR |
|
1796 |
{ |
|
1797 |
stream << (uchar) SequenceMarker; |
|
1798 |
} |
|
1799 |
||
1800 |
stream << (uchar) o << item_list.count(); |
|
1801 |
||
1802 |
for (int i = 0; i < item_list.count(); ++i) { |
|
1803 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
1804 |
if (item.widgetItem != 0) { |
|
1805 |
stream << (uchar) WidgetMarker; |
|
1806 |
QWidget *w = item.widgetItem->widget(); |
|
1807 |
QString name = w->objectName(); |
|
1808 |
if (name.isEmpty()) { |
|
1809 |
qWarning("QMainWindow::saveState(): 'objectName' not set for QDockWidget %p '%s;", |
|
1810 |
w, qPrintable(w->windowTitle())); |
|
1811 |
} |
|
1812 |
stream << name; |
|
1813 |
||
1814 |
uchar flags = 0; |
|
1815 |
if (!w->isHidden()) |
|
1816 |
flags |= StateFlagVisible; |
|
1817 |
if (w->isWindow()) |
|
1818 |
flags |= StateFlagFloating; |
|
1819 |
stream << flags; |
|
1820 |
||
1821 |
if (w->isWindow()) { |
|
1822 |
stream << w->x() << w->y() << w->width() << w->height(); |
|
1823 |
} else { |
|
1824 |
stream << item.pos << item.size << pick(o, item.minimumSize()) |
|
1825 |
<< pick(o, item.maximumSize()); |
|
1826 |
} |
|
1827 |
} else if (item.placeHolderItem != 0) { |
|
1828 |
stream << (uchar) WidgetMarker; |
|
1829 |
stream << item.placeHolderItem->objectName; |
|
1830 |
uchar flags = 0; |
|
1831 |
if (!item.placeHolderItem->hidden) |
|
1832 |
flags |= StateFlagVisible; |
|
1833 |
if (item.placeHolderItem->window) |
|
1834 |
flags |= StateFlagFloating; |
|
1835 |
stream << flags; |
|
1836 |
if (item.placeHolderItem->window) { |
|
1837 |
QRect r = item.placeHolderItem->topLevelRect; |
|
1838 |
stream << r.x() << r.y() << r.width() << r.height(); |
|
1839 |
} else { |
|
1840 |
stream << item.pos << item.size << (int)0 << (int)0; |
|
1841 |
} |
|
1842 |
} else if (item.subinfo != 0) { |
|
1843 |
stream << (uchar) SequenceMarker << item.pos << item.size << pick(o, item.minimumSize()) << pick(o, item.maximumSize()); |
|
1844 |
item.subinfo->saveState(stream); |
|
1845 |
} |
|
1846 |
} |
|
1847 |
} |
|
1848 |
||
1849 |
static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) |
|
1850 |
{ |
|
1851 |
switch (pos) { |
|
1852 |
case QInternal::LeftDock: return Qt::LeftDockWidgetArea; |
|
1853 |
case QInternal::RightDock: return Qt::RightDockWidgetArea; |
|
1854 |
case QInternal::TopDock: return Qt::TopDockWidgetArea; |
|
1855 |
case QInternal::BottomDock: return Qt::BottomDockWidgetArea; |
|
1856 |
default: break; |
|
1857 |
} |
|
1858 |
return Qt::NoDockWidgetArea; |
|
1859 |
} |
|
1860 |
||
1861 |
static QRect constrainedRect(QRect rect, const QRect &desktop) |
|
1862 |
{ |
|
1863 |
if (desktop.isValid()) { |
|
1864 |
rect.setWidth(qMin(rect.width(), desktop.width())); |
|
1865 |
rect.setHeight(qMin(rect.height(), desktop.height())); |
|
1866 |
rect.moveLeft(qMax(rect.left(), desktop.left())); |
|
1867 |
rect.moveTop(qMax(rect.top(), desktop.top())); |
|
1868 |
rect.moveRight(qMin(rect.right(), desktop.right())); |
|
1869 |
rect.moveBottom(qMin(rect.bottom(), desktop.bottom())); |
|
1870 |
} |
|
1871 |
||
1872 |
return rect; |
|
1873 |
} |
|
1874 |
||
1875 |
bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> &widgets, bool testing) |
|
1876 |
{ |
|
1877 |
uchar marker; |
|
1878 |
stream >> marker; |
|
1879 |
if (marker != TabMarker && marker != SequenceMarker) |
|
1880 |
return false; |
|
1881 |
||
1882 |
#ifndef QT_NO_TABBAR |
|
1883 |
tabbed = marker == TabMarker; |
|
1884 |
||
1885 |
int index = -1; |
|
1886 |
if (tabbed) |
|
1887 |
stream >> index; |
|
1888 |
#endif |
|
1889 |
||
1890 |
uchar orientation; |
|
1891 |
stream >> orientation; |
|
1892 |
o = static_cast<Qt::Orientation>(orientation); |
|
1893 |
||
1894 |
int cnt; |
|
1895 |
stream >> cnt; |
|
1896 |
||
1897 |
for (int i = 0; i < cnt; ++i) { |
|
1898 |
uchar nextMarker; |
|
1899 |
stream >> nextMarker; |
|
1900 |
if (nextMarker == WidgetMarker) { |
|
1901 |
QString name; |
|
1902 |
uchar flags; |
|
1903 |
stream >> name >> flags; |
|
1904 |
if (name.isEmpty()) { |
|
1905 |
int dummy; |
|
1906 |
stream >> dummy >> dummy >> dummy >> dummy; |
|
1907 |
continue; |
|
1908 |
} |
|
1909 |
||
1910 |
QDockWidget *widget = 0; |
|
1911 |
for (int j = 0; j < widgets.count(); ++j) { |
|
1912 |
if (widgets.at(j)->objectName() == name) { |
|
1913 |
widget = widgets.takeAt(j); |
|
1914 |
break; |
|
1915 |
} |
|
1916 |
} |
|
1917 |
||
1918 |
if (widget == 0) { |
|
1919 |
QPlaceHolderItem *placeHolder = new QPlaceHolderItem; |
|
1920 |
QDockAreaLayoutItem item(placeHolder); |
|
1921 |
||
1922 |
placeHolder->objectName = name; |
|
1923 |
placeHolder->window = flags & StateFlagFloating; |
|
1924 |
placeHolder->hidden = !(flags & StateFlagVisible); |
|
1925 |
if (placeHolder->window) { |
|
1926 |
int x, y, w, h; |
|
1927 |
stream >> x >> y >> w >> h; |
|
1928 |
placeHolder->topLevelRect = QRect(x, y, w, h); |
|
1929 |
} else { |
|
1930 |
int dummy; |
|
1931 |
stream >> item.pos >> item.size >> dummy >> dummy; |
|
1932 |
} |
|
1933 |
if (item.size != -1) |
|
1934 |
item.flags |= QDockAreaLayoutItem::KeepSize; |
|
1935 |
if (!testing) |
|
1936 |
item_list.append(item); |
|
1937 |
} else { |
|
1938 |
QDockAreaLayoutItem item(new QDockWidgetItem(widget)); |
|
1939 |
if (flags & StateFlagFloating) { |
|
1940 |
bool drawer = false; |
|
1941 |
#ifdef Q_WS_MAC // drawer support |
|
1942 |
extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp |
|
1943 |
extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp |
|
1944 |
drawer = qt_mac_is_macdrawer(widget); |
|
1945 |
#endif |
|
1946 |
||
1947 |
if (!testing) { |
|
1948 |
widget->hide(); |
|
1949 |
if (!drawer) |
|
1950 |
widget->setFloating(true); |
|
1951 |
} |
|
1952 |
||
1953 |
int x, y, w, h; |
|
1954 |
stream >> x >> y >> w >> h; |
|
1955 |
||
1956 |
#ifdef Q_WS_MAC // drawer support |
|
1957 |
if (drawer) { |
|
1958 |
mainWindow->window()->createWinId(); |
|
1959 |
widget->window()->createWinId(); |
|
1960 |
qt_mac_set_drawer_preferred_edge(widget, toDockWidgetArea(dockPos)); |
|
1961 |
} else |
|
1962 |
#endif |
|
1963 |
if (!testing) { |
|
1964 |
QRect r(x, y, w, h); |
|
1965 |
QDesktopWidget *desktop = QApplication::desktop(); |
|
1966 |
if (desktop->isVirtualDesktop()) |
|
1967 |
r = constrainedRect(r, desktop->screenGeometry(desktop->screenNumber(r.topLeft()))); |
|
1968 |
else |
|
1969 |
r = constrainedRect(r, desktop->screenGeometry(widget)); |
|
1970 |
widget->move(r.topLeft()); |
|
1971 |
widget->resize(r.size()); |
|
1972 |
} |
|
1973 |
||
1974 |
if (!testing) { |
|
1975 |
widget->setVisible(flags & StateFlagVisible); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1976 |
item_list.append(item); |
0 | 1977 |
} |
1978 |
} else { |
|
1979 |
int dummy; |
|
1980 |
stream >> item.pos >> item.size >> dummy >> dummy; |
|
1981 |
if (!testing) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1982 |
item_list.append(item); |
0 | 1983 |
widget->setFloating(false); |
1984 |
widget->setVisible(flags & StateFlagVisible); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1985 |
emit widget->dockLocationChanged(toDockWidgetArea(dockPos)); |
0 | 1986 |
} |
1987 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1988 |
if (testing) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1989 |
//was it is not really added to the layout, we need to delete the object here |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1990 |
delete item.widgetItem; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1991 |
} |
0 | 1992 |
} |
1993 |
} else if (nextMarker == SequenceMarker) { |
|
1994 |
int dummy; |
|
1995 |
#ifdef QT_NO_TABBAR |
|
1996 |
const int tabBarShape = 0; |
|
1997 |
#endif |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1998 |
QDockAreaLayoutItem item(new QDockAreaLayoutInfo(sep, dockPos, o, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1999 |
tabBarShape, mainWindow)); |
0 | 2000 |
stream >> item.pos >> item.size >> dummy >> dummy; |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2001 |
//we need to make sure the element is in the list so the dock widget can eventually be docked correctly |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2002 |
if (!testing) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2003 |
item_list.append(item); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2004 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2005 |
//here we need to make sure we change the item in the item_list |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2006 |
QDockAreaLayoutItem &lastItem = testing ? item : item_list.last(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2007 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2008 |
if (!lastItem.subinfo->restoreState(stream, widgets, testing)) |
0 | 2009 |
return false; |
2010 |
||
2011 |
} else { |
|
2012 |
return false; |
|
2013 |
} |
|
2014 |
} |
|
2015 |
||
2016 |
#ifndef QT_NO_TABBAR |
|
2017 |
if (!testing && tabbed && index >= 0 && index < item_list.count()) { |
|
2018 |
updateTabBar(); |
|
2019 |
setCurrentTabId(tabId(item_list.at(index))); |
|
2020 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2021 |
if (!testing && *sep == 1) |
0 | 2022 |
updateSeparatorWidgets(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2023 |
#endif |
0 | 2024 |
|
2025 |
return true; |
|
2026 |
} |
|
2027 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2028 |
#ifndef QT_NO_TABBAR |
0 | 2029 |
void QDockAreaLayoutInfo::updateSeparatorWidgets() const |
2030 |
{ |
|
2031 |
if (tabbed) { |
|
2032 |
separatorWidgets.clear(); |
|
2033 |
return; |
|
2034 |
} |
|
2035 |
||
2036 |
int j = 0; |
|
2037 |
for (int i = 0; i < item_list.count(); ++i) { |
|
2038 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
2039 |
||
2040 |
if (item.skip()) |
|
2041 |
continue; |
|
2042 |
||
2043 |
int next = this->next(i); |
|
2044 |
if ((item.flags & QDockAreaLayoutItem::GapItem) |
|
2045 |
|| (next != -1 && (item_list.at(next).flags & QDockAreaLayoutItem::GapItem))) |
|
2046 |
continue; |
|
2047 |
||
2048 |
if (item.subinfo) { |
|
2049 |
item.subinfo->updateSeparatorWidgets(); |
|
2050 |
} |
|
2051 |
||
2052 |
if (next == -1) |
|
2053 |
break; |
|
2054 |
||
2055 |
QWidget *sepWidget; |
|
2056 |
if (j < separatorWidgets.size() && separatorWidgets.at(j)) { |
|
2057 |
sepWidget = separatorWidgets.at(j); |
|
2058 |
} else { |
|
2059 |
sepWidget = mainWindowLayout()->getSeparatorWidget(); |
|
2060 |
separatorWidgets.append(sepWidget); |
|
2061 |
} |
|
2062 |
j++; |
|
2063 |
||
2064 |
#ifndef QT_MAC_USE_COCOA |
|
2065 |
sepWidget->raise(); |
|
2066 |
#endif |
|
2067 |
QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2); |
|
2068 |
sepWidget->setGeometry(sepRect); |
|
2069 |
sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft()))); |
|
2070 |
sepWidget->show(); |
|
2071 |
} |
|
2072 |
||
2073 |
for (int k = j; k < separatorWidgets.size(); ++k) { |
|
2074 |
separatorWidgets[k]->hide(); |
|
2075 |
} |
|
2076 |
separatorWidgets.resize(j); |
|
2077 |
Q_ASSERT(separatorWidgets.size() == j); |
|
2078 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2079 |
#endif //QT_NO_TABBAR |
0 | 2080 |
|
2081 |
#ifndef QT_NO_TABBAR |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2082 |
//returns whether the tabbar is visible or not |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2083 |
bool QDockAreaLayoutInfo::updateTabBar() const |
0 | 2084 |
{ |
2085 |
if (!tabbed) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2086 |
return false; |
0 | 2087 |
|
2088 |
QDockAreaLayoutInfo *that = const_cast<QDockAreaLayoutInfo*>(this); |
|
2089 |
||
2090 |
if (that->tabBar == 0) { |
|
2091 |
that->tabBar = mainWindowLayout()->getTabBar(); |
|
2092 |
that->tabBar->setShape(static_cast<QTabBar::Shape>(tabBarShape)); |
|
2093 |
that->tabBar->setDrawBase(true); |
|
2094 |
} |
|
2095 |
||
2096 |
bool blocked = tabBar->blockSignals(true); |
|
2097 |
bool gap = false; |
|
2098 |
||
2099 |
int tab_idx = 0; |
|
2100 |
bool changed = false; |
|
2101 |
for (int i = 0; i < item_list.count(); ++i) { |
|
2102 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
2103 |
if (item.skip()) |
|
2104 |
continue; |
|
2105 |
if (item.flags & QDockAreaLayoutItem::GapItem) { |
|
2106 |
gap = true; |
|
2107 |
continue; |
|
2108 |
} |
|
2109 |
if (item.widgetItem == 0) |
|
2110 |
continue; |
|
2111 |
||
2112 |
QDockWidget *dw = qobject_cast<QDockWidget*>(item.widgetItem->widget()); |
|
2113 |
QString title = dw->d_func()->fixedWindowTitle; |
|
2114 |
quintptr id = tabId(item); |
|
2115 |
if (tab_idx == tabBar->count()) { |
|
2116 |
tabBar->insertTab(tab_idx, title); |
|
2117 |
#ifndef QT_NO_TOOLTIP |
|
2118 |
tabBar->setTabToolTip(tab_idx, title); |
|
2119 |
#endif |
|
2120 |
tabBar->setTabData(tab_idx, id); |
|
2121 |
changed = true; |
|
2122 |
} else if (qvariant_cast<quintptr>(tabBar->tabData(tab_idx)) != id) { |
|
2123 |
if (tab_idx + 1 < tabBar->count() |
|
2124 |
&& qvariant_cast<quintptr>(tabBar->tabData(tab_idx + 1)) == id) |
|
2125 |
tabBar->removeTab(tab_idx); |
|
2126 |
else { |
|
2127 |
tabBar->insertTab(tab_idx, title); |
|
2128 |
#ifndef QT_NO_TOOLTIP |
|
2129 |
tabBar->setTabToolTip(tab_idx, title); |
|
2130 |
#endif |
|
2131 |
tabBar->setTabData(tab_idx, id); |
|
2132 |
} |
|
2133 |
changed = true; |
|
2134 |
} |
|
2135 |
||
2136 |
if (title != tabBar->tabText(tab_idx)) { |
|
2137 |
tabBar->setTabText(tab_idx, title); |
|
2138 |
#ifndef QT_NO_TOOLTIP |
|
2139 |
tabBar->setTabToolTip(tab_idx, title); |
|
2140 |
#endif |
|
2141 |
changed = true; |
|
2142 |
} |
|
2143 |
||
2144 |
++tab_idx; |
|
2145 |
} |
|
2146 |
||
2147 |
while (tab_idx < tabBar->count()) { |
|
2148 |
tabBar->removeTab(tab_idx); |
|
2149 |
changed = true; |
|
2150 |
} |
|
2151 |
||
2152 |
tabBar->blockSignals(blocked); |
|
2153 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2154 |
//returns if the tabbar is visible or not |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2155 |
return ( (gap ? 1 : 0) + tabBar->count()) > 1; |
0 | 2156 |
} |
2157 |
||
2158 |
void QDockAreaLayoutInfo::setTabBarShape(int shape) |
|
2159 |
{ |
|
2160 |
if (shape == tabBarShape) |
|
2161 |
return; |
|
2162 |
tabBarShape = shape; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2163 |
if (tabBar != 0) |
0 | 2164 |
tabBar->setShape(static_cast<QTabBar::Shape>(shape)); |
2165 |
||
2166 |
for (int i = 0; i < item_list.count(); ++i) { |
|
2167 |
QDockAreaLayoutItem &item = item_list[i]; |
|
2168 |
if (item.subinfo != 0) |
|
2169 |
item.subinfo->setTabBarShape(shape); |
|
2170 |
} |
|
2171 |
} |
|
2172 |
||
2173 |
QSize QDockAreaLayoutInfo::tabBarMinimumSize() const |
|
2174 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2175 |
if (!updateTabBar()) |
0 | 2176 |
return QSize(0, 0); |
2177 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2178 |
return tabBar->minimumSizeHint(); |
0 | 2179 |
} |
2180 |
||
2181 |
QSize QDockAreaLayoutInfo::tabBarSizeHint() const |
|
2182 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2183 |
if (!updateTabBar()) |
0 | 2184 |
return QSize(0, 0); |
2185 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2186 |
return tabBar->sizeHint(); |
0 | 2187 |
} |
2188 |
||
2189 |
QSet<QTabBar*> QDockAreaLayoutInfo::usedTabBars() const |
|
2190 |
{ |
|
2191 |
QSet<QTabBar*> result; |
|
2192 |
||
2193 |
if (tabbed) { |
|
2194 |
updateTabBar(); |
|
2195 |
result.insert(tabBar); |
|
2196 |
} |
|
2197 |
||
2198 |
for (int i = 0; i < item_list.count(); ++i) { |
|
2199 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
2200 |
if (item.subinfo != 0) |
|
2201 |
result += item.subinfo->usedTabBars(); |
|
2202 |
} |
|
2203 |
||
2204 |
return result; |
|
2205 |
} |
|
2206 |
||
2207 |
// returns a set of all used separator widgets for this dockarelayout info |
|
2208 |
// and all subinfos |
|
2209 |
QSet<QWidget*> QDockAreaLayoutInfo::usedSeparatorWidgets() const |
|
2210 |
{ |
|
2211 |
QSet<QWidget*> result; |
|
2212 |
||
2213 |
for (int i = 0; i < separatorWidgets.count(); ++i) |
|
2214 |
result << separatorWidgets.at(i); |
|
2215 |
||
2216 |
for (int i = 0; i < item_list.count(); ++i) { |
|
2217 |
const QDockAreaLayoutItem &item = item_list.at(i); |
|
2218 |
if (item.subinfo != 0) |
|
2219 |
result += item.subinfo->usedSeparatorWidgets(); |
|
2220 |
} |
|
2221 |
||
2222 |
return result; |
|
2223 |
} |
|
2224 |
||
2225 |
QRect QDockAreaLayoutInfo::tabContentRect() const |
|
2226 |
{ |
|
2227 |
if (!tabbed) |
|
2228 |
return QRect(); |
|
2229 |
||
2230 |
QRect result = rect; |
|
2231 |
QSize tbh = tabBarSizeHint(); |
|
2232 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2233 |
if (!tbh.isNull()) { |
0 | 2234 |
switch (tabBarShape) { |
2235 |
case QTabBar::RoundedNorth: |
|
2236 |
case QTabBar::TriangularNorth: |
|
2237 |
result.adjust(0, tbh.height(), 0, 0); |
|
2238 |
break; |
|
2239 |
case QTabBar::RoundedSouth: |
|
2240 |
case QTabBar::TriangularSouth: |
|
2241 |
result.adjust(0, 0, 0, -tbh.height()); |
|
2242 |
break; |
|
2243 |
case QTabBar::RoundedEast: |
|
2244 |
case QTabBar::TriangularEast: |
|
2245 |
result.adjust(0, 0, -tbh.width(), 0); |
|
2246 |
break; |
|
2247 |
case QTabBar::RoundedWest: |
|
2248 |
case QTabBar::TriangularWest: |
|
2249 |
result.adjust(tbh.width(), 0, 0, 0); |
|
2250 |
break; |
|
2251 |
default: |
|
2252 |
break; |
|
2253 |
} |
|
2254 |
} |
|
2255 |
||
2256 |
return result; |
|
2257 |
} |
|
2258 |
#endif // QT_NO_TABBAR |
|
2259 |
||
2260 |
/****************************************************************************** |
|
2261 |
** QDockAreaLayout |
|
2262 |
*/ |
|
2263 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2264 |
QDockAreaLayout::QDockAreaLayout(QMainWindow *win) : fallbackToSizeHints(true) |
0 | 2265 |
{ |
2266 |
mainWindow = win; |
|
2267 |
sep = win->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, win); |
|
2268 |
#ifndef QT_NO_TABBAR |
|
2269 |
const int tabShape = QTabBar::RoundedSouth; |
|
2270 |
#else |
|
2271 |
const int tabShape = 0; |
|
2272 |
#endif |
|
2273 |
docks[QInternal::LeftDock] |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2274 |
= QDockAreaLayoutInfo(&sep, QInternal::LeftDock, Qt::Vertical, tabShape, win); |
0 | 2275 |
docks[QInternal::RightDock] |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2276 |
= QDockAreaLayoutInfo(&sep, QInternal::RightDock, Qt::Vertical, tabShape, win); |
0 | 2277 |
docks[QInternal::TopDock] |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2278 |
= QDockAreaLayoutInfo(&sep, QInternal::TopDock, Qt::Horizontal, tabShape, win); |
0 | 2279 |
docks[QInternal::BottomDock] |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2280 |
= QDockAreaLayoutInfo(&sep, QInternal::BottomDock, Qt::Horizontal, tabShape, win); |
0 | 2281 |
centralWidgetItem = 0; |
2282 |
||
2283 |
||
2284 |
corners[Qt::TopLeftCorner] = Qt::TopDockWidgetArea; |
|
2285 |
corners[Qt::TopRightCorner] = Qt::TopDockWidgetArea; |
|
2286 |
corners[Qt::BottomLeftCorner] = Qt::BottomDockWidgetArea; |
|
2287 |
corners[Qt::BottomRightCorner] = Qt::BottomDockWidgetArea; |
|
2288 |
} |
|
2289 |
||
2290 |
bool QDockAreaLayout::isValid() const |
|
2291 |
{ |
|
2292 |
return rect.isValid(); |
|
2293 |
} |
|
2294 |
||
2295 |
void QDockAreaLayout::saveState(QDataStream &stream) const |
|
2296 |
{ |
|
2297 |
stream << (uchar) DockWidgetStateMarker; |
|
2298 |
int cnt = 0; |
|
2299 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2300 |
if (!docks[i].item_list.isEmpty()) |
|
2301 |
++cnt; |
|
2302 |
} |
|
2303 |
stream << cnt; |
|
2304 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2305 |
if (docks[i].item_list.isEmpty()) |
|
2306 |
continue; |
|
2307 |
stream << i << docks[i].rect.size(); |
|
2308 |
docks[i].saveState(stream); |
|
2309 |
} |
|
2310 |
||
2311 |
stream << centralWidgetRect.size(); |
|
2312 |
||
2313 |
for (int i = 0; i < 4; ++i) |
|
2314 |
stream << static_cast<int>(corners[i]); |
|
2315 |
} |
|
2316 |
||
2317 |
bool QDockAreaLayout::restoreState(QDataStream &stream, const QList<QDockWidget*> &_dockwidgets, bool testing) |
|
2318 |
{ |
|
2319 |
QList<QDockWidget*> dockwidgets = _dockwidgets; |
|
2320 |
||
2321 |
int cnt; |
|
2322 |
stream >> cnt; |
|
2323 |
for (int i = 0; i < cnt; ++i) { |
|
2324 |
int pos; |
|
2325 |
stream >> pos; |
|
2326 |
QSize size; |
|
2327 |
stream >> size; |
|
2328 |
if (!testing) { |
|
2329 |
docks[pos].rect = QRect(QPoint(0, 0), size); |
|
2330 |
} |
|
2331 |
if (!docks[pos].restoreState(stream, dockwidgets, testing)) { |
|
2332 |
stream.setStatus(QDataStream::ReadCorruptData); |
|
2333 |
return false; |
|
2334 |
} |
|
2335 |
} |
|
2336 |
||
2337 |
QSize size; |
|
2338 |
stream >> size; |
|
2339 |
centralWidgetRect = QRect(QPoint(0, 0), size); |
|
2340 |
||
2341 |
bool ok = stream.status() == QDataStream::Ok; |
|
2342 |
||
2343 |
if (ok) { |
|
2344 |
int cornerData[4]; |
|
2345 |
for (int i = 0; i < 4; ++i) |
|
2346 |
stream >> cornerData[i]; |
|
2347 |
if (stream.status() == QDataStream::Ok) { |
|
2348 |
for (int i = 0; i < 4; ++i) |
|
2349 |
corners[i] = static_cast<Qt::DockWidgetArea>(cornerData[i]); |
|
2350 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2351 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2352 |
if (!testing) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2353 |
fallbackToSizeHints = false; |
0 | 2354 |
} |
2355 |
||
2356 |
return ok; |
|
2357 |
} |
|
2358 |
||
2359 |
QList<int> QDockAreaLayout::indexOfPlaceHolder(const QString &objectName) const |
|
2360 |
{ |
|
2361 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2362 |
QList<int> result = docks[i].indexOfPlaceHolder(objectName); |
|
2363 |
if (!result.isEmpty()) { |
|
2364 |
result.prepend(i); |
|
2365 |
return result; |
|
2366 |
} |
|
2367 |
} |
|
2368 |
return QList<int>(); |
|
2369 |
} |
|
2370 |
||
2371 |
QList<int> QDockAreaLayout::indexOf(QWidget *dockWidget) const |
|
2372 |
{ |
|
2373 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2374 |
QList<int> result = docks[i].indexOf(dockWidget); |
|
2375 |
if (!result.isEmpty()) { |
|
2376 |
result.prepend(i); |
|
2377 |
return result; |
|
2378 |
} |
|
2379 |
} |
|
2380 |
return QList<int>(); |
|
2381 |
} |
|
2382 |
||
2383 |
QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const |
|
2384 |
{ |
|
2385 |
QMainWindow::DockOptions opts = mainWindow->dockOptions(); |
|
2386 |
bool nestingEnabled = opts & QMainWindow::AllowNestedDocks; |
|
2387 |
QDockAreaLayoutInfo::TabMode tabMode = QDockAreaLayoutInfo::NoTabs; |
|
2388 |
#ifndef QT_NO_TABBAR |
|
2389 |
if (opts & QMainWindow::AllowTabbedDocks |
|
2390 |
|| opts & QMainWindow::VerticalTabs) |
|
2391 |
tabMode = QDockAreaLayoutInfo::AllowTabs; |
|
2392 |
if (opts & QMainWindow::ForceTabbedDocks) |
|
2393 |
tabMode = QDockAreaLayoutInfo::ForceTabs; |
|
2394 |
||
2395 |
if (tabMode == QDockAreaLayoutInfo::ForceTabs) |
|
2396 |
nestingEnabled = false; |
|
2397 |
#endif |
|
2398 |
||
2399 |
||
2400 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2401 |
const QDockAreaLayoutInfo &info = docks[i]; |
|
2402 |
||
2403 |
if (!info.isEmpty() && info.rect.contains(pos)) { |
|
2404 |
QList<int> result |
|
2405 |
= docks[i].gapIndex(pos, nestingEnabled, tabMode); |
|
2406 |
if (!result.isEmpty()) |
|
2407 |
result.prepend(i); |
|
2408 |
return result; |
|
2409 |
} |
|
2410 |
} |
|
2411 |
||
2412 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2413 |
const QDockAreaLayoutInfo &info = docks[i]; |
|
2414 |
||
2415 |
if (info.isEmpty()) { |
|
2416 |
QRect r; |
|
2417 |
switch (i) { |
|
2418 |
case QInternal::LeftDock: |
|
2419 |
r = QRect(rect.left(), rect.top(), EmptyDropAreaSize, rect.height()); |
|
2420 |
break; |
|
2421 |
case QInternal::RightDock: |
|
2422 |
r = QRect(rect.right() - EmptyDropAreaSize, rect.top(), |
|
2423 |
EmptyDropAreaSize, rect.height()); |
|
2424 |
break; |
|
2425 |
case QInternal::TopDock: |
|
2426 |
r = QRect(rect.left(), rect.top(), rect.width(), EmptyDropAreaSize); |
|
2427 |
break; |
|
2428 |
case QInternal::BottomDock: |
|
2429 |
r = QRect(rect.left(), rect.bottom() - EmptyDropAreaSize, |
|
2430 |
rect.width(), EmptyDropAreaSize); |
|
2431 |
break; |
|
2432 |
} |
|
2433 |
if (r.contains(pos)) { |
|
2434 |
if (opts & QMainWindow::ForceTabbedDocks && !info.item_list.isEmpty()) { |
|
2435 |
//in case of ForceTabbedDocks, we pass -1 in order to force the gap to be tabbed |
|
2436 |
//it mustn't be completely empty otherwise it won't work |
|
2437 |
return QList<int>() << i << -1 << 0; |
|
2438 |
} else { |
|
2439 |
return QList<int>() << i << 0; |
|
2440 |
} |
|
2441 |
} |
|
2442 |
} |
|
2443 |
} |
|
2444 |
||
2445 |
return QList<int>(); |
|
2446 |
} |
|
2447 |
||
2448 |
QList<int> QDockAreaLayout::findSeparator(const QPoint &pos) const |
|
2449 |
{ |
|
2450 |
QList<int> result; |
|
2451 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2452 |
const QDockAreaLayoutInfo &info = docks[i]; |
|
2453 |
if (info.isEmpty()) |
|
2454 |
continue; |
|
2455 |
QRect rect = separatorRect(i); |
|
2456 |
if (!rect.isNull() && sep == 1) |
|
2457 |
rect.adjust(-2, -2, 2, 2); |
|
2458 |
if (rect.contains(pos) && !info.hasFixedSize()) { |
|
2459 |
result << i; |
|
2460 |
break; |
|
2461 |
} else if (info.rect.contains(pos)) { |
|
2462 |
result = docks[i].findSeparator(pos); |
|
2463 |
if (!result.isEmpty()) { |
|
2464 |
result.prepend(i); |
|
2465 |
break; |
|
2466 |
} |
|
2467 |
} |
|
2468 |
} |
|
2469 |
||
2470 |
return result; |
|
2471 |
} |
|
2472 |
||
2473 |
QDockAreaLayoutInfo *QDockAreaLayout::info(QWidget *widget) |
|
2474 |
{ |
|
2475 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
2476 |
if (QDockAreaLayoutInfo *result = docks[i].info(widget)) |
|
2477 |
return result; |
|
2478 |
} |
|
2479 |
||
2480 |
return 0; |
|
2481 |
} |
|
2482 |
||
2483 |
QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path) |
|
2484 |
{ |
|
2485 |
Q_ASSERT(!path.isEmpty()); |
|
2486 |
const int index = path.first(); |
|
2487 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2488 |
||
2489 |
if (path.count() == 1) |
|
2490 |
return &docks[index]; |
|
2491 |
||
2492 |
return docks[index].info(path.mid(1)); |
|
2493 |
} |
|
2494 |
||
2495 |
const QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path) const |
|
2496 |
{ |
|
2497 |
return const_cast<QDockAreaLayout*>(this)->info(path); |
|
2498 |
} |
|
2499 |
||
2500 |
QDockAreaLayoutItem &QDockAreaLayout::item(const QList<int> &path) |
|
2501 |
{ |
|
2502 |
Q_ASSERT(!path.isEmpty()); |
|
2503 |
const int index = path.first(); |
|
2504 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2505 |
return docks[index].item(path.mid(1)); |
|
2506 |
} |
|
2507 |
||
2508 |
QRect QDockAreaLayout::itemRect(const QList<int> &path) const |
|
2509 |
{ |
|
2510 |
Q_ASSERT(!path.isEmpty()); |
|
2511 |
const int index = path.first(); |
|
2512 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2513 |
return docks[index].itemRect(path.mid(1)); |
|
2514 |
} |
|
2515 |
||
2516 |
QRect QDockAreaLayout::separatorRect(int index) const |
|
2517 |
{ |
|
2518 |
const QDockAreaLayoutInfo &dock = docks[index]; |
|
2519 |
if (dock.isEmpty()) |
|
2520 |
return QRect(); |
|
2521 |
QRect r = dock.rect; |
|
2522 |
switch (index) { |
|
2523 |
case QInternal::LeftDock: |
|
2524 |
return QRect(r.right() + 1, r.top(), sep, r.height()); |
|
2525 |
case QInternal::RightDock: |
|
2526 |
return QRect(r.left() - sep, r.top(), sep, r.height()); |
|
2527 |
case QInternal::TopDock: |
|
2528 |
return QRect(r.left(), r.bottom() + 1, r.width(), sep); |
|
2529 |
case QInternal::BottomDock: |
|
2530 |
return QRect(r.left(), r.top() - sep, r.width(), sep); |
|
2531 |
default: |
|
2532 |
break; |
|
2533 |
} |
|
2534 |
return QRect(); |
|
2535 |
} |
|
2536 |
||
2537 |
QRect QDockAreaLayout::separatorRect(const QList<int> &path) const |
|
2538 |
{ |
|
2539 |
Q_ASSERT(!path.isEmpty()); |
|
2540 |
||
2541 |
const int index = path.first(); |
|
2542 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2543 |
||
2544 |
if (path.count() == 1) |
|
2545 |
return separatorRect(index); |
|
2546 |
else |
|
2547 |
return docks[index].separatorRect(path.mid(1)); |
|
2548 |
} |
|
2549 |
||
2550 |
bool QDockAreaLayout::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem) |
|
2551 |
{ |
|
2552 |
Q_ASSERT(!path.isEmpty()); |
|
2553 |
const int index = path.first(); |
|
2554 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2555 |
return docks[index].insertGap(path.mid(1), dockWidgetItem); |
|
2556 |
} |
|
2557 |
||
2558 |
QLayoutItem *QDockAreaLayout::plug(const QList<int> &path) |
|
2559 |
{ |
|
2560 |
Q_ASSERT(!path.isEmpty()); |
|
2561 |
const int index = path.first(); |
|
2562 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2563 |
return docks[index].plug(path.mid(1)); |
|
2564 |
} |
|
2565 |
||
2566 |
QLayoutItem *QDockAreaLayout::unplug(const QList<int> &path) |
|
2567 |
{ |
|
2568 |
Q_ASSERT(!path.isEmpty()); |
|
2569 |
const int index = path.first(); |
|
2570 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2571 |
return docks[index].unplug(path.mid(1)); |
|
2572 |
} |
|
2573 |
||
2574 |
void QDockAreaLayout::remove(const QList<int> &path) |
|
2575 |
{ |
|
2576 |
Q_ASSERT(!path.isEmpty()); |
|
2577 |
const int index = path.first(); |
|
2578 |
Q_ASSERT(index >= 0 && index < QInternal::DockCount); |
|
2579 |
docks[index].remove(path.mid(1)); |
|
2580 |
} |
|
2581 |
||
2582 |
static inline int qMin(int i1, int i2, int i3) { return qMin(i1, qMin(i2, i3)); } |
|
2583 |
static inline int qMax(int i1, int i2, int i3) { return qMax(i1, qMax(i2, i3)); } |
|
2584 |
||
2585 |
void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list, |
|
2586 |
QVector<QLayoutStruct> *_hor_struct_list) |
|
2587 |
{ |
|
2588 |
QSize center_hint(0, 0); |
|
2589 |
QSize center_min(0, 0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2590 |
const bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty(); |
0 | 2591 |
if (have_central) { |
2592 |
center_hint = centralWidgetRect.size(); |
|
2593 |
if (!center_hint.isValid()) |
|
2594 |
center_hint = centralWidgetItem->sizeHint(); |
|
2595 |
center_min = centralWidgetItem->minimumSize(); |
|
2596 |
} |
|
2597 |
||
2598 |
QRect center_rect = rect; |
|
2599 |
if (!docks[QInternal::LeftDock].isEmpty()) |
|
2600 |
center_rect.setLeft(rect.left() + docks[QInternal::LeftDock].rect.width() + sep); |
|
2601 |
if (!docks[QInternal::TopDock].isEmpty()) |
|
2602 |
center_rect.setTop(rect.top() + docks[QInternal::TopDock].rect.height() + sep); |
|
2603 |
if (!docks[QInternal::RightDock].isEmpty()) |
|
2604 |
center_rect.setRight(rect.right() - docks[QInternal::RightDock].rect.width() - sep); |
|
2605 |
if (!docks[QInternal::BottomDock].isEmpty()) |
|
2606 |
center_rect.setBottom(rect.bottom() - docks[QInternal::BottomDock].rect.height() - sep); |
|
2607 |
||
2608 |
QSize left_hint = docks[QInternal::LeftDock].size(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2609 |
if (left_hint.isNull() || fallbackToSizeHints) |
0 | 2610 |
left_hint = docks[QInternal::LeftDock].sizeHint(); |
2611 |
QSize left_min = docks[QInternal::LeftDock].minimumSize(); |
|
2612 |
QSize left_max = docks[QInternal::LeftDock].maximumSize(); |
|
2613 |
left_hint = left_hint.boundedTo(left_max).expandedTo(left_min); |
|
2614 |
||
2615 |
QSize right_hint = docks[QInternal::RightDock].size(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2616 |
if (right_hint.isNull() || fallbackToSizeHints) |
0 | 2617 |
right_hint = docks[QInternal::RightDock].sizeHint(); |
2618 |
QSize right_min = docks[QInternal::RightDock].minimumSize(); |
|
2619 |
QSize right_max = docks[QInternal::RightDock].maximumSize(); |
|
2620 |
right_hint = right_hint.boundedTo(right_max).expandedTo(right_min); |
|
2621 |
||
2622 |
QSize top_hint = docks[QInternal::TopDock].size(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2623 |
if (top_hint.isNull() || fallbackToSizeHints) |
0 | 2624 |
top_hint = docks[QInternal::TopDock].sizeHint(); |
2625 |
QSize top_min = docks[QInternal::TopDock].minimumSize(); |
|
2626 |
QSize top_max = docks[QInternal::TopDock].maximumSize(); |
|
2627 |
top_hint = top_hint.boundedTo(top_max).expandedTo(top_min); |
|
2628 |
||
2629 |
QSize bottom_hint = docks[QInternal::BottomDock].size(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2630 |
if (bottom_hint.isNull() || fallbackToSizeHints) |
0 | 2631 |
bottom_hint = docks[QInternal::BottomDock].sizeHint(); |
2632 |
QSize bottom_min = docks[QInternal::BottomDock].minimumSize(); |
|
2633 |
QSize bottom_max = docks[QInternal::BottomDock].maximumSize(); |
|
2634 |
bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min); |
|
2635 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2636 |
fallbackToSizeHints = false; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2637 |
|
0 | 2638 |
if (_ver_struct_list != 0) { |
2639 |
QVector<QLayoutStruct> &ver_struct_list = *_ver_struct_list; |
|
2640 |
ver_struct_list.resize(3); |
|
2641 |
||
2642 |
// top -------------------------------------------------- |
|
2643 |
ver_struct_list[0].init(); |
|
2644 |
ver_struct_list[0].stretch = 0; |
|
2645 |
ver_struct_list[0].sizeHint = top_hint.height(); |
|
2646 |
ver_struct_list[0].minimumSize = top_min.height(); |
|
2647 |
ver_struct_list[0].maximumSize = top_max.height(); |
|
2648 |
ver_struct_list[0].expansive = false; |
|
2649 |
ver_struct_list[0].empty = docks[QInternal::TopDock].isEmpty(); |
|
2650 |
ver_struct_list[0].pos = docks[QInternal::TopDock].rect.top(); |
|
2651 |
ver_struct_list[0].size = docks[QInternal::TopDock].rect.height(); |
|
2652 |
||
2653 |
// center -------------------------------------------------- |
|
2654 |
ver_struct_list[1].init(); |
|
2655 |
ver_struct_list[1].stretch = center_hint.height(); |
|
2656 |
||
2657 |
bool tl_significant = corners[Qt::TopLeftCorner] == Qt::TopDockWidgetArea |
|
2658 |
|| docks[QInternal::TopDock].isEmpty(); |
|
2659 |
bool bl_significant = corners[Qt::BottomLeftCorner] == Qt::BottomDockWidgetArea |
|
2660 |
|| docks[QInternal::BottomDock].isEmpty(); |
|
2661 |
bool tr_significant = corners[Qt::TopRightCorner] == Qt::TopDockWidgetArea |
|
2662 |
|| docks[QInternal::TopDock].isEmpty(); |
|
2663 |
bool br_significant = corners[Qt::BottomRightCorner] == Qt::BottomDockWidgetArea |
|
2664 |
|| docks[QInternal::BottomDock].isEmpty(); |
|
2665 |
||
2666 |
int left = (tl_significant && bl_significant) ? left_hint.height() : 0; |
|
2667 |
int right = (tr_significant && br_significant) ? right_hint.height() : 0; |
|
2668 |
ver_struct_list[1].sizeHint = qMax(left, center_hint.height(), right); |
|
2669 |
||
2670 |
left = (tl_significant && bl_significant) ? left_min.height() : 0; |
|
2671 |
right = (tr_significant && br_significant) ? right_min.height() : 0; |
|
2672 |
ver_struct_list[1].minimumSize = qMax(left, center_min.height(), right); |
|
2673 |
ver_struct_list[1].maximumSize = have_central ? QWIDGETSIZE_MAX : 0; |
|
2674 |
ver_struct_list[1].expansive = have_central; |
|
2675 |
ver_struct_list[1].empty = docks[QInternal::LeftDock].isEmpty() |
|
2676 |
&& !have_central |
|
2677 |
&& docks[QInternal::RightDock].isEmpty(); |
|
2678 |
ver_struct_list[1].pos = center_rect.top(); |
|
2679 |
ver_struct_list[1].size = center_rect.height(); |
|
2680 |
||
2681 |
// bottom -------------------------------------------------- |
|
2682 |
ver_struct_list[2].init(); |
|
2683 |
ver_struct_list[2].stretch = 0; |
|
2684 |
ver_struct_list[2].sizeHint = bottom_hint.height(); |
|
2685 |
ver_struct_list[2].minimumSize = bottom_min.height(); |
|
2686 |
ver_struct_list[2].maximumSize = bottom_max.height(); |
|
2687 |
ver_struct_list[2].expansive = false; |
|
2688 |
ver_struct_list[2].empty = docks[QInternal::BottomDock].isEmpty(); |
|
2689 |
ver_struct_list[2].pos = docks[QInternal::BottomDock].rect.top(); |
|
2690 |
ver_struct_list[2].size = docks[QInternal::BottomDock].rect.height(); |
|
2691 |
||
2692 |
for (int i = 0; i < 3; ++i) { |
|
2693 |
ver_struct_list[i].sizeHint |
|
2694 |
= qMax(ver_struct_list[i].sizeHint, ver_struct_list[i].minimumSize); |
|
2695 |
} |
|
2696 |
} |
|
2697 |
||
2698 |
if (_hor_struct_list != 0) { |
|
2699 |
QVector<QLayoutStruct> &hor_struct_list = *_hor_struct_list; |
|
2700 |
hor_struct_list.resize(3); |
|
2701 |
||
2702 |
// left -------------------------------------------------- |
|
2703 |
hor_struct_list[0].init(); |
|
2704 |
hor_struct_list[0].stretch = 0; |
|
2705 |
hor_struct_list[0].sizeHint = left_hint.width(); |
|
2706 |
hor_struct_list[0].minimumSize = left_min.width(); |
|
2707 |
hor_struct_list[0].maximumSize = left_max.width(); |
|
2708 |
hor_struct_list[0].expansive = false; |
|
2709 |
hor_struct_list[0].empty = docks[QInternal::LeftDock].isEmpty(); |
|
2710 |
hor_struct_list[0].pos = docks[QInternal::LeftDock].rect.left(); |
|
2711 |
hor_struct_list[0].size = docks[QInternal::LeftDock].rect.width(); |
|
2712 |
||
2713 |
// center -------------------------------------------------- |
|
2714 |
hor_struct_list[1].init(); |
|
2715 |
hor_struct_list[1].stretch = center_hint.width(); |
|
2716 |
||
2717 |
bool tl_significant = corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea |
|
2718 |
|| docks[QInternal::LeftDock].isEmpty(); |
|
2719 |
bool tr_significant = corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea |
|
2720 |
|| docks[QInternal::RightDock].isEmpty(); |
|
2721 |
bool bl_significant = corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea |
|
2722 |
|| docks[QInternal::LeftDock].isEmpty(); |
|
2723 |
bool br_significant = corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea |
|
2724 |
|| docks[QInternal::RightDock].isEmpty(); |
|
2725 |
||
2726 |
int top = (tl_significant && tr_significant) ? top_hint.width() : 0; |
|
2727 |
int bottom = (bl_significant && br_significant) ? bottom_hint.width() : 0; |
|
2728 |
hor_struct_list[1].sizeHint = qMax(top, center_hint.width(), bottom); |
|
2729 |
||
2730 |
top = (tl_significant && tr_significant) ? top_min.width() : 0; |
|
2731 |
bottom = (bl_significant && br_significant) ? bottom_min.width() : 0; |
|
2732 |
hor_struct_list[1].minimumSize = qMax(top, center_min.width(), bottom); |
|
2733 |
||
2734 |
hor_struct_list[1].maximumSize = have_central ? QWIDGETSIZE_MAX : 0; |
|
2735 |
hor_struct_list[1].expansive = have_central; |
|
2736 |
hor_struct_list[1].empty = !have_central; |
|
2737 |
hor_struct_list[1].pos = center_rect.left(); |
|
2738 |
hor_struct_list[1].size = center_rect.width(); |
|
2739 |
||
2740 |
// right -------------------------------------------------- |
|
2741 |
hor_struct_list[2].init(); |
|
2742 |
hor_struct_list[2].stretch = 0; |
|
2743 |
hor_struct_list[2].sizeHint = right_hint.width(); |
|
2744 |
hor_struct_list[2].minimumSize = right_min.width(); |
|
2745 |
hor_struct_list[2].maximumSize = right_max.width(); |
|
2746 |
hor_struct_list[2].expansive = false; |
|
2747 |
hor_struct_list[2].empty = docks[QInternal::RightDock].isEmpty(); |
|
2748 |
hor_struct_list[2].pos = docks[QInternal::RightDock].rect.left(); |
|
2749 |
hor_struct_list[2].size = docks[QInternal::RightDock].rect.width(); |
|
2750 |
||
2751 |
for (int i = 0; i < 3; ++i) { |
|
2752 |
hor_struct_list[i].sizeHint |
|
2753 |
= qMax(hor_struct_list[i].sizeHint, hor_struct_list[i].minimumSize); |
|
2754 |
} |
|
2755 |
} |
|
2756 |
} |
|
2757 |
||
2758 |
void QDockAreaLayout::setGrid(QVector<QLayoutStruct> *ver_struct_list, |
|
2759 |
QVector<QLayoutStruct> *hor_struct_list) |
|
2760 |
{ |
|
2761 |
||
2762 |
// top --------------------------------------------------- |
|
2763 |
||
2764 |
if (!docks[QInternal::TopDock].isEmpty()) { |
|
2765 |
QRect r = docks[QInternal::TopDock].rect; |
|
2766 |
if (hor_struct_list != 0) { |
|
2767 |
r.setLeft(corners[Qt::TopLeftCorner] == Qt::TopDockWidgetArea |
|
2768 |
|| docks[QInternal::LeftDock].isEmpty() |
|
2769 |
? rect.left() : hor_struct_list->at(1).pos); |
|
2770 |
r.setRight(corners[Qt::TopRightCorner] == Qt::TopDockWidgetArea |
|
2771 |
|| docks[QInternal::RightDock].isEmpty() |
|
2772 |
? rect.right() : hor_struct_list->at(2).pos - sep - 1); |
|
2773 |
} |
|
2774 |
if (ver_struct_list != 0) { |
|
2775 |
r.setTop(rect.top()); |
|
2776 |
r.setBottom(ver_struct_list->at(1).pos - sep - 1); |
|
2777 |
} |
|
2778 |
docks[QInternal::TopDock].rect = r; |
|
2779 |
docks[QInternal::TopDock].fitItems(); |
|
2780 |
} |
|
2781 |
||
2782 |
// bottom --------------------------------------------------- |
|
2783 |
||
2784 |
if (!docks[QInternal::BottomDock].isEmpty()) { |
|
2785 |
QRect r = docks[QInternal::BottomDock].rect; |
|
2786 |
if (hor_struct_list != 0) { |
|
2787 |
r.setLeft(corners[Qt::BottomLeftCorner] == Qt::BottomDockWidgetArea |
|
2788 |
|| docks[QInternal::LeftDock].isEmpty() |
|
2789 |
? rect.left() : hor_struct_list->at(1).pos); |
|
2790 |
r.setRight(corners[Qt::BottomRightCorner] == Qt::BottomDockWidgetArea |
|
2791 |
|| docks[QInternal::RightDock].isEmpty() |
|
2792 |
? rect.right() : hor_struct_list->at(2).pos - sep - 1); |
|
2793 |
} |
|
2794 |
if (ver_struct_list != 0) { |
|
2795 |
r.setTop(ver_struct_list->at(2).pos); |
|
2796 |
r.setBottom(rect.bottom()); |
|
2797 |
} |
|
2798 |
docks[QInternal::BottomDock].rect = r; |
|
2799 |
docks[QInternal::BottomDock].fitItems(); |
|
2800 |
} |
|
2801 |
||
2802 |
// left --------------------------------------------------- |
|
2803 |
||
2804 |
if (!docks[QInternal::LeftDock].isEmpty()) { |
|
2805 |
QRect r = docks[QInternal::LeftDock].rect; |
|
2806 |
if (hor_struct_list != 0) { |
|
2807 |
r.setLeft(rect.left()); |
|
2808 |
r.setRight(hor_struct_list->at(1).pos - sep - 1); |
|
2809 |
} |
|
2810 |
if (ver_struct_list != 0) { |
|
2811 |
r.setTop(corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea |
|
2812 |
|| docks[QInternal::TopDock].isEmpty() |
|
2813 |
? rect.top() : ver_struct_list->at(1).pos); |
|
2814 |
r.setBottom(corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea |
|
2815 |
|| docks[QInternal::BottomDock].isEmpty() |
|
2816 |
? rect.bottom() : ver_struct_list->at(2).pos - sep - 1); |
|
2817 |
} |
|
2818 |
docks[QInternal::LeftDock].rect = r; |
|
2819 |
docks[QInternal::LeftDock].fitItems(); |
|
2820 |
} |
|
2821 |
||
2822 |
// right --------------------------------------------------- |
|
2823 |
||
2824 |
if (!docks[QInternal::RightDock].isEmpty()) { |
|
2825 |
QRect r = docks[QInternal::RightDock].rect; |
|
2826 |
if (hor_struct_list != 0) { |
|
2827 |
r.setLeft(hor_struct_list->at(2).pos); |
|
2828 |
r.setRight(rect.right()); |
|
2829 |
} |
|
2830 |
if (ver_struct_list != 0) { |
|
2831 |
r.setTop(corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea |
|
2832 |
|| docks[QInternal::TopDock].isEmpty() |
|
2833 |
? rect.top() : ver_struct_list->at(1).pos); |
|
2834 |
r.setBottom(corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea |
|
2835 |
|| docks[QInternal::BottomDock].isEmpty() |
|
2836 |
? rect.bottom() : ver_struct_list->at(2).pos - sep - 1); |
|
2837 |
} |
|
2838 |
docks[QInternal::RightDock].rect = r; |
|
2839 |
docks[QInternal::RightDock].fitItems(); |
|
2840 |
} |
|
2841 |
||
2842 |
// center --------------------------------------------------- |
|
2843 |
||
2844 |
if (hor_struct_list != 0) { |
|
2845 |
centralWidgetRect.setLeft(hor_struct_list->at(1).pos); |
|
2846 |
centralWidgetRect.setWidth(hor_struct_list->at(1).size); |
|
2847 |
} |
|
2848 |
if (ver_struct_list != 0) { |
|
2849 |
centralWidgetRect.setTop(ver_struct_list->at(1).pos); |
|
2850 |
centralWidgetRect.setHeight(ver_struct_list->at(1).size); |
|
2851 |
} |
|
2852 |
} |
|
2853 |
||
2854 |
void QDockAreaLayout::fitLayout() |
|
2855 |
{ |
|
2856 |
QVector<QLayoutStruct> ver_struct_list(3); |
|
2857 |
QVector<QLayoutStruct> hor_struct_list(3); |
|
2858 |
getGrid(&ver_struct_list, &hor_struct_list); |
|
2859 |
||
2860 |
qGeomCalc(ver_struct_list, 0, 3, rect.top(), rect.height(), sep); |
|
2861 |
qGeomCalc(hor_struct_list, 0, 3, rect.left(), rect.width(), sep); |
|
2862 |
||
2863 |
setGrid(&ver_struct_list, &hor_struct_list); |
|
2864 |
} |
|
2865 |
||
2866 |
void QDockAreaLayout::clear() |
|
2867 |
{ |
|
2868 |
for (int i = 0; i < QInternal::DockCount; ++i) |
|
2869 |
docks[i].clear(); |
|
2870 |
||
2871 |
rect = QRect(); |
|
2872 |
centralWidgetRect = QRect(); |
|
2873 |
} |
|
2874 |
||
2875 |
QSize QDockAreaLayout::sizeHint() const |
|
2876 |
{ |
|
2877 |
int left_sep = 0; |
|
2878 |
int right_sep = 0; |
|
2879 |
int top_sep = 0; |
|
2880 |
int bottom_sep = 0; |
|
2881 |
||
2882 |
if (centralWidgetItem != 0) { |
|
2883 |
left_sep = docks[QInternal::LeftDock].isEmpty() ? 0 : sep; |
|
2884 |
right_sep = docks[QInternal::RightDock].isEmpty() ? 0 : sep; |
|
2885 |
top_sep = docks[QInternal::TopDock].isEmpty() ? 0 : sep; |
|
2886 |
bottom_sep = docks[QInternal::BottomDock].isEmpty() ? 0 : sep; |
|
2887 |
} |
|
2888 |
||
2889 |
QSize left = docks[QInternal::LeftDock].sizeHint() + QSize(left_sep, 0); |
|
2890 |
QSize right = docks[QInternal::RightDock].sizeHint() + QSize(right_sep, 0); |
|
2891 |
QSize top = docks[QInternal::TopDock].sizeHint() + QSize(0, top_sep); |
|
2892 |
QSize bottom = docks[QInternal::BottomDock].sizeHint() + QSize(0, bottom_sep); |
|
2893 |
QSize center = centralWidgetItem == 0 ? QSize(0, 0) : centralWidgetItem->sizeHint(); |
|
2894 |
||
2895 |
int row1 = top.width(); |
|
2896 |
int row2 = left.width() + center.width() + right.width(); |
|
2897 |
int row3 = bottom.width(); |
|
2898 |
int col1 = left.height(); |
|
2899 |
int col2 = top.height() + center.height() + bottom.height(); |
|
2900 |
int col3 = right.height(); |
|
2901 |
||
2902 |
if (corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea) |
|
2903 |
row1 += left.width(); |
|
2904 |
else |
|
2905 |
col1 += top.height(); |
|
2906 |
||
2907 |
if (corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea) |
|
2908 |
row1 += right.width(); |
|
2909 |
else |
|
2910 |
col3 += top.height(); |
|
2911 |
||
2912 |
if (corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea) |
|
2913 |
row3 += left.width(); |
|
2914 |
else |
|
2915 |
col1 += bottom.height(); |
|
2916 |
||
2917 |
if (corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea) |
|
2918 |
row3 += right.width(); |
|
2919 |
else |
|
2920 |
col3 += bottom.height(); |
|
2921 |
||
2922 |
return QSize(qMax(row1, row2, row3), qMax(col1, col2, col3)); |
|
2923 |
} |
|
2924 |
||
2925 |
QSize QDockAreaLayout::minimumSize() const |
|
2926 |
{ |
|
2927 |
int left_sep = 0; |
|
2928 |
int right_sep = 0; |
|
2929 |
int top_sep = 0; |
|
2930 |
int bottom_sep = 0; |
|
2931 |
||
2932 |
if (centralWidgetItem != 0) { |
|
2933 |
left_sep = docks[QInternal::LeftDock].isEmpty() ? 0 : sep; |
|
2934 |
right_sep = docks[QInternal::RightDock].isEmpty() ? 0 : sep; |
|
2935 |
top_sep = docks[QInternal::TopDock].isEmpty() ? 0 : sep; |
|
2936 |
bottom_sep = docks[QInternal::BottomDock].isEmpty() ? 0 : sep; |
|
2937 |
} |
|
2938 |
||
2939 |
QSize left = docks[QInternal::LeftDock].minimumSize() + QSize(left_sep, 0); |
|
2940 |
QSize right = docks[QInternal::RightDock].minimumSize() + QSize(right_sep, 0); |
|
2941 |
QSize top = docks[QInternal::TopDock].minimumSize() + QSize(0, top_sep); |
|
2942 |
QSize bottom = docks[QInternal::BottomDock].minimumSize() + QSize(0, bottom_sep); |
|
2943 |
QSize center = centralWidgetItem == 0 ? QSize(0, 0) : centralWidgetItem->minimumSize(); |
|
2944 |
||
2945 |
int row1 = top.width(); |
|
2946 |
int row2 = left.width() + center.width() + right.width(); |
|
2947 |
int row3 = bottom.width(); |
|
2948 |
int col1 = left.height(); |
|
2949 |
int col2 = top.height() + center.height() + bottom.height(); |
|
2950 |
int col3 = right.height(); |
|
2951 |
||
2952 |
if (corners[Qt::TopLeftCorner] == Qt::LeftDockWidgetArea) |
|
2953 |
row1 += left.width(); |
|
2954 |
else |
|
2955 |
col1 += top.height(); |
|
2956 |
||
2957 |
if (corners[Qt::TopRightCorner] == Qt::RightDockWidgetArea) |
|
2958 |
row1 += right.width(); |
|
2959 |
else |
|
2960 |
col3 += top.height(); |
|
2961 |
||
2962 |
if (corners[Qt::BottomLeftCorner] == Qt::LeftDockWidgetArea) |
|
2963 |
row3 += left.width(); |
|
2964 |
else |
|
2965 |
col1 += bottom.height(); |
|
2966 |
||
2967 |
if (corners[Qt::BottomRightCorner] == Qt::RightDockWidgetArea) |
|
2968 |
row3 += right.width(); |
|
2969 |
else |
|
2970 |
col3 += bottom.height(); |
|
2971 |
||
2972 |
return QSize(qMax(row1, row2, row3), qMax(col1, col2, col3)); |
|
2973 |
} |
|
2974 |
||
2975 |
bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget) |
|
2976 |
{ |
|
2977 |
QList<int> index = indexOfPlaceHolder(dockWidget->objectName()); |
|
2978 |
if (index.isEmpty()) |
|
2979 |
return false; |
|
2980 |
||
2981 |
QDockAreaLayoutItem &item = this->item(index); |
|
2982 |
QPlaceHolderItem *placeHolder = item.placeHolderItem; |
|
2983 |
Q_ASSERT(placeHolder != 0); |
|
2984 |
||
2985 |
item.widgetItem = new QDockWidgetItem(dockWidget); |
|
2986 |
||
2987 |
if (placeHolder->window) { |
|
2988 |
QDesktopWidget desktop; |
|
2989 |
QRect r = constrainedRect(placeHolder->topLevelRect, desktop.screenGeometry(dockWidget)); |
|
2990 |
dockWidget->d_func()->setWindowState(true, true, r); |
|
2991 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2992 |
dockWidget->setVisible(!placeHolder->hidden); |
0 | 2993 |
#ifdef Q_WS_X11 |
2994 |
if (placeHolder->window) // gets rid of the X11BypassWindowManager window flag |
|
2995 |
dockWidget->d_func()->setWindowState(true); |
|
2996 |
#endif |
|
2997 |
||
2998 |
item.placeHolderItem = 0; |
|
2999 |
delete placeHolder; |
|
3000 |
||
3001 |
return true; |
|
3002 |
} |
|
3003 |
||
3004 |
void QDockAreaLayout::addDockWidget(QInternal::DockPosition pos, QDockWidget *dockWidget, |
|
3005 |
Qt::Orientation orientation) |
|
3006 |
{ |
|
3007 |
QLayoutItem *dockWidgetItem = new QDockWidgetItem(dockWidget); |
|
3008 |
QDockAreaLayoutInfo &info = docks[pos]; |
|
3009 |
if (orientation == info.o || info.item_list.count() <= 1) { |
|
3010 |
// empty dock areas, or dock areas containing exactly one widget can have their orientation |
|
3011 |
// switched. |
|
3012 |
info.o = orientation; |
|
3013 |
||
3014 |
QDockAreaLayoutItem new_item(dockWidgetItem); |
|
3015 |
info.item_list.append(new_item); |
|
3016 |
#ifndef QT_NO_TABBAR |
|
3017 |
if (info.tabbed && !new_item.skip()) { |
|
3018 |
info.updateTabBar(); |
|
3019 |
info.setCurrentTabId(tabId(new_item)); |
|
3020 |
} |
|
3021 |
#endif |
|
3022 |
} else { |
|
3023 |
#ifndef QT_NO_TABBAR |
|
3024 |
int tbshape = info.tabBarShape; |
|
3025 |
#else |
|
3026 |
int tbshape = 0; |
|
3027 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3028 |
QDockAreaLayoutInfo new_info(&sep, pos, orientation, tbshape, mainWindow); |
0 | 3029 |
new_info.item_list.append(new QDockAreaLayoutInfo(info)); |
3030 |
new_info.item_list.append(dockWidgetItem); |
|
3031 |
info = new_info; |
|
3032 |
} |
|
3033 |
||
3034 |
QList<int> index = indexOfPlaceHolder(dockWidget->objectName()); |
|
3035 |
if (!index.isEmpty()) |
|
3036 |
remove(index); |
|
3037 |
} |
|
3038 |
||
3039 |
void QDockAreaLayout::tabifyDockWidget(QDockWidget *first, QDockWidget *second) |
|
3040 |
{ |
|
3041 |
QList<int> path = indexOf(first); |
|
3042 |
if (path.isEmpty()) |
|
3043 |
return; |
|
3044 |
||
3045 |
QDockAreaLayoutInfo *info = this->info(path); |
|
3046 |
Q_ASSERT(info != 0); |
|
3047 |
info->tab(path.last(), new QDockWidgetItem(second)); |
|
3048 |
||
3049 |
QList<int> index = indexOfPlaceHolder(second->objectName()); |
|
3050 |
if (!index.isEmpty()) |
|
3051 |
remove(index); |
|
3052 |
} |
|
3053 |
||
3054 |
void QDockAreaLayout::splitDockWidget(QDockWidget *after, |
|
3055 |
QDockWidget *dockWidget, |
|
3056 |
Qt::Orientation orientation) |
|
3057 |
{ |
|
3058 |
QList<int> path = indexOf(after); |
|
3059 |
if (path.isEmpty()) |
|
3060 |
return; |
|
3061 |
||
3062 |
QDockAreaLayoutInfo *info = this->info(path); |
|
3063 |
Q_ASSERT(info != 0); |
|
3064 |
info->split(path.last(), orientation, new QDockWidgetItem(dockWidget)); |
|
3065 |
||
3066 |
QList<int> index = indexOfPlaceHolder(dockWidget->objectName()); |
|
3067 |
if (!index.isEmpty()) |
|
3068 |
remove(index); |
|
3069 |
} |
|
3070 |
||
3071 |
void QDockAreaLayout::apply(bool animate) |
|
3072 |
{ |
|
3073 |
QWidgetAnimator &widgetAnimator |
|
3074 |
= qobject_cast<QMainWindowLayout*>(mainWindow->layout())->widgetAnimator; |
|
3075 |
||
3076 |
for (int i = 0; i < QInternal::DockCount; ++i) |
|
3077 |
docks[i].apply(animate); |
|
3078 |
if (centralWidgetItem != 0 && !centralWidgetItem->isEmpty()) { |
|
3079 |
widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect, |
|
3080 |
animate); |
|
3081 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3082 |
#ifndef QT_NO_TABBAR |
0 | 3083 |
if (sep == 1) |
3084 |
updateSeparatorWidgets(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3085 |
#endif //QT_NO_TABBAR |
0 | 3086 |
} |
3087 |
||
3088 |
void QDockAreaLayout::paintSeparators(QPainter *p, QWidget *widget, |
|
3089 |
const QRegion &clip, |
|
3090 |
const QPoint &mouse) const |
|
3091 |
{ |
|
3092 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3093 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3094 |
if (dock.isEmpty()) |
|
3095 |
continue; |
|
3096 |
QRect r = separatorRect(i); |
|
3097 |
if (clip.contains(r) && !dock.hasFixedSize()) { |
|
3098 |
Qt::Orientation opposite = dock.o == Qt::Horizontal |
|
3099 |
? Qt::Vertical : Qt::Horizontal; |
|
3100 |
paintSep(p, widget, r, opposite, r.contains(mouse)); |
|
3101 |
} |
|
3102 |
if (clip.contains(dock.rect)) |
|
3103 |
dock.paintSeparators(p, widget, clip, mouse); |
|
3104 |
} |
|
3105 |
} |
|
3106 |
||
3107 |
QRegion QDockAreaLayout::separatorRegion() const |
|
3108 |
{ |
|
3109 |
QRegion result; |
|
3110 |
||
3111 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3112 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3113 |
if (dock.isEmpty()) |
|
3114 |
continue; |
|
3115 |
result |= separatorRect(i); |
|
3116 |
result |= dock.separatorRegion(); |
|
3117 |
} |
|
3118 |
||
3119 |
return result; |
|
3120 |
} |
|
3121 |
||
3122 |
int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &origin, |
|
3123 |
const QPoint &dest) |
|
3124 |
{ |
|
3125 |
int delta = 0; |
|
3126 |
int index = separator.last(); |
|
3127 |
||
3128 |
if (separator.count() > 1) { |
|
3129 |
QDockAreaLayoutInfo *info = this->info(separator); |
|
3130 |
delta = pick(info->o, dest - origin); |
|
3131 |
if (delta != 0) |
|
3132 |
delta = info->separatorMove(index, delta); |
|
3133 |
info->apply(false); |
|
3134 |
return delta; |
|
3135 |
} |
|
3136 |
||
3137 |
QVector<QLayoutStruct> list; |
|
3138 |
||
3139 |
if (index == QInternal::LeftDock || index == QInternal::RightDock) |
|
3140 |
getGrid(0, &list); |
|
3141 |
else |
|
3142 |
getGrid(&list, 0); |
|
3143 |
||
3144 |
int sep_index = index == QInternal::LeftDock || index == QInternal::TopDock |
|
3145 |
? 0 : 1; |
|
3146 |
Qt::Orientation o = index == QInternal::LeftDock || index == QInternal::RightDock |
|
3147 |
? Qt::Horizontal |
|
3148 |
: Qt::Vertical; |
|
3149 |
||
3150 |
delta = pick(o, dest - origin); |
|
3151 |
delta = separatorMoveHelper(list, sep_index, delta, sep); |
|
3152 |
||
3153 |
if (index == QInternal::LeftDock || index == QInternal::RightDock) |
|
3154 |
setGrid(0, &list); |
|
3155 |
else |
|
3156 |
setGrid(&list, 0); |
|
3157 |
||
3158 |
apply(false); |
|
3159 |
||
3160 |
return delta; |
|
3161 |
} |
|
3162 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3163 |
#ifndef QT_NO_TABBAR |
0 | 3164 |
// Sets the correct positions for the seperator widgets |
3165 |
// Allocates new sepearator widgets with getSeparatorWidget |
|
3166 |
void QDockAreaLayout::updateSeparatorWidgets() const |
|
3167 |
{ |
|
3168 |
int j = 0; |
|
3169 |
||
3170 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3171 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3172 |
if (dock.isEmpty()) |
|
3173 |
continue; |
|
3174 |
||
3175 |
QWidget *sepWidget; |
|
3176 |
if (j < separatorWidgets.size()) { |
|
3177 |
sepWidget = separatorWidgets.at(j); |
|
3178 |
} else { |
|
3179 |
sepWidget = qobject_cast<QMainWindowLayout*>(mainWindow->layout())->getSeparatorWidget(); |
|
3180 |
separatorWidgets.append(sepWidget); |
|
3181 |
} |
|
3182 |
j++; |
|
3183 |
||
3184 |
#ifndef QT_MAC_USE_COCOA |
|
3185 |
sepWidget->raise(); |
|
3186 |
#endif |
|
3187 |
QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2); |
|
3188 |
sepWidget->setGeometry(sepRect); |
|
3189 |
sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft()))); |
|
3190 |
sepWidget->show(); |
|
3191 |
} |
|
3192 |
for (int i = j; i < separatorWidgets.size(); ++i) |
|
3193 |
separatorWidgets.at(i)->hide(); |
|
3194 |
||
3195 |
separatorWidgets.resize(j); |
|
3196 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3197 |
#endif //QT_NO_TABBAR |
0 | 3198 |
|
3199 |
QLayoutItem *QDockAreaLayout::itemAt(int *x, int index) const |
|
3200 |
{ |
|
3201 |
Q_ASSERT(x != 0); |
|
3202 |
||
3203 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3204 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3205 |
if (QLayoutItem *ret = dock.itemAt(x, index)) |
|
3206 |
return ret; |
|
3207 |
} |
|
3208 |
||
3209 |
if (centralWidgetItem && (*x)++ == index) |
|
3210 |
return centralWidgetItem; |
|
3211 |
||
3212 |
return 0; |
|
3213 |
} |
|
3214 |
||
3215 |
QLayoutItem *QDockAreaLayout::takeAt(int *x, int index) |
|
3216 |
{ |
|
3217 |
Q_ASSERT(x != 0); |
|
3218 |
||
3219 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3220 |
QDockAreaLayoutInfo &dock = docks[i]; |
|
3221 |
if (QLayoutItem *ret = dock.takeAt(x, index)) |
|
3222 |
return ret; |
|
3223 |
} |
|
3224 |
||
3225 |
if (centralWidgetItem && (*x)++ == index) { |
|
3226 |
QLayoutItem *ret = centralWidgetItem; |
|
3227 |
centralWidgetItem = 0; |
|
3228 |
return ret; |
|
3229 |
} |
|
3230 |
||
3231 |
return 0; |
|
3232 |
} |
|
3233 |
||
3234 |
void QDockAreaLayout::deleteAllLayoutItems() |
|
3235 |
{ |
|
3236 |
for (int i = 0; i < QInternal::DockCount; ++i) |
|
3237 |
docks[i].deleteAllLayoutItems(); |
|
3238 |
} |
|
3239 |
||
3240 |
#ifndef QT_NO_TABBAR |
|
3241 |
QSet<QTabBar*> QDockAreaLayout::usedTabBars() const |
|
3242 |
{ |
|
3243 |
QSet<QTabBar*> result; |
|
3244 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3245 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3246 |
result += dock.usedTabBars(); |
|
3247 |
} |
|
3248 |
return result; |
|
3249 |
} |
|
3250 |
||
3251 |
// Returns the set of all used separator widgets |
|
3252 |
QSet<QWidget*> QDockAreaLayout::usedSeparatorWidgets() const |
|
3253 |
{ |
|
3254 |
QSet<QWidget*> result; |
|
3255 |
||
3256 |
for (int i = 0; i < separatorWidgets.count(); ++i) |
|
3257 |
result << separatorWidgets.at(i); |
|
3258 |
for (int i = 0; i < QInternal::DockCount; ++i) { |
|
3259 |
const QDockAreaLayoutInfo &dock = docks[i]; |
|
3260 |
result += dock.usedSeparatorWidgets(); |
|
3261 |
} |
|
3262 |
return result; |
|
3263 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3264 |
#endif |
0 | 3265 |
|
3266 |
QRect QDockAreaLayout::gapRect(const QList<int> &path) const |
|
3267 |
{ |
|
3268 |
const QDockAreaLayoutInfo *info = this->info(path); |
|
3269 |
if (info == 0) |
|
3270 |
return QRect(); |
|
3271 |
const QList<QDockAreaLayoutItem> &item_list = info->item_list; |
|
3272 |
Qt::Orientation o = info->o; |
|
3273 |
int index = path.last(); |
|
3274 |
if (index < 0 || index >= item_list.count()) |
|
3275 |
return QRect(); |
|
3276 |
const QDockAreaLayoutItem &item = item_list.at(index); |
|
3277 |
if (!(item.flags & QDockAreaLayoutItem::GapItem)) |
|
3278 |
return QRect(); |
|
3279 |
||
3280 |
QRect result; |
|
3281 |
||
3282 |
#ifndef QT_NO_TABBAR |
|
3283 |
if (info->tabbed) { |
|
3284 |
result = info->tabContentRect(); |
|
3285 |
} else |
|
3286 |
#endif |
|
3287 |
{ |
|
3288 |
int pos = item.pos; |
|
3289 |
int size = item.size; |
|
3290 |
||
3291 |
int prev = info->prev(index); |
|
3292 |
int next = info->next(index); |
|
3293 |
||
3294 |
if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { |
|
3295 |
pos += sep; |
|
3296 |
size -= sep; |
|
3297 |
} |
|
3298 |
if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) |
|
3299 |
size -= sep; |
|
3300 |
||
3301 |
QPoint p; |
|
3302 |
rpick(o, p) = pos; |
|
3303 |
rperp(o, p) = perp(o, info->rect.topLeft()); |
|
3304 |
QSize s; |
|
3305 |
rpick(o, s) = size; |
|
3306 |
rperp(o, s) = perp(o, info->rect.size()); |
|
3307 |
||
3308 |
result = QRect(p, s); |
|
3309 |
} |
|
3310 |
||
3311 |
return result; |
|
3312 |
} |
|
3313 |
||
3314 |
void QDockAreaLayout::keepSize(QDockWidget *w) |
|
3315 |
{ |
|
3316 |
QList<int> path = indexOf(w); |
|
3317 |
if (path.isEmpty()) |
|
3318 |
return; |
|
3319 |
QDockAreaLayoutItem &item = this->item(path); |
|
3320 |
if (item.size != -1) |
|
3321 |
item.flags |= QDockAreaLayoutItem::KeepSize; |
|
3322 |
} |
|
3323 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3324 |
void QDockAreaLayout::styleChangedEvent() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3325 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3326 |
sep = mainWindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainWindow); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3327 |
fitLayout(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3328 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3329 |
|
0 | 3330 |
QT_END_NAMESPACE |
3331 |
||
3332 |
#endif // QT_NO_DOCKWIDGET |