17
18
29 return qSmartMinSize(
static_cast<QWidgetItem*>(
widgetItem));
37 return realSizeHint();
44 QSize s = wid->sizeHint().expandedTo(wid->minimumSizeHint());
45 if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
47 if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
49 s = s.boundedTo(wid->maximumSize())
50 .expandedTo(wid->minimumSize());
62
63
73 for (
int i = 0; i < toolBarItems.size(); ++i) {
78 QSize sh = item.sizeHint();
79 a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh);
80 b = qMax(b, perp(o, sh));
93 for (
int i = 0; i < toolBarItems.size(); ++i) {
98 QSize ms = item.minimumSize();
100 b = qMax(b, perp(o, ms));
104 rpick(o, result) = a;
105 rperp(o, result) = b;
113 int min = pick(o, minimumSize());
114 int space = pick(o, rect.size());
115 int extra = qMax(0, space - min);
117 for (
int i = 0; i < toolBarItems.size(); ++i) {
122 if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item
.widgetItem->widget()->layout()))
123 tblayout->checkUsePopupMenu();
125 const int itemMin = pick(o, item.minimumSize());
127 item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint());
130 const int extraSpace = qMin(item
.size - itemMin, extra);
131 item
.size = itemMin + extraSpace;
140 for (
int i = 0; i < toolBarItems.size(); ++i) {
147 item.size = qMax(0, pick(o, rect.size()) - item.pos);
154 for (
int i = 0; i < toolBarItems.size(); ++i) {
155 if (!toolBarItems.at(i).skip())
162
163
169 case QInternal::LeftDock:
170 case QInternal::RightDock:
173 case QInternal::TopDock:
174 case QInternal::BottomDock:
186 for (
int i = 0; i < lines.size(); ++i) {
191 QSize hint = l.sizeHint();
192 a = qMax(a, pick(o, hint));
197 rpick(o, result) = a;
198 rperp(o, result) = b;
206 for (
int i = 0; i < lines.size(); ++i) {
211 QSize m = l.minimumSize();
212 a = qMax(a, pick(o, m));
217 rpick(o, result) = a;
218 rperp(o, result) = b;
229 bool reverse = dockPos == QInternal::RightDock || dockPos == QInternal::BottomDock;
231 int i = reverse ? lines.size() - 1 : 0;
233 if ((reverse && i < 0) || (!reverse && i == lines.size()))
238 if (o == Qt::Horizontal) {
239 l.rect.setLeft(rect.left());
240 l.rect.setRight(rect.right());
241 l.rect.setTop(b + rect.top());
242 b += l.sizeHint().height();
243 l.rect.setBottom(b - 1 + rect.top());
245 l.rect.setTop(rect.top());
246 l.rect.setBottom(rect.bottom());
247 l.rect.setLeft(b + rect.left());
248 b += l.sizeHint().width();
249 l.rect.setRight(b - 1 + rect.left());
255 i += reverse ? -1 : 1;
261 toolBar->setOrientation(o);
262 QLayoutItem *item =
new QWidgetItemV2(toolBar);
269 if (before ==
nullptr) {
271 lines.append(QToolBarAreaLayoutLine(o));
272 lines.last().toolBarItems.append(item);
276 for (
int j = 0; j < lines.size(); ++j) {
279 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
280 if (line.toolBarItems.at(k).widgetItem->widget() == before) {
281 line.toolBarItems.insert(k, item);
290 for (
int j = 0; j < lines.size(); ++j) {
293 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
298 line.toolBarItems.removeAt(k);
300 if (line.toolBarItems.isEmpty() && j < lines.size() - 1)
311 if (before ==
nullptr) {
312 if (!lines.isEmpty() && lines.constLast().toolBarItems.isEmpty())
314 lines.append(QToolBarAreaLayoutLine(o));
318 for (
int j = 0; j < lines.size(); ++j) {
321 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
322 if (line.toolBarItems.at(k).widgetItem->widget() == before) {
327 newLine.toolBarItems = line.toolBarItems.mid(k);
328 line.toolBarItems = line.toolBarItems.mid(0, k);
329 lines.insert(j + 1, newLine);
339 for (
int j = 0; j < lines.size(); ++j) {
342 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
343 if (line.toolBarItems.at(k).widgetItem->widget() == before) {
349 lines[j - 1].toolBarItems += lines[j].toolBarItems;
365 if (o == Qt::Vertical)
369 for (
int j = 0; j < lines.size(); ++j) {
372 int previousIndex = -1;
374 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
377 int newPos = current
.pos;
379 if (previousIndex >= 0) {
381 if (pos < current
.pos) {
382 newPos = qMax(pos, minPos);
385 int maxPos = pick(o, rect.size());
386 for(
int l = k; l < line.toolBarItems.size(); ++l) {
389 maxPos -= pick(o, item.minimumSize());
392 newPos = qMin(pos, maxPos);
396 int extra = newPos - current
.pos;
400 const int diff = pick(o, previous.sizeHint()) - (previous.size + extra);
401 if (qAbs(diff) < QApplication::startDragDistance()) {
407 current.extendSize(line.o, -extra);
410 previous.extendSize(line.o, extra);
415 for(
int l = previousIndex; l >=0; --l) {
418 const int minPreferredSize = pick(o, item.minimumSize());
419 const int margin = item
.size - minPreferredSize;
420 if (margin < extra) {
421 item.resize(line.o, minPreferredSize);
424 item.extendSize(line.o, -extra);
429 Q_ASSERT(extra == 0);
439 minPos += pick(o, current.minimumSize());
448 if (rect.contains(pos)) {
452 const int p = pick(o, pos - rect.topLeft());
454 for (
int j = 0; j < lines.size(); ++j) {
458 if (!line.rect.contains(pos))
462 for (; k < line.toolBarItems.size(); ++k) {
467 int size = qMin(item.size, pick(o, item.sizeHint()));
469 if (p > item
.pos + size)
471 if (p > item
.pos + size/2)
482 const int dist = distance(pos);
484 if (dist >= 0 && *minDistance > dist) {
488 result << lines.size() << 0;
498 Q_ASSERT(path.size() == 2);
499 int j = path.first();
500 if (j == lines.size())
501 lines.append(QToolBarAreaLayoutLine(o));
504 const int k = path.at(1);
511 for(
int p = k - 1 ; p >= 0; --p) {
515 int previousSizeHint = pick(line.o, previous.sizeHint());
516 int previousExtraSpace = previous
.size - previousSizeHint;
518 if (previousExtraSpace > 0) {
521 previous
.size = previousSizeHint;
523 gap_item.resize(o, previousExtraSpace);
530 line.toolBarItems.insert(k, gap_item);
543 Q_ASSERT(path.size() == 2);
550 QRect result = line.rect;
552 if (o == Qt::Horizontal) {
553 result.setLeft(item
.pos + line.rect.left());
554 result.setWidth(item
.size);
556 result.setTop(item
.pos + line.rect.top());
557 result.setHeight(item
.size);
566 case QInternal::LeftDock:
567 if (pos.y() < rect.bottom())
568 return pos.x() - rect.right();
570 case QInternal::RightDock:
571 if (pos.y() < rect.bottom())
572 return rect.left() - pos.x();
574 case QInternal::TopDock:
575 if (pos.x() < rect.right())
576 return pos.y() - rect.bottom();
578 case QInternal::BottomDock:
579 if (pos.x() < rect.right())
580 return rect.top() - pos.y();
583 case QInternal::DockCount:
590
591
595 for (
int i = 0; i < QInternal::DockCount; ++i) {
596 QInternal::DockPosition pos =
static_cast<QInternal::DockPosition>(i);
597 docks[i] = QToolBarAreaLayoutInfo(pos);
606 QSize left_hint = docks[QInternal::LeftDock].sizeHint();
607 QSize right_hint = docks[QInternal::RightDock].sizeHint();
608 QSize top_hint = docks[QInternal::TopDock].sizeHint();
609 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();
611 QRect center = rect.adjusted(left_hint.width(), top_hint.height(),
612 -right_hint.width(), -bottom_hint.height());
614 docks[QInternal::TopDock].rect = QRect(rect.left(), rect.top(),
615 rect.width(), top_hint.height());
616 docks[QInternal::LeftDock].rect = QRect(rect.left(), center.top(),
617 left_hint.width(), center.height());
618 docks[QInternal::RightDock].rect = QRect(center.right() + 1, center.top(),
619 right_hint.width(), center.height());
620 docks[QInternal::BottomDock].rect = QRect(rect.left(), center.bottom() + 1,
621 rect.width(), bottom_hint.height());
623 docks[QInternal::TopDock].fitLayout();
624 docks[QInternal::LeftDock].fitLayout();
625 docks[QInternal::RightDock].fitLayout();
626 docks[QInternal::BottomDock].fitLayout();
636 QSize result = centerMin;
638 QSize left_min = docks[QInternal::LeftDock].minimumSize();
639 QSize right_min = docks[QInternal::RightDock].minimumSize();
640 QSize top_min = docks[QInternal::TopDock].minimumSize();
641 QSize bottom_min = docks[QInternal::BottomDock].minimumSize();
643 result.setWidth(qMax(top_min.width(), result.width()));
644 result.setWidth(qMax(bottom_min.width(), result.width()));
645 result.setHeight(qMax(left_min.height(), result.height()));
646 result.setHeight(qMax(right_min.height(), result.height()));
648 result.rwidth() += left_min.width() + right_min.width();
649 result.rheight() += top_min.height() + bottom_min.height();
659 QSize result = centerHint;
661 QSize left_hint = docks[QInternal::LeftDock].sizeHint();
662 QSize right_hint = docks[QInternal::RightDock].sizeHint();
663 QSize top_hint = docks[QInternal::TopDock].sizeHint();
664 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();
666 result.setWidth(qMax(top_hint.width(), result.width()));
667 result.setWidth(qMax(bottom_hint.width(), result.width()));
668 result.setHeight(qMax(left_hint.height(), result.height()));
669 result.setHeight(qMax(right_hint.height(), result.height()));
671 result.rwidth() += left_hint.width() + right_hint.width();
672 result.rheight() += top_hint.height() + bottom_hint.height();
683 QSize left_hint = docks[QInternal::LeftDock].sizeHint();
684 QSize right_hint = docks[QInternal::RightDock].sizeHint();
685 QSize top_hint = docks[QInternal::TopDock].sizeHint();
686 QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();
688 result.adjust(-left_hint.width()*coef, -top_hint.height()*coef,
689 right_hint.width()*coef, bottom_hint.height()*coef);
696 Q_ASSERT(x !=
nullptr);
698 for (
int i = 0; i < QInternal::DockCount; ++i) {
701 for (
int j = 0; j < dock.lines.size(); ++j) {
704 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
706 return line.toolBarItems.at(k).widgetItem;
716 Q_ASSERT(x !=
nullptr);
718 for (
int i = 0; i < QInternal::DockCount; ++i) {
721 for (
int j = 0; j < dock.lines.size(); ++j) {
724 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
725 if ((*x)++ == index) {
726 QLayoutItem *result = line.toolBarItems.takeAt(k).widgetItem;
727 if (line.toolBarItems.isEmpty())
728 dock.lines.removeAt(j);
740 for (
int i = 0; i < QInternal::DockCount; ++i) {
743 for (
int j = 0; j < dock.lines.size(); ++j) {
746 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
758 for (
int i = 0; i < QInternal::DockCount; ++i) {
761 for (
int j = 0; j < dock.lines.size(); ++j) {
764 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
765 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)
766 return static_cast<QInternal::DockPosition>(i);
771 return QInternal::DockCount;
776 QInternal::DockPosition pos = findToolBar(before);
777 if (pos == QInternal::DockCount)
780 return docks[pos].insertToolBar(before, toolBar);
785 QInternal::DockPosition pos = findToolBar(toolBar);
786 if (pos == QInternal::DockCount)
788 docks[pos].removeToolBar(toolBar);
793 return docks[pos].insertToolBar(
nullptr, toolBar);
798 QInternal::DockPosition pos = findToolBar(before);
799 if (pos == QInternal::DockCount)
801 docks[pos].insertToolBarBreak(before);
806 QInternal::DockPosition pos = findToolBar(before);
807 if (pos == QInternal::DockCount)
809 docks[pos].removeToolBarBreak(before);
814 docks[pos].insertToolBarBreak(
nullptr);
819 QInternal::DockPosition pos = findToolBar(toolbar);
820 if (pos == QInternal::DockCount)
822 docks[pos].moveToolBar(toolbar, p);
828 if (docks[pos].lines.isEmpty())
829 docks[pos].lines.append(QToolBarAreaLayoutLine(docks[pos].o));
830 docks[pos].lines.last().toolBarItems.append(item);
835 QInternal::DockPosition pos = findToolBar(before);
836 if (pos == QInternal::DockCount)
839 docks[pos].insertItem(before, item);
845 Q_ASSERT(layout !=
nullptr);
847 Qt::LayoutDirection dir = mainWindow->layoutDirection();
849 for (
int i = 0; i < QInternal::DockCount; ++i) {
852 for (
int j = 0; j < dock.lines.size(); ++j) {
857 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
864 if (line.o == Qt::Horizontal) {
865 geo.setTop(line.rect.top());
866 geo.setBottom(line.rect.bottom());
867 geo.setLeft(line.rect.left() + item
.pos);
868 geo.setRight(line.rect.left() + item
.pos + item
.size - 1);
870 geo.setLeft(line.rect.left());
871 geo.setRight(line.rect.right());
872 geo.setTop(line.rect.top() + item
.pos);
873 geo.setBottom(line.rect.top() + item
.pos + item
.size - 1);
878 if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {
879 QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(toolBar->layout());
881 QPoint tr = geo.topRight();
882 QSize size = tbl->expandedSize(geo.size());
884 geo.moveTopRight(tr);
885 if (geo.bottom() > rect.bottom())
886 geo.moveBottom(rect.bottom());
887 if (geo.right() > rect.right())
888 geo.moveRight(rect.right());
896 if (visible && dock.o == Qt::Horizontal)
897 geo = QStyle::visualRect(dir, line.rect, geo);
899 layout->widgetAnimator.animate(widget, geo, animate);
907 for (
int i = 0; i < QInternal::DockCount; ++i) {
910 for (
int j = 0; j < dock.lines.size(); ++j) {
913 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
914 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)
915 return j > 0 && k == 0;
925 for (
int i = 0; i < QInternal::DockCount; ++i) {
928 for (
int j = 0; j < dock.lines.size(); ++j) {
931 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
932 if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) {
933 if (line.toolBarItems.size() == 1)
934 option->positionWithinLine = QStyleOptionToolBar::OnlyOne;
936 option->positionWithinLine = QStyleOptionToolBar::Beginning;
937 else if (k == line.toolBarItems.size() - 1)
938 option->positionWithinLine = QStyleOptionToolBar::End;
940 option->positionWithinLine = QStyleOptionToolBar::Middle;
942 if (dock.lines.size() == 1)
943 option->positionOfLine = QStyleOptionToolBar::OnlyOne;
945 option->positionOfLine = QStyleOptionToolBar::Beginning;
946 else if (j == dock.lines.size() - 1)
947 option->positionOfLine = QStyleOptionToolBar::End;
949 option->positionOfLine = QStyleOptionToolBar::Middle;
964 for (
int i = 0; i < QInternal::DockCount; ++i) {
967 for (
int j = 0; j < dock.lines.size(); ++j) {
970 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
997 Qt::LayoutDirection dir = mainWindow->layoutDirection();
998 int minDistance = 80;
1000 for (
int i = 0; i < QInternal::DockCount; ++i) {
1002 if (docks[i].o == Qt::Horizontal)
1003 p = QStyle::visualPos(dir, docks[i].rect, p);
1004 QList<
int> result = docks[i].gapIndex(p, &minDistance);
1005 if (!result.isEmpty()) {
1016 for (
int i = 0; i < QInternal::DockCount; ++i) {
1019 for (
int j = 0; j < dock.lines.size(); ++j) {
1022 for (
int k = 0; k < line.toolBarItems.size(); k++) {
1023 if (line.toolBarItems[k].gap) {
1025 result << i << j << k;
1031 return QList<
int>();
1036 Q_ASSERT(path.size() == 3);
1037 const int i = path.first();
1038 Q_ASSERT(i >= 0 && i < QInternal::DockCount);
1039 return docks[i].insertGap(path.mid(1), item);
1044 Q_ASSERT(path.size() == 3);
1047 line.toolBarItems.removeAt(path.at(2));
1048 if (line.toolBarItems.isEmpty())
1049 dock.lines.removeAt(path.at(1));
1054 for (
int i = 0; i < QInternal::DockCount; ++i) {
1057 for (
int j = 0; j < dock.lines.size(); ++j) {
1060 for (
int k = 0; k < line.toolBarItems.size(); k++) {
1061 if (line.toolBarItems[k].widgetItem == item) {
1062 line.toolBarItems.removeAt(k);
1063 if (line.toolBarItems.isEmpty())
1064 dock.lines.removeAt(j);
1074 for (
int i = 0; i < QInternal::DockCount; ++i)
1081 Q_ASSERT(path.size() == 3);
1083 if (path.at(0) < 0 || path.at(0) >= QInternal::DockCount)
1086 if (path.at(1) < 0 || path.at(1) >= info.lines.size())
1089 if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.size())
1091 return &(line.toolBarItems[path.at(2)]);
1096 const int i = path.first();
1098 QRect r = docks[i].itemRect(path.mid(1));
1099 if (docks[i].o == Qt::Horizontal)
1100 r = QStyle::visualRect(mainWindow->layoutDirection(),
1108 if (Q_UNLIKELY(!item)) {
1109 qWarning() <<
"No item at" << path;
1112 Q_ASSERT(item
->gap);
1121 Q_ASSERT(path.size() == 3);
1128 if (item->size != pick(line.o, item->realSizeHint())) {
1131 int newExtraSpace = 0;
1134 for (
int i = path.at(2) - 1; i >= 0; --i) {
1139 for (
int j = path.at(2) + 1; j < line.toolBarItems.size(); ++j) {
1142 newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint());
1143 previous.resize(line.o, next
.pos - previous
.pos);
1154 for (
int i = path.at(2) - 1; i >= 0; --i) {
1157 previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace);
1165 Q_ASSERT(!item
->gap);
1172 *floating = geom0 & 1;
1178 int x = (
int)(geom0 & 0x0000ffff) - 0x7FFF;
1179 int y = (
int)(geom1 & 0x0000ffff) - 0x7FFF;
1184 int w = geom0 & 0x0000ffff;
1185 int h = geom1 & 0x0000ffff;
1187 return QRect(x, y, w, h);
1190static void packRect(uint *geom0, uint *geom1,
const QRect &rect,
bool floating)
1201 *geom0 |= qMax(0, rect.width()) & 0x0000ffff;
1202 *geom1 |= qMax(0, rect.height()) & 0x0000ffff;
1207 *geom0 |= qMax(0, rect.x() + 0x7FFF) & 0x0000ffff;
1208 *geom1 |= qMax(0, rect.y() + 0x7FFF) & 0x0000ffff;
1220 stream << (uchar) ToolBarStateMarkerEx;
1223 for (
int i = 0; i < QInternal::DockCount; ++i)
1224 lineCount += docks[i].lines.size();
1226 stream << lineCount;
1228 for (
int i = 0; i < QInternal::DockCount; ++i) {
1231 for (
int j = 0; j < dock.lines.size(); ++j) {
1234 stream << i <<
int(line.toolBarItems.size());
1236 for (
int k = 0; k < line.toolBarItems.size(); ++k) {
1239 QString objectName = widget->objectName();
1240 if (Q_UNLIKELY(objectName.isEmpty())) {
1241 qWarning(
"QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'",
1242 widget, widget->windowTitle().toLocal8Bit().constData());
1244 stream << objectName;
1248 uchar shownOrientation = (uchar)!widget->isHidden();
1249 if (QToolBar * tb= qobject_cast<QToolBar*>(widget)) {
1250 if (tb->orientation() == Qt::Vertical)
1251 shownOrientation |= 2;
1253 stream << shownOrientation;
1259 packRect(&geom0, &geom1, widget->geometry(), widget->isWindow());
1260 stream << geom0 << geom1;
1276 QList<QToolBar*> toolBars = _toolBars;
1280 for (
int j = 0; j < lines; ++j) {
1283 if (pos < 0 || pos >= QInternal::DockCount)
1289 const bool applyingLayout = !testing;
1292 for (
int k = 0; k < cnt; ++k) {
1296 stream >> objectName;
1299 item.pos = getInt(stream);
1300 item.size = getInt(stream);
1303
1304
1305
1306
1307
1308
1311 bool floating =
false;
1313 geom0 = getInt(stream);
1315 geom1 = getInt(stream);
1316 rect = unpackRect(geom0, geom1, &floating);
1319 QToolBar *toolBar =
nullptr;
1320 for (
int x = 0; x < toolBars.size(); ++x) {
1321 if (toolBars.at(x)->objectName() == objectName) {
1322 toolBar = toolBars.takeAt(x);
1326 if (toolBar ==
nullptr) {
1330 if (applyingLayout) {
1333 auto *toolBarPrivate = QWidgetPrivate::get(toolBar);
1334 toolBarPrivate->widgetItem =
nullptr;
1335 item.widgetItem =
new QWidgetItemV2(toolBar);
1336 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
1337 toolBar->setVisible(shown & 1);
1338 toolBar->d_func()->setWindowState(floating,
false, rect);
1341 line.toolBarItems.append(item);
1345 if (applyingLayout) {
1346 dock.lines.append(line);
1351 return stream.status() == QDataStream::Ok;
1356 for (
int i = 0; i < QInternal::DockCount; ++i) {
1357 if (!docks[i].lines.isEmpty())
Combined button and popup list for selecting options.
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)