qtoolbararealayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtoolbararealayout.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <QWidgetItem>-
41#include <QToolBar>-
42#include <QStyleOption>-
43#include <QApplication>-
44#include <qdebug.h>-
45-
46#include "qtoolbararealayout_p.h"-
47#include "qmainwindowlayout_p.h"-
48#include "qwidgetanimator_p.h"-
49#include "qtoolbarlayout_p.h"-
50#include "qtoolbar_p.h"-
51-
52/******************************************************************************-
53** QToolBarAreaLayoutItem-
54*/-
55-
56#ifndef QT_NO_TOOLBAR-
57-
58QT_BEGIN_NAMESPACE-
59-
60// qmainwindow.cpp-
61extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow);-
62-
63QSize QToolBarAreaLayoutItem::minimumSize() const-
64{-
65 if (skip())-
66 return QSize(0, 0);-
67 return qSmartMinSize(static_cast<QWidgetItem*>(widgetItem));-
68}-
69-
70QSize QToolBarAreaLayoutItem::sizeHint() const-
71{-
72 if (skip())-
73 return QSize(0, 0);-
74-
75 return realSizeHint();-
76}-
77-
78//returns the real size hint not taking into account the visibility of the widget-
79QSize QToolBarAreaLayoutItem::realSizeHint() const-
80{-
81 QWidget *wid = widgetItem->widget();-
82 QSize s = wid->sizeHint().expandedTo(wid->minimumSizeHint());-
83 if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)-
84 s.setWidth(0);-
85 if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)-
86 s.setHeight(0);-
87 s = s.boundedTo(wid->maximumSize())-
88 .expandedTo(wid->minimumSize());-
89 return s;-
90}-
91-
92bool QToolBarAreaLayoutItem::skip() const-
93{-
94 if (gap)-
95 return false;-
96 return widgetItem == 0 || widgetItem->isEmpty();-
97}-
98-
99/******************************************************************************-
100** QToolBarAreaLayoutLine-
101*/-
102-
103QToolBarAreaLayoutLine::QToolBarAreaLayoutLine(Qt::Orientation orientation)-
104 : o(orientation)-
105{-
106}-
107-
108QSize QToolBarAreaLayoutLine::sizeHint() const-
109{-
110 int a = 0, b = 0;-
111 for (int i = 0; i < toolBarItems.count(); ++i) {-
112 const QToolBarAreaLayoutItem &item = toolBarItems.at(i);-
113 if (item.skip())-
114 continue;-
115-
116 QSize sh = item.sizeHint();-
117 a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh);-
118 b = qMax(b, perp(o, sh));-
119 }-
120-
121 QSize result;-
122 rpick(o, result) = a;-
123 rperp(o, result) = b;-
124-
125 return result;-
126}-
127-
128QSize QToolBarAreaLayoutLine::minimumSize() const-
129{-
130 int a = 0, b = 0;-
131 for (int i = 0; i < toolBarItems.count(); ++i) {-
132 const QToolBarAreaLayoutItem &item = toolBarItems[i];-
133 if (item.skip())-
134 continue;-
135-
136 QSize ms = item.minimumSize();-
137 a += pick(o, ms);-
138 b = qMax(b, perp(o, ms));-
139 }-
140-
141 QSize result;-
142 rpick(o, result) = a;-
143 rperp(o, result) = b;-
144-
145 return result;-
146}-
147-
148void QToolBarAreaLayoutLine::fitLayout()-
149{-
150 int last = -1;-
151 int min = pick(o, minimumSize());-
152 int space = pick(o, rect.size());-
153 int extra = qMax(0, space - min);-
154-
155 for (int i = 0; i < toolBarItems.count(); ++i) {-
156 QToolBarAreaLayoutItem &item = toolBarItems[i];-
157 if (item.skip())-
158 continue;-
159-
160 if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout()))-
161 tblayout->checkUsePopupMenu();-
162-
163 const int itemMin = pick(o, item.minimumSize());-
164 //preferredSize is the default if it is set, otherwise, we take the sizehint-
165 item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint());-
166-
167 //the extraspace is the space above the item minimum sizehint-
168 const int extraSpace = qMin(item.size - itemMin, extra);-
169 item.size = itemMin + extraSpace; //that is the real size-
170-
171 extra -= extraSpace;-
172-
173 last = i;-
174 }-
175-
176 // calculate the positions from the sizes-
177 int pos = 0;-
178 for (int i = 0; i < toolBarItems.count(); ++i) {-
179 QToolBarAreaLayoutItem &item = toolBarItems[i];-
180 if (item.skip())-
181 continue;-
182-
183 item.pos = pos;-
184 if (i == last) // stretch the last item to the end of the line-
185 item.size = qMax(0, pick(o, rect.size()) - item.pos);-
186 pos += item.size;-
187 }-
188}-
189-
190bool QToolBarAreaLayoutLine::skip() const-
191{-
192 for (int i = 0; i < toolBarItems.count(); ++i) {-
193 if (!toolBarItems.at(i).skip())-
194 return false;-
195 }-
196 return true;-
197}-
198-
199/******************************************************************************-
200** QToolBarAreaLayoutInfo-
201*/-
202-
203QToolBarAreaLayoutInfo::QToolBarAreaLayoutInfo(QInternal::DockPosition pos)-
204 : dockPos(pos), dirty(false)-
205{-
206 switch (pos) {-
207 case QInternal::LeftDock:-
208 case QInternal::RightDock:-
209 o = Qt::Vertical;-
210 break;-
211 case QInternal::TopDock:-
212 case QInternal::BottomDock:-
213 o = Qt::Horizontal;-
214 break;-
215 default:-
216 o = Qt::Horizontal;-
217 break;-
218 }-
219}-
220-
221QSize QToolBarAreaLayoutInfo::sizeHint() const-
222{-
223 int a = 0, b = 0;-
224 for (int i = 0; i < lines.count(); ++i) {-
225 const QToolBarAreaLayoutLine &l = lines.at(i);-
226 if (l.skip())-
227 continue;-
228-
229 QSize hint = l.sizeHint();-
230 a = qMax(a, pick(o, hint));-
231 b += perp(o, hint);-
232 }-
233-
234 QSize result;-
235 rpick(o, result) = a;-
236 rperp(o, result) = b;-
237-
238 return result;-
239}-
240-
241QSize QToolBarAreaLayoutInfo::minimumSize() const-
242{-
243 int a = 0, b = 0;-
244 for (int i = 0; i < lines.count(); ++i) {-
245 const QToolBarAreaLayoutLine &l = lines.at(i);-
246 if (l.skip())-
247 continue;-
248-
249 QSize m = l.minimumSize();-
250 a = qMax(a, pick(o, m));-
251 b += perp(o, m);-
252 }-
253-
254 QSize result;-
255 rpick(o, result) = a;-
256 rperp(o, result) = b;-
257-
258 return result;-
259}-
260-
261void QToolBarAreaLayoutInfo::fitLayout()-
262{-
263 dirty = false;-
264-
265 int b = 0;-
266-
267 bool reverse = dockPos == QInternal::RightDock || dockPos == QInternal::BottomDock;-
268-
269 int i = reverse ? lines.count() - 1 : 0;-
270 for (;;) {-
271 if ((reverse && i < 0) || (!reverse && i == lines.count()))-
272 break;-
273-
274 QToolBarAreaLayoutLine &l = lines[i];-
275 if (!l.skip()) {-
276 if (o == Qt::Horizontal) {-
277 l.rect.setLeft(rect.left());-
278 l.rect.setRight(rect.right());-
279 l.rect.setTop(b + rect.top());-
280 b += l.sizeHint().height();-
281 l.rect.setBottom(b - 1 + rect.top());-
282 } else {-
283 l.rect.setTop(rect.top());-
284 l.rect.setBottom(rect.bottom());-
285 l.rect.setLeft(b + rect.left());-
286 b += l.sizeHint().width();-
287 l.rect.setRight(b - 1 + rect.left());-
288 }-
289-
290 l.fitLayout();-
291 }-
292-
293 i += reverse ? -1 : 1;-
294 }-
295}-
296-
297QLayoutItem *QToolBarAreaLayoutInfo::insertToolBar(QToolBar *before, QToolBar *toolBar)-
298{-
299 toolBar->setOrientation(o);-
300 QLayoutItem *item = new QWidgetItemV2(toolBar);-
301 insertItem(before, item);-
302 return item;-
303}-
304-
305void QToolBarAreaLayoutInfo::insertItem(QToolBar *before, QLayoutItem *item)-
306{-
307 if (before == 0) {-
308 if (lines.isEmpty())-
309 lines.append(QToolBarAreaLayoutLine(o));-
310 lines.last().toolBarItems.append(item);-
311 return;-
312 }-
313-
314 for (int j = 0; j < lines.count(); ++j) {-
315 QToolBarAreaLayoutLine &line = lines[j];-
316-
317 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
318 if (line.toolBarItems.at(k).widgetItem->widget() == before) {-
319 line.toolBarItems.insert(k, item);-
320 return;-
321 }-
322 }-
323 }-
324}-
325-
326void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar)-
327{-
328 for (int j = 0; j < lines.count(); ++j) {-
329 QToolBarAreaLayoutLine &line = lines[j];-
330-
331 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
332 QToolBarAreaLayoutItem &item = line.toolBarItems[k];-
333 if (item.widgetItem->widget() == toolBar) {-
334 delete item.widgetItem;-
335 item.widgetItem = 0;-
336 line.toolBarItems.removeAt(k);-
337-
338 if (line.toolBarItems.isEmpty() && j < lines.count() - 1)-
339 lines.removeAt(j);-
340-
341 return;-
342 }-
343 }-
344 }-
345}-
346-
347void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before)-
348{-
349 if (before == 0) {
before == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
350 if (!lines.isEmpty() && lines.lastconstLast().toolBarItems.isEmpty())
!lines.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
lines.constLas...tems.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
351 return;
never executed: return;
0
352 lines.append(QToolBarAreaLayoutLine(o));-
353 return;
never executed: return;
0
354 }-
355-
356 for (int j = 0; j < lines.count(); ++j) {
j < lines.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
357 QToolBarAreaLayoutLine &line = lines[j];-
358-
359 for (int k = 0; k < line.toolBarItems.count(); ++k) {
k < line.toolBarItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
360 if (line.toolBarItems.at(k).widgetItem->widget() == before) {
line.toolBarIt...et() == beforeDescription
TRUEnever evaluated
FALSEnever evaluated
0
361 if (k == 0)
k == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
362 return;
never executed: return;
0
363-
364 QToolBarAreaLayoutLine newLine(o);-
365 newLine.toolBarItems = line.toolBarItems.mid(k);-
366 line.toolBarItems = line.toolBarItems.mid(0, k);-
367 lines.insert(j + 1, newLine);-
368-
369 return;
never executed: return;
0
370 }-
371 }
never executed: end of block
0
372 }
never executed: end of block
0
373}
never executed: end of block
0
374-
375void QToolBarAreaLayoutInfo::removeToolBarBreak(QToolBar *before)-
376{-
377 for (int j = 0; j < lines.count(); ++j) {-
378 const QToolBarAreaLayoutLine &line = lines.at(j);-
379-
380 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
381 if (line.toolBarItems.at(k).widgetItem->widget() == before) {-
382 if (k != 0)-
383 return;-
384 if (j == 0)-
385 return;-
386-
387 lines[j - 1].toolBarItems += lines[j].toolBarItems;-
388 lines.removeAt(j);-
389-
390 return;-
391 }-
392 }-
393 }-
394}-
395-
396void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos)-
397{-
398 if (dirty)-
399 fitLayout();-
400-
401 dirty = true;-
402-
403 if (o == Qt::Vertical)-
404 pos -= rect.top();-
405-
406 //here we actually update the preferredSize for the line containing the toolbar so that we move it-
407 for (int j = 0; j < lines.count(); ++j) {-
408 QToolBarAreaLayoutLine &line = lines[j];-
409-
410 int previousIndex = -1;-
411 int minPos = 0;-
412 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
413 QToolBarAreaLayoutItem &current = line.toolBarItems[k];-
414 if (current.widgetItem->widget() == toolbar) {-
415 int newPos = current.pos;-
416-
417 if (previousIndex >= 0) {-
418 QToolBarAreaLayoutItem &previous = line.toolBarItems[previousIndex];-
419 if (pos < current.pos) {-
420 newPos = qMax(pos, minPos);-
421 } else {-
422 //we check the max value for the position (until everything at the right is "compressed")-
423 int maxPos = pick(o, rect.size());-
424 for(int l = k; l < line.toolBarItems.count(); ++l) {-
425 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(l);-
426 if (!item.skip()) {-
427 maxPos -= pick(o, item.minimumSize());-
428 }-
429 }-
430 newPos = qMin(pos, maxPos);-
431 }-
432-
433 //extra is the number of pixels to add to the previous toolbar-
434 int extra = newPos - current.pos;-
435-
436 //we check if the previous is near its size hint-
437 //in which case we try to stick to it-
438 const int diff = pick(o, previous.sizeHint()) - (previous.size + extra);-
439 if (qAbs(diff) < QApplication::startDragDistance()) {-
440 //we stick to the default place and size-
441 extra += diff;-
442 }-
443-
444 //update for the current item-
445 current.extendSize(line.o, -extra);-
446-
447 if (extra >= 0) {-
448 previous.extendSize(line.o, extra);-
449 } else {-
450 //we need to push the toolbars on the left starting with previous-
451 extra = -extra; // we just need to know the number of pixels-
452 ///at this point we need to get extra pixels from the toolbars at the left-
453 for(int l = previousIndex; l >=0; --l) {-
454 QToolBarAreaLayoutItem &item = line.toolBarItems[l];-
455 if (!item.skip()) {-
456 const int minPreferredSize = pick(o, item.minimumSize());-
457 const int margin = item.size - minPreferredSize;-
458 if (margin < extra) {-
459 item.resize(line.o, minPreferredSize);-
460 extra -= margin;-
461 } else {-
462 item.extendSize(line.o, -extra);-
463 extra = 0;-
464 }-
465 }-
466 }-
467 Q_ASSERT(extra == 0);-
468 }-
469 } else {-
470 //the item is the first one, it should be at position 0-
471 }-
472-
473 return;-
474-
475 } else if (!current.skip()) {-
476 previousIndex = k;-
477 minPos += pick(o, current.minimumSize());-
478 }-
479 }-
480 }-
481}-
482-
483-
484QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const-
485{-
486 if (rect.contains(pos)) {-
487 // <pos> is in QToolBarAreaLayout coordinates.-
488 // <item.pos> is in local dockarea coordinates (see ~20 lines below)-
489 // Since we're comparing p with item.pos, we put them in the same coordinate system.-
490 const int p = pick(o, pos - rect.topLeft());-
491-
492 for (int j = 0; j < lines.count(); ++j) {-
493 const QToolBarAreaLayoutLine &line = lines.at(j);-
494 if (line.skip())-
495 continue;-
496 if (!line.rect.contains(pos))-
497 continue;-
498-
499 int k = 0;-
500 for (; k < line.toolBarItems.count(); ++k) {-
501 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);-
502 if (item.skip())-
503 continue;-
504-
505 int size = qMin(item.size, pick(o, item.sizeHint()));-
506-
507 if (p > item.pos + size)-
508 continue;-
509 if (p > item.pos + size/2)-
510 ++k;-
511 break;-
512 }-
513-
514 QList<int> result;-
515 result << j << k;-
516 *minDistance = 0; //we found a perfect match-
517 return result;-
518 }-
519 } else {-
520 const int dist = distance(pos);-
521 //it will only return a path if the minDistance is higher than the current distance-
522 if (dist >= 0 && *minDistance > dist) {-
523 *minDistance = dist;-
524-
525 QList<int> result;-
526 result << lines.count() << 0;-
527 return result;-
528 }-
529 }-
530-
531 return QList<int>();-
532}-
533-
534bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item)-
535{-
536 Q_ASSERT(path.count() == 2);-
537 int j = path.first();-
538 if (j == lines.count())-
539 lines.append(QToolBarAreaLayoutLine(o));-
540-
541 QToolBarAreaLayoutLine &line = lines[j];-
542 const int k = path.at(1);-
543-
544 QToolBarAreaLayoutItem gap_item;-
545 gap_item.gap = true;-
546 gap_item.widgetItem = item;-
547-
548 //update the previous item's preferred size-
549 for(int p = k - 1 ; p >= 0; --p) {-
550 QToolBarAreaLayoutItem &previous = line.toolBarItems[p];-
551 if (!previous.skip()) {-
552 //we found the previous one-
553 int previousSizeHint = pick(line.o, previous.sizeHint());-
554 int previousExtraSpace = previous.size - previousSizeHint;-
555-
556 if (previousExtraSpace > 0) {-
557 //in this case we reset the space-
558 previous.preferredSize = -1;-
559 previous.size = previousSizeHint;-
560-
561 gap_item.resize(o, previousExtraSpace);-
562 }-
563-
564 break;-
565 }-
566 }-
567-
568 line.toolBarItems.insert(k, gap_item);-
569 return true;-
570-
571}-
572-
573void QToolBarAreaLayoutInfo::clear()-
574{-
575 lines.clear();-
576 rect = QRect();-
577}-
578-
579QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const-
580{-
581 Q_ASSERT(path.count() == 2);-
582 int j = path.at(0);-
583 int k = path.at(1);-
584-
585 const QToolBarAreaLayoutLine &line = lines.at(j);-
586 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);-
587-
588 QRect result = line.rect;-
589-
590 if (o == Qt::Horizontal) {-
591 result.setLeft(item.pos + line.rect.left());-
592 result.setWidth(item.size);-
593 } else {-
594 result.setTop(item.pos + line.rect.top());-
595 result.setHeight(item.size);-
596 }-
597-
598 return result;-
599}-
600-
601int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const-
602{-
603 switch (dockPos) {-
604 case QInternal::LeftDock:-
605 if (pos.y() < rect.bottom())-
606 return pos.x() - rect.right();-
607 break;-
608 case QInternal::RightDock:-
609 if (pos.y() < rect.bottom())-
610 return rect.left() - pos.x();-
611 break;-
612 case QInternal::TopDock:-
613 if (pos.x() < rect.right())-
614 return pos.y() - rect.bottom();-
615 break;-
616 case QInternal::BottomDock:-
617 if (pos.x() < rect.right())-
618 return rect.top() - pos.y();-
619 break;-
620-
621 case QInternal::DockCount:-
622 break;-
623 }-
624 return -1;-
625}-
626-
627/******************************************************************************-
628** QToolBarAreaLayout-
629*/-
630-
631QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true)-
632{-
633 for (int i = 0; i < QInternal::DockCount; ++i) {-
634 QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i);-
635 docks[i] = QToolBarAreaLayoutInfo(pos);-
636 }-
637}-
638-
639QRect QToolBarAreaLayout::fitLayout()-
640{-
641 if (!visible)-
642 return rect;-
643-
644 QSize left_hint = docks[QInternal::LeftDock].sizeHint();-
645 QSize right_hint = docks[QInternal::RightDock].sizeHint();-
646 QSize top_hint = docks[QInternal::TopDock].sizeHint();-
647 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();-
648-
649 QRect center = rect.adjusted(left_hint.width(), top_hint.height(),-
650 -right_hint.width(), -bottom_hint.height());-
651-
652 docks[QInternal::TopDock].rect = QRect(rect.left(), rect.top(),-
653 rect.width(), top_hint.height());-
654 docks[QInternal::LeftDock].rect = QRect(rect.left(), center.top(),-
655 left_hint.width(), center.height());-
656 docks[QInternal::RightDock].rect = QRect(center.right() + 1, center.top(),-
657 right_hint.width(), center.height());-
658 docks[QInternal::BottomDock].rect = QRect(rect.left(), center.bottom() + 1,-
659 rect.width(), bottom_hint.height());-
660-
661 docks[QInternal::TopDock].fitLayout();-
662 docks[QInternal::LeftDock].fitLayout();-
663 docks[QInternal::RightDock].fitLayout();-
664 docks[QInternal::BottomDock].fitLayout();-
665-
666 return center;-
667}-
668-
669QSize QToolBarAreaLayout::minimumSize(const QSize &centerMin) const-
670{-
671 if (!visible)-
672 return centerMin;-
673-
674 QSize result = centerMin;-
675-
676 QSize left_min = docks[QInternal::LeftDock].minimumSize();-
677 QSize right_min = docks[QInternal::RightDock].minimumSize();-
678 QSize top_min = docks[QInternal::TopDock].minimumSize();-
679 QSize bottom_min = docks[QInternal::BottomDock].minimumSize();-
680-
681 result.setWidth(qMax(top_min.width(), result.width()));-
682 result.setWidth(qMax(bottom_min.width(), result.width()));-
683 result.setHeight(qMax(left_min.height(), result.height()));-
684 result.setHeight(qMax(right_min.height(), result.height()));-
685-
686 result.rwidth() += left_min.width() + right_min.width();-
687 result.rheight() += top_min.height() + bottom_min.height();-
688-
689 return result;-
690}-
691-
692QSize QToolBarAreaLayout::sizeHint(const QSize &centerHint) const-
693{-
694 if (!visible)-
695 return centerHint;-
696-
697 QSize result = centerHint;-
698-
699 QSize left_hint = docks[QInternal::LeftDock].sizeHint();-
700 QSize right_hint = docks[QInternal::RightDock].sizeHint();-
701 QSize top_hint = docks[QInternal::TopDock].sizeHint();-
702 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();-
703-
704 result.setWidth(qMax(top_hint.width(), result.width()));-
705 result.setWidth(qMax(bottom_hint.width(), result.width()));-
706 result.setHeight(qMax(left_hint.height(), result.height()));-
707 result.setHeight(qMax(right_hint.height(), result.height()));-
708-
709 result.rwidth() += left_hint.width() + right_hint.width();-
710 result.rheight() += top_hint.height() + bottom_hint.height();-
711-
712 return result;-
713}-
714-
715QRect QToolBarAreaLayout::rectHint(const QRect &r) const-
716{-
717 int coef = visible ? 1 : -1;-
718-
719 QRect result = r;-
720-
721 QSize left_hint = docks[QInternal::LeftDock].sizeHint();-
722 QSize right_hint = docks[QInternal::RightDock].sizeHint();-
723 QSize top_hint = docks[QInternal::TopDock].sizeHint();-
724 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();-
725-
726 result.adjust(-left_hint.width()*coef, -top_hint.height()*coef,-
727 right_hint.width()*coef, bottom_hint.height()*coef);-
728-
729 return result;-
730}-
731-
732QLayoutItem *QToolBarAreaLayout::itemAt(int *x, int index) const-
733{-
734 Q_ASSERT(x != 0);-
735-
736 for (int i = 0; i < QInternal::DockCount; ++i) {-
737 const QToolBarAreaLayoutInfo &dock = docks[i];-
738-
739 for (int j = 0; j < dock.lines.count(); ++j) {-
740 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
741-
742 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
743 if ((*x)++ == index)-
744 return line.toolBarItems.at(k).widgetItem;-
745 }-
746 }-
747 }-
748-
749 return 0;-
750}-
751-
752QLayoutItem *QToolBarAreaLayout::takeAt(int *x, int index)-
753{-
754 Q_ASSERT(x != 0);-
755-
756 for (int i = 0; i < QInternal::DockCount; ++i) {-
757 QToolBarAreaLayoutInfo &dock = docks[i];-
758-
759 for (int j = 0; j < dock.lines.count(); ++j) {-
760 QToolBarAreaLayoutLine &line = dock.lines[j];-
761-
762 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
763 if ((*x)++ == index) {-
764 QLayoutItem *result = line.toolBarItems.takeAt(k).widgetItem;-
765 if (line.toolBarItems.isEmpty())-
766 dock.lines.removeAt(j);-
767 return result;-
768 }-
769 }-
770 }-
771 }-
772-
773 return 0;-
774}-
775-
776void QToolBarAreaLayout::deleteAllLayoutItems()-
777{-
778 for (int i = 0; i < QInternal::DockCount; ++i) {-
779 QToolBarAreaLayoutInfo &dock = docks[i];-
780-
781 for (int j = 0; j < dock.lines.count(); ++j) {-
782 QToolBarAreaLayoutLine &line = dock.lines[j];-
783-
784 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
785 QToolBarAreaLayoutItem &item = line.toolBarItems[k];-
786 if (!item.gap)-
787 delete item.widgetItem;-
788 item.widgetItem = 0;-
789 }-
790 }-
791 }-
792}-
793-
794QInternal::DockPosition QToolBarAreaLayout::findToolBar(QToolBar *toolBar) const-
795{-
796 for (int i = 0; i < QInternal::DockCount; ++i) {-
797 const QToolBarAreaLayoutInfo &dock = docks[i];-
798-
799 for (int j = 0; j < dock.lines.count(); ++j) {-
800 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
801-
802 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
803 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)-
804 return static_cast<QInternal::DockPosition>(i);-
805 }-
806 }-
807 }-
808-
809 return QInternal::DockCount;-
810}-
811-
812QLayoutItem *QToolBarAreaLayout::insertToolBar(QToolBar *before, QToolBar *toolBar)-
813{-
814 QInternal::DockPosition pos = findToolBar(before);-
815 if (pos == QInternal::DockCount)-
816 return 0;-
817-
818 return docks[pos].insertToolBar(before, toolBar);-
819}-
820-
821void QToolBarAreaLayout::removeToolBar(QToolBar *toolBar)-
822{-
823 QInternal::DockPosition pos = findToolBar(toolBar);-
824 if (pos == QInternal::DockCount)-
825 return;-
826 docks[pos].removeToolBar(toolBar);-
827}-
828-
829QLayoutItem *QToolBarAreaLayout::addToolBar(QInternal::DockPosition pos, QToolBar *toolBar)-
830{-
831 return docks[pos].insertToolBar(0, toolBar);-
832}-
833-
834void QToolBarAreaLayout::insertToolBarBreak(QToolBar *before)-
835{-
836 QInternal::DockPosition pos = findToolBar(before);-
837 if (pos == QInternal::DockCount)-
838 return;-
839 docks[pos].insertToolBarBreak(before);-
840}-
841-
842void QToolBarAreaLayout::removeToolBarBreak(QToolBar *before)-
843{-
844 QInternal::DockPosition pos = findToolBar(before);-
845 if (pos == QInternal::DockCount)-
846 return;-
847 docks[pos].removeToolBarBreak(before);-
848}-
849-
850void QToolBarAreaLayout::addToolBarBreak(QInternal::DockPosition pos)-
851{-
852 docks[pos].insertToolBarBreak(0);-
853}-
854-
855void QToolBarAreaLayout::moveToolBar(QToolBar *toolbar, int p)-
856{-
857 QInternal::DockPosition pos = findToolBar(toolbar);-
858 if (pos == QInternal::DockCount)-
859 return;-
860 docks[pos].moveToolBar(toolbar, p);-
861}-
862-
863-
864void QToolBarAreaLayout::insertItem(QInternal::DockPosition pos, QLayoutItem *item)-
865{-
866 if (docks[pos].lines.isEmpty())-
867 docks[pos].lines.append(QToolBarAreaLayoutLine(docks[pos].o));-
868 docks[pos].lines.last().toolBarItems.append(item);-
869}-
870-
871void QToolBarAreaLayout::insertItem(QToolBar *before, QLayoutItem *item)-
872{-
873 QInternal::DockPosition pos = findToolBar(before);-
874 if (pos == QInternal::DockCount)-
875 return;-
876-
877 docks[pos].insertItem(before, item);-
878}-
879-
880void QToolBarAreaLayout::apply(bool animate)-
881{-
882 QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow);-
883 Q_ASSERT(layout != 0);-
884-
885 Qt::LayoutDirection dir = mainWindow->layoutDirection();-
886-
887 for (int i = 0; i < QInternal::DockCount; ++i) {-
888 const QToolBarAreaLayoutInfo &dock = docks[i];-
889-
890 for (int j = 0; j < dock.lines.count(); ++j) {-
891 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
892 if (line.skip())-
893 continue;-
894-
895 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
896 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);-
897 if (item.skip() || item.gap)-
898 continue;-
899-
900 QRect geo;-
901 if (visible) {-
902 if (line.o == Qt::Horizontal) {-
903 geo.setTop(line.rect.top());-
904 geo.setBottom(line.rect.bottom());-
905 geo.setLeft(line.rect.left() + item.pos);-
906 geo.setRight(line.rect.left() + item.pos + item.size - 1);-
907 } else {-
908 geo.setLeft(line.rect.left());-
909 geo.setRight(line.rect.right());-
910 geo.setTop(line.rect.top() + item.pos);-
911 geo.setBottom(line.rect.top() + item.pos + item.size - 1);-
912 }-
913 }-
914-
915 QWidget *widget = item.widgetItem->widget();-
916 if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {-
917 QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(toolBar->layout());-
918 if (tbl->expanded) {-
919 QPoint tr = geo.topRight();-
920 QSize size = tbl->expandedSize(geo.size());-
921 geo.setSize(size);-
922 geo.moveTopRight(tr);-
923 if (geo.bottom() > rect.bottom())-
924 geo.moveBottom(rect.bottom());-
925 if (geo.right() > rect.right())-
926 geo.moveRight(rect.right());-
927 if (geo.left() < 0)-
928 geo.moveLeft(0);-
929 if (geo.top() < 0)-
930 geo.moveTop(0);-
931 }-
932 }-
933-
934 if (visible && dock.o == Qt::Horizontal)-
935 geo = QStyle::visualRect(dir, line.rect, geo);-
936-
937 layout->widgetAnimator.animate(widget, geo, animate);-
938 }-
939 }-
940 }-
941}-
942-
943bool QToolBarAreaLayout::toolBarBreak(QToolBar *toolBar) const-
944{-
945 for (int i = 0; i < QInternal::DockCount; ++i) {-
946 const QToolBarAreaLayoutInfo &dock = docks[i];-
947-
948 for (int j = 0; j < dock.lines.count(); ++j) {-
949 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
950-
951 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
952 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)-
953 return j > 0 && k == 0;-
954 }-
955 }-
956 }-
957-
958 return false;-
959}-
960-
961void QToolBarAreaLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const-
962{-
963 for (int i = 0; i < QInternal::DockCount; ++i) {-
964 const QToolBarAreaLayoutInfo &dock = docks[i];-
965-
966 for (int j = 0; j < dock.lines.count(); ++j) {-
967 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
968-
969 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
970 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) {-
971 if (line.toolBarItems.count() == 1)-
972 option->positionWithinLine = QStyleOptionToolBar::OnlyOne;-
973 else if (k == 0)-
974 option->positionWithinLine = QStyleOptionToolBar::Beginning;-
975 else if (k == line.toolBarItems.count() - 1)-
976 option->positionWithinLine = QStyleOptionToolBar::End;-
977 else-
978 option->positionWithinLine = QStyleOptionToolBar::Middle;-
979-
980 if (dock.lines.count() == 1)-
981 option->positionOfLine = QStyleOptionToolBar::OnlyOne;-
982 else if (j == 0)-
983 option->positionOfLine = QStyleOptionToolBar::Beginning;-
984 else if (j == dock.lines.count() - 1)-
985 option->positionOfLine = QStyleOptionToolBar::End;-
986 else-
987 option->positionOfLine = QStyleOptionToolBar::Middle;-
988-
989 return;-
990 }-
991 }-
992 }-
993 }-
994}-
995-
996QList<int> QToolBarAreaLayout::indexOf(QWidget *toolBar) const-
997{-
998 QList<int> result;-
999-
1000 bool found = false;-
1001-
1002 for (int i = 0; i < QInternal::DockCount; ++i) {-
1003 const QToolBarAreaLayoutInfo &dock = docks[i];-
1004-
1005 for (int j = 0; j < dock.lines.count(); ++j) {-
1006 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
1007-
1008 for (int k = 0; k < line.toolBarItems.count(); ++k) {-
1009 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);-
1010 if (!item.gap && item.widgetItem->widget() == toolBar) {-
1011 found = true;-
1012 result.prepend(k);-
1013 break;-
1014 }-
1015 }-
1016-
1017 if (found) {-
1018 result.prepend(j);-
1019 break;-
1020 }-
1021 }-
1022-
1023 if (found) {-
1024 result.prepend(i);-
1025 break;-
1026 }-
1027 }-
1028-
1029 return result;-
1030}-
1031-
1032//this functions returns the path to the possible gapindex for the position pos-
1033QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const-
1034{-
1035 Qt::LayoutDirection dir = mainWindow->layoutDirection();-
1036 int minDistance = 80; // when a dock area is empty, how "wide" is it?-
1037 QList<int> ret; //return value-
1038 for (int i = 0; i < QInternal::DockCount; ++i) {-
1039 QPoint p = pos;-
1040 if (docks[i].o == Qt::Horizontal)-
1041 p = QStyle::visualPos(dir, docks[i].rect, p);-
1042 QList<int> result = docks[i].gapIndex(p, &minDistance);-
1043 if (!result.isEmpty()) {-
1044 result.prepend(i);-
1045 ret = result;-
1046 }-
1047 }-
1048-
1049 return ret;-
1050}-
1051-
1052QList<int> QToolBarAreaLayout::currentGapIndex() const-
1053{-
1054 for (int i = 0; i < QInternal::DockCount; ++i) {-
1055 const QToolBarAreaLayoutInfo &dock = docks[i];-
1056-
1057 for (int j = 0; j < dock.lines.count(); ++j) {-
1058 const QToolBarAreaLayoutLine &line = dock.lines[j];-
1059-
1060 for (int k = 0; k < line.toolBarItems.count(); k++) {-
1061 if (line.toolBarItems[k].gap) {-
1062 QList<int> result;-
1063 result << i << j << k;-
1064 return result;-
1065 }-
1066 }-
1067 }-
1068 }-
1069 return QList<int>();-
1070}-
1071-
1072bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item)-
1073{-
1074 Q_ASSERT(path.count() == 3);-
1075 const int i = path.first();-
1076 Q_ASSERT(i >= 0 && i < QInternal::DockCount);-
1077 return docks[i].insertGap(path.mid(1), item);-
1078}-
1079-
1080void QToolBarAreaLayout::remove(const QList<int> &path)-
1081{-
1082 Q_ASSERT(path.count() == 3);-
1083 docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2));-
1084}-
1085-
1086void QToolBarAreaLayout::remove(QLayoutItem *item)-
1087{-
1088 for (int i = 0; i < QInternal::DockCount; ++i) {-
1089 QToolBarAreaLayoutInfo &dock = docks[i];-
1090-
1091 for (int j = 0; j < dock.lines.count(); ++j) {-
1092 QToolBarAreaLayoutLine &line = dock.lines[j];-
1093-
1094 for (int k = 0; k < line.toolBarItems.count(); k++) {-
1095 if (line.toolBarItems[k].widgetItem == item) {-
1096 line.toolBarItems.removeAt(k);-
1097 if (line.toolBarItems.isEmpty())-
1098 dock.lines.removeAt(j);-
1099 return;-
1100 }-
1101 }-
1102 }-
1103 }-
1104}-
1105-
1106void QToolBarAreaLayout::clear()-
1107{-
1108 for (int i = 0; i < QInternal::DockCount; ++i)-
1109 docks[i].clear();-
1110 rect = QRect();-
1111}-
1112-
1113QToolBarAreaLayoutItem *QToolBarAreaLayout::item(const QList<int> &path)-
1114{-
1115 Q_ASSERT(path.count() == 3);-
1116-
1117 if (path.at(0) < 0 || path.at(0) >= QInternal::DockCount)-
1118 return 0;-
1119 QToolBarAreaLayoutInfo &info = docks[path.at(0)];-
1120 if (path.at(1) < 0 || path.at(1) >= info.lines.count())-
1121 return 0;-
1122 QToolBarAreaLayoutLine &line = info.lines[path.at(1)];-
1123 if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.count())-
1124 return 0;-
1125 return &(line.toolBarItems[path.at(2)]);-
1126}-
1127-
1128QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const-
1129{-
1130 const int i = path.first();-
1131-
1132 QRect r = docks[i].itemRect(path.mid(1));-
1133 if (docks[i].o == Qt::Horizontal)-
1134 r = QStyle::visualRect(mainWindow->layoutDirection(),-
1135 docks[i].rect, r);-
1136 return r;-
1137}-
1138-
1139QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path)-
1140{-
1141 QToolBarAreaLayoutItem *item = this->item(path);-
1142 if (Q_UNLIKELY(!item))) {
__builtin_expe...!item), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1143 qWarning() << "No item at" << path;-
1144 return 0;
never executed: return 0;
0
1145 }-
1146 Q_ASSERT(item->gap);-
1147 Q_ASSERT(item->widgetItem != 0);-
1148 item->gap = false;-
1149 return item->widgetItem;
never executed: return item->widgetItem;
0
1150}-
1151-
1152QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other)-
1153{-
1154 //other needs to be update as well-
1155 Q_ASSERT(path.count() == 3);-
1156 QToolBarAreaLayoutItem *item = this->item(path);-
1157 Q_ASSERT(item);-
1158-
1159 //update the leading space here-
1160 QToolBarAreaLayoutInfo &info = docks[path.at(0)];-
1161 QToolBarAreaLayoutLine &line = info.lines[path.at(1)];-
1162 if (item->size != pick(line.o, item->realSizeHint())) {-
1163 //the item doesn't have its default size-
1164 //so we'll give this to the next item-
1165 int newExtraSpace = 0;-
1166 //let's iterate over the siblings of the current item that pare placed before it-
1167 //we need to find just the one before-
1168 for (int i = path.at(2) - 1; i >= 0; --i) {-
1169 QToolBarAreaLayoutItem &previous = line.toolBarItems[i];-
1170 if (!previous.skip()) {-
1171 //we need to check if it has a previous element and a next one-
1172 //the previous will get its size changed-
1173 for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) {-
1174 const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j);-
1175 if (!next.skip()) {-
1176 newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint());-
1177 previous.resize(line.o, next.pos - previous.pos);-
1178 break;-
1179 }-
1180 }-
1181 break;-
1182 }-
1183 }-
1184-
1185 if (other) {-
1186 QToolBarAreaLayoutInfo &info = other->docks[path.at(0)];-
1187 QToolBarAreaLayoutLine &line = info.lines[path.at(1)];-
1188 for (int i = path.at(2) - 1; i >= 0; --i) {-
1189 QToolBarAreaLayoutItem &previous = line.toolBarItems[i];-
1190 if (!previous.skip()) {-
1191 previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace);-
1192 break;-
1193 }-
1194 }-
1195-
1196 }-
1197 }-
1198-
1199 Q_ASSERT(!item->gap);-
1200 item->gap = true;-
1201 return item->widgetItem;-
1202}-
1203-
1204static QRect unpackRect(uint geom0, uint geom1, bool *floating)-
1205{-
1206 *floating = geom0 & 1;-
1207 if (!*floating)-
1208 return QRect();-
1209-
1210 geom0 >>= 1;-
1211-
1212 int x = (int)(geom0 & 0x0000ffff) - 0x7FFF;-
1213 int y = (int)(geom1 & 0x0000ffff) - 0x7FFF;-
1214-
1215 geom0 >>= 16;-
1216 geom1 >>= 16;-
1217-
1218 int w = geom0 & 0x0000ffff;-
1219 int h = geom1 & 0x0000ffff;-
1220-
1221 return QRect(x, y, w, h);-
1222}-
1223-
1224static void packRect(uint *geom0, uint *geom1, const QRect &rect, bool floating)-
1225{-
1226 *geom0 = 0;-
1227 *geom1 = 0;-
1228-
1229 if (!floating)-
1230 return;-
1231-
1232 // The 0x7FFF is half of 0xFFFF. We add it so we can handle negative coordinates on-
1233 // dual monitors. It's subtracted when unpacking.-
1234-
1235 *geom0 |= qMax(0, rect.width()) & 0x0000ffff;-
1236 *geom1 |= qMax(0, rect.height()) & 0x0000ffff;-
1237-
1238 *geom0 <<= 16;-
1239 *geom1 <<= 16;-
1240-
1241 *geom0 |= qMax(0, rect.x() + 0x7FFF) & 0x0000ffff;-
1242 *geom1 |= qMax(0, rect.y() + 0x7FFF) & 0x0000ffff;-
1243-
1244 // yeah, we chop one bit off the width, but it still has a range up to 32512-
1245-
1246 *geom0 <<= 1;-
1247 *geom0 |= 1;-
1248}-
1249-
1250-
1251void QToolBarAreaLayout::saveState(QDataStream &stream) const-
1252{-
1253 // save toolbar state-
1254 stream << (uchar) ToolBarStateMarkerEx;-
1255-
1256 int lineCount = 0;-
1257 for (int i = 0; i < QInternal::DockCount; ++i)
i < QInternal::DockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1258 lineCount += docks[i].lines.count();
never executed: lineCount += docks[i].lines.count();
0
1259-
1260 stream << lineCount;-
1261-
1262 for (int i = 0; i < QInternal::DockCount; ++i) {
i < QInternal::DockCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1263 const QToolBarAreaLayoutInfo &dock = docks[i];-
1264-
1265 for (int j = 0; j < dock.lines.count(); ++j) {
j < dock.lines.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1266 const QToolBarAreaLayoutLine &line = dock.lines.at(j);-
1267-
1268 stream << i << line.toolBarItems.count();-
1269-
1270 for (int k = 0; k < line.toolBarItems.count(); ++k) {
k < line.toolBarItems.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);-
1272 QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget();-
1273 QString objectName = widget->objectName();-
1274 if (Q_UNLIKELY(objectName.isEmpty())())) {
__builtin_expe...pty()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1275 qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'",-
1276 widget, widget->windowTitle().toLocal8Bit().constData());-
1277 }
never executed: end of block
0
1278 stream << objectName;-
1279 // we store information as:-
1280 // 1st bit: 1 if shown-
1281 // 2nd bit: 1 if orientation is vertical (default is horizontal)-
1282 uchar shownOrientation = (uchar)!widget->isHidden();-
1283 if (QToolBar * tb= qobject_cast<QToolBar*>(widget)) {
QToolBar * tb=...lBar*>(widget)Description
TRUEnever evaluated
FALSEnever evaluated
0
1284 if (tb->orientation() == Qt::Vertical)
tb->orientatio...= Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
1285 shownOrientation |= 2;
never executed: shownOrientation |= 2;
0
1286 }
never executed: end of block
0
1287 stream << shownOrientation;-
1288 stream << item.pos;-
1289 //we store the preferred size. If the use rdidn't resize the toolbars it will be -1-
1290 stream << item.preferredSize;-
1291-
1292 uint geom0, geom1;-
1293 packRect(&geom0, &geom1, widget->geometry(), widget->isWindow());-
1294 stream << geom0 << geom1;-
1295 }
never executed: end of block
0
1296 }
never executed: end of block
0
1297 }
never executed: end of block
0
1298}
never executed: end of block
0
1299-
1300static inline int getInt(QDataStream &stream)-
1301{-
1302 int x;-
1303 stream >> x;-
1304 return x;-
1305}-
1306-
1307-
1308bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker, bool testing)-
1309{-
1310 QList<QToolBar*> toolBars = _toolBars;-
1311 int lines;-
1312 stream >> lines;-
1313-
1314 for (int j = 0; j < lines; ++j) {-
1315 int pos;-
1316 stream >> pos;-
1317 if (pos < 0 || pos >= QInternal::DockCount)-
1318 return false;-
1319 int cnt;-
1320 stream >> cnt;-
1321-
1322 QToolBarAreaLayoutInfo &dock = docks[pos];-
1323 const bool applyingLayout = !testing;-
1324 QToolBarAreaLayoutLine line(dock.o);-
1325-
1326 for (int k = 0; k < cnt; ++k) {-
1327 QToolBarAreaLayoutItem item;-
1328-
1329 QString objectName;-
1330 stream >> objectName;-
1331 uchar shown;-
1332 stream >> shown;-
1333 item.pos = getInt(stream);-
1334 item.size = getInt(stream);-
1335-
1336 /*-
1337 4.3.0 added floating toolbars, but failed to add the ability to restore them.-
1338 We need to store there geometry (four ints). We cannot change the format in a-
1339 patch release (4.3.1) by adding ToolBarStateMarkerEx2 to signal extra data. So-
1340 for now we'll pack it in the two legacy ints we no longer used in Qt4.3.0.-
1341 In 4.4, we should add ToolBarStateMarkerEx2 and fix this properly.-
1342 */-
1343-
1344 QRect rect;-
1345 bool floating = false;-
1346 uint geom0, geom1;-
1347 geom0 = getInt(stream);-
1348 if (tmarker == ToolBarStateMarkerEx) {-
1349 geom1 = getInt(stream);-
1350 rect = unpackRect(geom0, geom1, &floating);-
1351 }-
1352-
1353 QToolBar *toolBar = 0;-
1354 for (int x = 0; x < toolBars.count(); ++x) {-
1355 if (toolBars.at(x)->objectName() == objectName) {-
1356 toolBar = toolBars.takeAt(x);-
1357 break;-
1358 }-
1359 }-
1360 if (toolBar == 0) {-
1361 continue;-
1362 }-
1363-
1364 if (applyingLayout) {-
1365 item.widgetItem = new QWidgetItemV2(toolBar);-
1366 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);-
1367 toolBar->setVisible(shown & 1);-
1368 toolBar->d_func()->setWindowState(floating, true, rect);-
1369-
1370 item.preferredSize = item.size;-
1371 line.toolBarItems.append(item);-
1372 }-
1373 }-
1374-
1375 if (applyingLayout) {-
1376 dock.lines.append(line);-
1377 }-
1378 }-
1379-
1380-
1381 return stream.status() == QDataStream::Ok;-
1382}-
1383-
1384bool QToolBarAreaLayout::isEmpty() const-
1385{-
1386 for (int i = 0; i < QInternal::DockCount; ++i) {-
1387 if (!docks[i].lines.isEmpty())-
1388 return false;-
1389 }-
1390 return true;-
1391}-
1392-
1393QT_END_NAMESPACE-
1394-
1395#endif // QT_NO_TOOLBAR-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9