Changeset 561 for trunk/src/gui/widgets/qtoolbararealayout.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qtoolbararealayout.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 114 114 115 115 QSize sh = item.sizeHint(); 116 a += pick(o, sh) + item.extraSpace;116 a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh); 117 117 b = qMax(b, perp(o, sh)); 118 118 } … … 157 157 continue; 158 158 159 QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout()); 160 if (tblayout) 159 if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout())) 161 160 tblayout->checkUsePopupMenu(); 162 161 163 int itemMin = pick(o, item.minimumSize());164 int itemHint = pick(o, item.sizeHint());165 //we ensure the extraspace is not too low166 item.extraSpace = qMax(itemMin - itemHint, item.extraSpace); 167 itemHint += item.extraSpace;168 int itemExtra = qMin(itemHint- itemMin, extra);169 170 item.size = itemMin + itemExtra; 171 extra -= itemExtra;162 const int itemMin = pick(o, item.minimumSize()); 163 //preferredSize is the default if it is set, otherwise, we take the sizehint 164 item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint()); 165 166 //the extraspace is the space above the item minimum sizehint 167 const int extraSpace = qMin(item.size - itemMin, extra); 168 item.size = itemMin + extraSpace; //that is the real size 169 170 extra -= extraSpace; 172 171 173 172 last = i; … … 396 395 void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) 397 396 { 398 if (dirty) {397 if (dirty) 399 398 fitLayout(); 400 }401 399 402 400 dirty = true; 403 401 404 if (o == Qt::Vertical) {402 if (o == Qt::Vertical) 405 403 pos -= rect.top(); 406 } 407 408 //here we actually update the extraSpace for the line containing the toolbar so that we move it 404 405 //here we actually update the preferredSize for the line containing the toolbar so that we move it 409 406 for (int j = 0; j < lines.count(); ++j) { 410 407 QToolBarAreaLayoutLine &line = lines[j]; … … 433 430 } 434 431 435 // let's update the previous extra space432 //extra is the number of pixels to add to the previous toolbar 436 433 int extra = newPos - current.pos; 437 434 438 if (qAbs(previous.extraSpace + extra) < QApplication::startDragDistance()) { 439 //we stick to the default space 440 extra = 0; 435 //we check if the previous is near its size hint 436 //in which case we try to stick to it 437 const int diff = pick(o, previous.sizeHint()) - (previous.size + extra); 438 if (qAbs(diff) < QApplication::startDragDistance()) { 439 //we stick to the default place and size 440 extra += diff; 441 441 } 442 442 443 443 //update for the current item 444 current.extraSpace -= extra; 445 //this ensures the toolbars to be pushed to the right when necessary 446 current.extraSpace = qMax(pick(o,current.minimumSize())- pick(o,current.sizeHint()), current.extraSpace); 447 444 current.extendSize(line.o, -extra); 445 448 446 if (extra >= 0) { 449 previous.extraSpace += extra; 450 447 previous.extendSize(line.o, extra); 451 448 } else { 452 449 //we need to push the toolbars on the left starting with previous … … 456 453 QToolBarAreaLayoutItem &item = line.toolBarItems[l]; 457 454 if (!item.skip()) { 458 const int min ExtraSpace = pick(o, item.minimumSize()) - pick(o, item.sizeHint());459 const int margin = item. extraSpace - minExtraSpace;455 const int minPreferredSize = pick(o, item.minimumSize()); 456 const int margin = item.size - minPreferredSize; 460 457 if (margin < extra) { 461 item. extraSpace = minExtraSpace;458 item.resize(line.o, minPreferredSize); 462 459 extra -= margin; 463 460 } else { 464 item.ext raSpace -= extra;461 item.extendSize(line.o, -extra); 465 462 extra = 0; 466 463 } … … 484 481 485 482 486 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos ) const483 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const 487 484 { 488 485 int p = pick(o, pos); … … 513 510 QList<int> result; 514 511 result << j << k; 512 *minDistance = 0; //we found a perfect match 515 513 return result; 516 514 } 517 } else if (appendLineDropRect().contains(pos)) { 518 QList<int> result; 519 result << lines.count() << 0; 520 return result; 515 } else { 516 const int dist = distance(pos); 517 //it will only return a path if the minDistance is higher than the current distance 518 if (dist >= 0 && *minDistance > dist) { 519 *minDistance = dist; 520 521 QList<int> result; 522 result << lines.count() << 0; 523 return result; 524 } 521 525 } 522 526 … … 524 528 } 525 529 526 bool QToolBarAreaLayoutInfo::insertGap(QList<int> path, QLayoutItem *item) 527 { 528 int j = path.at(0); 530 bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item) 531 { 532 Q_ASSERT(path.count() == 2); 533 int j = path.first(); 529 534 if (j == lines.count()) 530 535 lines.append(QToolBarAreaLayoutLine(o)); … … 537 542 gap_item.widgetItem = item; 538 543 539 //update the previous item's extra space544 //update the previous item's preferred size 540 545 for(int p = k - 1 ; p >= 0; --p) { 541 546 QToolBarAreaLayoutItem &previous = line.toolBarItems[p]; 542 547 if (!previous.skip()) { 543 548 //we found the previous one 544 gap_item.extraSpace = qMax(0, previous.extraSpace - pick(o, gap_item.sizeHint())); 545 previous.extraSpace = qMin(previous.extraSpace, 0); 549 int previousSizeHint = pick(line.o, previous.sizeHint()); 550 int previousExtraSpace = previous.size - previousSizeHint; 551 552 if (previousExtraSpace > 0) { 553 //in this case we reset the space 554 previous.preferredSize = -1; 555 previous.size = previousSizeHint; 556 557 gap_item.resize(o, previousExtraSpace); 558 } 559 546 560 break; 547 561 } … … 556 570 { 557 571 lines.clear(); 558 rect = QRect(0, 0, -1, -1); 559 } 560 561 QRect QToolBarAreaLayoutInfo::itemRect(QList<int> path) const 562 { 572 rect = QRect(); 573 } 574 575 QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const 576 { 577 Q_ASSERT(path.count() == 2); 563 578 int j = path.at(0); 564 579 int k = path.at(1); … … 580 595 } 581 596 582 QRect QToolBarAreaLayoutInfo::appendLineDropRect() const 583 { 584 QRect result; 585 597 int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const 598 { 586 599 switch (dockPos) { 587 600 case QInternal::LeftDock: 588 result = QRect(rect.right(), rect.top(), 589 EmptyDockAreaSize, rect.height()); 590 break; 601 if (pos.y() < rect.bottom()) 602 return pos.x() - rect.right(); 591 603 case QInternal::RightDock: 592 result = QRect(rect.left() - EmptyDockAreaSize, rect.top(), 593 EmptyDockAreaSize, rect.height()); 594 break; 604 if (pos.y() < rect.bottom()) 605 return rect.left() - pos.x(); 595 606 case QInternal::TopDock: 596 result = QRect(rect.left(), rect.bottom() + 1, 597 rect.width(), EmptyDockAreaSize); 598 break; 607 if (pos.x() < rect.right()) 608 return pos.y() - rect.bottom(); 599 609 case QInternal::BottomDock: 600 result = QRect(rect.left(), rect.top() - EmptyDockAreaSize, 601 rect.width(), EmptyDockAreaSize); 602 break; 610 if (pos.x() < rect.right()) 611 return rect.top() - pos.y(); 603 612 default: 604 613 break; 605 614 } 606 607 return result; 615 return -1; 608 616 } 609 617 … … 612 620 */ 613 621 614 QToolBarAreaLayout::QToolBarAreaLayout(QMainWindow *win) 615 { 616 visible = true; 617 mainWindow = win; 622 QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true) 623 { 618 624 for (int i = 0; i < QInternal::DockCount; ++i) { 619 625 QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i); … … 771 777 for (int k = 0; k < line.toolBarItems.count(); ++k) { 772 778 QToolBarAreaLayoutItem &item = line.toolBarItems[k]; 773 delete item.widgetItem; 779 if (!item.gap) 780 delete item.widgetItem; 774 781 item.widgetItem = 0; 775 782 } … … 921 928 geo = QStyle::visualRect(dir, line.rect, geo); 922 929 923 layout->widgetAnimator ->animate(widget, geo, animate);930 layout->widgetAnimator.animate(widget, geo, animate); 924 931 } 925 932 } … … 1016 1023 } 1017 1024 1025 //this functions returns the path to the possible gapindex for the position pos 1018 1026 QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const 1019 1027 { 1020 1028 Qt::LayoutDirection dir = mainWindow->layoutDirection(); 1029 int minDistance = 80; // when a dock area is empty, how "wide" is it? 1030 QList<int> ret; //return value 1021 1031 for (int i = 0; i < QInternal::DockCount; ++i) { 1022 1032 QPoint p = pos; 1023 1033 if (docks[i].o == Qt::Horizontal) 1024 1034 p = QStyle::visualPos(dir, docks[i].rect, p); 1025 QList<int> result = docks[i].gapIndex(p );1035 QList<int> result = docks[i].gapIndex(p, &minDistance); 1026 1036 if (!result.isEmpty()) { 1027 1037 result.prepend(i); 1028 ret urnresult;1029 } 1030 } 1031 1032 return QList<int>();1038 ret = result; 1039 } 1040 } 1041 1042 return ret; 1033 1043 } 1034 1044 … … 1053 1063 } 1054 1064 1055 bool QToolBarAreaLayout::insertGap( QList<int>path, QLayoutItem *item)1056 { 1057 Q_ASSERT( !path.isEmpty());1058 int i = path.takeFirst();1065 bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) 1066 { 1067 Q_ASSERT(path.count() == 3); 1068 const int i = path.first(); 1059 1069 Q_ASSERT(i >= 0 && i < QInternal::DockCount); 1060 return docks[i].insertGap(path, item); 1061 } 1062 1063 void QToolBarAreaLayout::remove(QList<int> path) 1064 { 1070 return docks[i].insertGap(path.mid(1), item); 1071 } 1072 1073 void QToolBarAreaLayout::remove(const QList<int> &path) 1074 { 1075 Q_ASSERT(path.count() == 3); 1065 1076 docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2)); 1066 1077 } … … 1090 1101 for (int i = 0; i < QInternal::DockCount; ++i) 1091 1102 docks[i].clear(); 1092 rect = QRect( 0, 0, -1, -1);1093 } 1094 1095 QToolBarAreaLayoutItem &QToolBarAreaLayout::item( QList<int>path)1103 rect = QRect(); 1104 } 1105 1106 QToolBarAreaLayoutItem &QToolBarAreaLayout::item(const QList<int> &path) 1096 1107 { 1097 1108 Q_ASSERT(path.count() == 3); … … 1105 1116 } 1106 1117 1107 QRect QToolBarAreaLayout::itemRect( QList<int>path) const1108 { 1109 int i = path.takeFirst();1110 1111 QRect r = docks[i].itemRect(path );1118 QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const 1119 { 1120 const int i = path.first(); 1121 1122 QRect r = docks[i].itemRect(path.mid(1)); 1112 1123 if (docks[i].o == Qt::Horizontal) 1113 1124 r = QStyle::visualRect(mainWindow->layoutDirection(), … … 1116 1127 } 1117 1128 1118 QLayoutItem *QToolBarAreaLayout::plug( QList<int>path)1129 QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) 1119 1130 { 1120 1131 QToolBarAreaLayoutItem &item = this->item(path); … … 1125 1136 } 1126 1137 1127 QLayoutItem *QToolBarAreaLayout::unplug( QList<int>path, QToolBarAreaLayout *other)1138 QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) 1128 1139 { 1129 1140 //other needs to be update as well 1141 Q_ASSERT(path.count() == 3); 1130 1142 QToolBarAreaLayoutItem &item = this->item(path); 1131 1143 … … 1133 1145 QToolBarAreaLayoutInfo &info = docks[path.at(0)]; 1134 1146 QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; 1135 if (item.extraSpace != 0) { 1147 if (item.size != pick(line.o, item.realSizeHint())) { 1148 //the item doesn't have its default size 1149 //so we'll give this to the next item 1136 1150 int newExtraSpace = 0; 1151 //let's iterate over the siblings of the current item that pare placed before it 1152 //we need to find just the one before 1137 1153 for (int i = path.at(2) - 1; i >= 0; --i) { 1138 1154 QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; 1139 1155 if (!previous.skip()) { 1156 //we need to check if it has a previous element and a next one 1157 //the previous will get its size changed 1140 1158 for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) { 1141 1159 const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j); 1142 1160 if (!next.skip()) { 1143 newExtraSpace = previous.extraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); 1161 newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); 1162 previous.resize(line.o, next.pos - previous.pos); 1163 break; 1144 1164 } 1145 break;1146 1165 } 1147 1166 break; … … 1155 1174 QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; 1156 1175 if (!previous.skip()) { 1157 previous. extraSpace = newExtraSpace;1176 previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace); 1158 1177 break; 1159 1178 } … … 1162 1181 } 1163 1182 } 1164 1165 1183 1166 1184 Q_ASSERT(!item.gap); … … 1254 1272 stream << shownOrientation; 1255 1273 stream << item.pos; 1256 // if extraSpace is 0 the item has its "normal" size, so no need to store the size (we store -1)1257 stream << (item.extraSpace == 0 ? -1 : (pick(line.o, item.realSizeHint()) + item.extraSpace));1274 //we store the preferred size. If the use rdidn't resize the toolbars it will be -1 1275 stream << item.preferredSize; 1258 1276 1259 1277 uint geom0, geom1; … … 1284 1302 int lines; 1285 1303 stream >> lines; 1304 if (!testing) 1305 testing = mainWindow->unifiedTitleAndToolBarOnMac(); 1286 1306 1287 1307 for (int j = 0; j < lines; ++j) { … … 1294 1314 1295 1315 QToolBarAreaLayoutInfo &dock = docks[pos]; 1316 const bool applyingLayout = !testing && !(pos == QInternal::TopDock && mainWindow->unifiedTitleAndToolBarOnMac()); 1296 1317 QToolBarAreaLayoutLine line(dock.o); 1297 1318 … … 1334 1355 } 1335 1356 1336 if ( !testing) {1357 if (applyingLayout) { 1337 1358 item.widgetItem = new QWidgetItemV2(toolBar); 1338 1359 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o); … … 1340 1361 toolBar->d_func()->setWindowState(floating, true, rect); 1341 1362 1342 //if it is -1, it means we should use the default size 1343 item.extraSpace = (item.size == -1) ? 0 : item.size - pick(line.o, item.realSizeHint()); 1344 1345 1363 item.preferredSize = item.size; 1346 1364 line.toolBarItems.append(item); 1347 1365 } 1348 1366 } 1349 1367 1350 if ( !testing) {1368 if (applyingLayout) { 1351 1369 dock.lines.append(line); 1352 1370 }
Note:
See TracChangeset
for help on using the changeset viewer.