src/gui/widgets/qtoolbararealayout.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   478         }
   478         }
   479     }
   479     }
   480 }
   480 }
   481 
   481 
   482 
   482 
   483 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const
   483 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const
   484 {
   484 {
   485     int p = pick(o, pos);
   485     int p = pick(o, pos);
   486 
   486 
   487     if (rect.contains(pos)) {
   487     if (rect.contains(pos)) {
   488         for (int j = 0; j < lines.count(); ++j) {
   488         for (int j = 0; j < lines.count(); ++j) {
   507                 break;
   507                 break;
   508             }
   508             }
   509 
   509 
   510             QList<int> result;
   510             QList<int> result;
   511             result << j << k;
   511             result << j << k;
       
   512             *minDistance = 0; //we found a perfect match
   512             return result;
   513             return result;
   513         }
   514         }
   514     } else if (appendLineDropRect().contains(pos)) {
   515     } else {
   515         QList<int> result;
   516         const int dist = distance(pos);
   516         result << lines.count() << 0;
   517         //it will only return a path if the minDistance is higher than the current distance
   517         return result;
   518         if (dist >= 0 && *minDistance > dist) {
       
   519             *minDistance = dist;
       
   520 
       
   521             QList<int> result;
       
   522             result << lines.count() << 0;
       
   523             return result;
       
   524         }
   518     }
   525     }
   519 
   526 
   520     return QList<int>();
   527     return QList<int>();
   521 }
   528 }
   522 
   529 
   585     }
   592     }
   586 
   593 
   587     return result;
   594     return result;
   588 }
   595 }
   589 
   596 
   590 QRect QToolBarAreaLayoutInfo::appendLineDropRect() const
   597 int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const
   591 {
   598 {
   592     QRect result;
       
   593 
       
   594     switch (dockPos) {
   599     switch (dockPos) {
   595         case QInternal::LeftDock:
   600         case QInternal::LeftDock:
   596             result = QRect(rect.right(), rect.top(),
   601             if (pos.y() < rect.bottom())
   597                             EmptyDockAreaSize, rect.height());
   602                 return pos.x() - rect.right();
   598             break;
       
   599         case QInternal::RightDock:
   603         case QInternal::RightDock:
   600             result = QRect(rect.left() - EmptyDockAreaSize, rect.top(),
   604             if (pos.y() < rect.bottom())
   601                             EmptyDockAreaSize, rect.height());
   605                 return rect.left() - pos.x();
   602             break;
       
   603         case QInternal::TopDock:
   606         case QInternal::TopDock:
   604             result = QRect(rect.left(), rect.bottom() + 1,
   607             if (pos.x() < rect.right())
   605                             rect.width(), EmptyDockAreaSize);
   608                 return pos.y() - rect.bottom();
   606             break;
       
   607         case QInternal::BottomDock:
   609         case QInternal::BottomDock:
   608             result = QRect(rect.left(), rect.top() - EmptyDockAreaSize,
   610             if (pos.x() < rect.right())
   609                             rect.width(), EmptyDockAreaSize);
   611                 return rect.top() - pos.y();
   610             break;
       
   611         default:
   612         default:
   612             break;
   613             break;
   613     }
   614     }
   614 
   615     return -1;
   615     return result;
       
   616 }
   616 }
   617 
   617 
   618 /******************************************************************************
   618 /******************************************************************************
   619 ** QToolBarAreaLayout
   619 ** QToolBarAreaLayout
   620 */
   620 */
  1020     }
  1020     }
  1021 
  1021 
  1022     return result;
  1022     return result;
  1023 }
  1023 }
  1024 
  1024 
       
  1025 //this functions returns the path to the possible gapindex for the position pos
  1025 QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const
  1026 QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const
  1026 {
  1027 {
  1027     Qt::LayoutDirection dir = mainWindow->layoutDirection();
  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
  1028     for (int i = 0; i < QInternal::DockCount; ++i) {
  1031     for (int i = 0; i < QInternal::DockCount; ++i) {
  1029         QPoint p = pos;
  1032         QPoint p = pos;
  1030         if (docks[i].o == Qt::Horizontal)
  1033         if (docks[i].o == Qt::Horizontal)
  1031             p = QStyle::visualPos(dir, docks[i].rect, p);
  1034             p = QStyle::visualPos(dir, docks[i].rect, p);
  1032         QList<int> result = docks[i].gapIndex(p);
  1035         QList<int> result = docks[i].gapIndex(p, &minDistance);
  1033         if (!result.isEmpty()) {
  1036         if (!result.isEmpty()) {
  1034             result.prepend(i);
  1037             result.prepend(i);
  1035             return result;
  1038             ret = result;
  1036         }
  1039         }
  1037     }
  1040     }
  1038 
  1041 
  1039     return QList<int>();
  1042     return ret;
  1040 }
  1043 }
  1041 
  1044 
  1042 QList<int> QToolBarAreaLayout::currentGapIndex() const
  1045 QList<int> QToolBarAreaLayout::currentGapIndex() const
  1043 {
  1046 {
  1044     for (int i = 0; i < QInternal::DockCount; ++i) {
  1047     for (int i = 0; i < QInternal::DockCount; ++i) {
  1296 bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker, bool pre43, bool testing)
  1299 bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker, bool pre43, bool testing)
  1297 {
  1300 {
  1298     QList<QToolBar*> toolBars = _toolBars;
  1301     QList<QToolBar*> toolBars = _toolBars;
  1299     int lines;
  1302     int lines;
  1300     stream >> lines;
  1303     stream >> lines;
       
  1304 	if (!testing)
       
  1305 	testing = mainWindow->unifiedTitleAndToolBarOnMac();
  1301 
  1306 
  1302     for (int j = 0; j < lines; ++j) {
  1307     for (int j = 0; j < lines; ++j) {
  1303         int pos;
  1308         int pos;
  1304         stream >> pos;
  1309         stream >> pos;
  1305         if (pos < 0 || pos >= QInternal::DockCount)
  1310         if (pos < 0 || pos >= QInternal::DockCount)
  1306             return false;
  1311             return false;
  1307         int cnt;
  1312         int cnt;
  1308         stream >> cnt;
  1313         stream >> cnt;
  1309 
  1314 
  1310         QToolBarAreaLayoutInfo &dock = docks[pos];
  1315         QToolBarAreaLayoutInfo &dock = docks[pos];
       
  1316 		const bool applyingLayout = !testing && !(pos == QInternal::TopDock && mainWindow->unifiedTitleAndToolBarOnMac());
  1311         QToolBarAreaLayoutLine line(dock.o);
  1317         QToolBarAreaLayoutLine line(dock.o);
  1312 
  1318 
  1313         for (int k = 0; k < cnt; ++k) {
  1319         for (int k = 0; k < cnt; ++k) {
  1314             QToolBarAreaLayoutItem item;
  1320             QToolBarAreaLayoutItem item;
  1315 
  1321 
  1346             }
  1352             }
  1347             if (toolBar == 0) {
  1353             if (toolBar == 0) {
  1348                 continue;
  1354                 continue;
  1349             }
  1355             }
  1350 
  1356 
  1351             if (!testing) {
  1357             if (applyingLayout) {
  1352                 item.widgetItem = new QWidgetItemV2(toolBar);
  1358                 item.widgetItem = new QWidgetItemV2(toolBar);
  1353                 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
  1359                 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
  1354                 toolBar->setVisible(shown & 1);
  1360                 toolBar->setVisible(shown & 1);
  1355                 toolBar->d_func()->setWindowState(floating, true, rect);
  1361                 toolBar->d_func()->setWindowState(floating, true, rect);
  1356 
  1362 
  1357                 item.preferredSize = item.size;
  1363                 item.preferredSize = item.size;
  1358                 line.toolBarItems.append(item);
  1364                 line.toolBarItems.append(item);
  1359             }
  1365             }
  1360         }
  1366         }
  1361 
  1367 
  1362         if (!testing) {
  1368         if (applyingLayout) {
  1363             dock.lines.append(line);
  1369             dock.lines.append(line);
  1364         }
  1370         }
  1365     }
  1371     }
  1366 
  1372 
  1367 
  1373