src/gui/widgets/qdockarealayout.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
  1165 
  1165 
  1166             // this is not yet a nested layout - make it
  1166             // this is not yet a nested layout - make it
  1167 
  1167 
  1168             QDockAreaLayoutInfo *subinfo = item.subinfo;
  1168             QDockAreaLayoutInfo *subinfo = item.subinfo;
  1169             QLayoutItem *widgetItem = item.widgetItem;
  1169             QLayoutItem *widgetItem = item.widgetItem;
  1170             QRect r = subinfo == 0 ? dockedGeometry(widgetItem->widget()) : subinfo->rect;
  1170             QPlaceHolderItem *placeHolderItem = item.placeHolderItem;
       
  1171             QRect r = subinfo == 0 ? widgetItem ? dockedGeometry(widgetItem->widget()) : placeHolderItem->topLevelRect : subinfo->rect;
  1171 
  1172 
  1172             Qt::Orientation opposite = o == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;
  1173             Qt::Orientation opposite = o == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;
  1173 #ifdef QT_NO_TABBAR
  1174 #ifdef QT_NO_TABBAR
  1174             const int tabBarShape = 0;
  1175             const int tabBarShape = 0;
  1175 #endif
  1176 #endif
  1176             QDockAreaLayoutInfo *new_info
  1177             QDockAreaLayoutInfo *new_info
  1177                 = new QDockAreaLayoutInfo(sep, dockPos, opposite, tabBarShape, mainWindow);
  1178                 = new QDockAreaLayoutInfo(sep, dockPos, opposite, tabBarShape, mainWindow);
  1178 
  1179 
       
  1180             //item become a new top-level
  1179             item.subinfo = new_info;
  1181             item.subinfo = new_info;
  1180             item.widgetItem = 0;
  1182             item.widgetItem = 0;
       
  1183             item.placeHolderItem = 0;
  1181 
  1184 
  1182             QDockAreaLayoutItem new_item
  1185             QDockAreaLayoutItem new_item
  1183                 = widgetItem == 0
  1186                 = widgetItem == 0
  1184                     ? QDockAreaLayoutItem(subinfo)
  1187                     ? QDockAreaLayoutItem(subinfo)
  1185                     : QDockAreaLayoutItem(widgetItem);
  1188                     : widgetItem ? QDockAreaLayoutItem(widgetItem) : QDockAreaLayoutItem(placeHolderItem);
  1186             new_item.size = pick(opposite, r.size());
  1189             new_item.size = pick(opposite, r.size());
  1187             new_item.pos = pick(opposite, r.topLeft());
  1190             new_item.pos = pick(opposite, r.topLeft());
  1188             new_info->item_list.append(new_item);
  1191             new_info->item_list.append(new_item);
  1189 #ifndef QT_NO_TABBAR
  1192 #ifndef QT_NO_TABBAR
  1190             if (insert_tabbed) {
  1193             if (insert_tabbed) {
  1298     int index = path.first();
  1301     int index = path.first();
  1299     if (index < 0)
  1302     if (index < 0)
  1300         index = -index - 1;
  1303         index = -index - 1;
  1301     if (index >= item_list.count())
  1304     if (index >= item_list.count())
  1302         return this;
  1305         return this;
  1303     if (path.count() == 1 || item_list.at(index).subinfo == 0)
  1306     if (path.count() == 1 || item_list[index].subinfo == 0)
  1304         return this;
  1307         return this;
  1305     return item_list.at(index).subinfo->info(path.mid(1));
  1308     return item_list[index].subinfo->info(path.mid(1));
  1306 }
  1309 }
  1307 
  1310 
  1308 QRect QDockAreaLayoutInfo::itemRect(int index) const
  1311 QRect QDockAreaLayoutInfo::itemRect(int index) const
  1309 {
  1312 {
  1310     const QDockAreaLayoutItem &item = item_list.at(index);
  1313     const QDockAreaLayoutItem &item = item_list.at(index);
  1554                         && (geo.right() < 0 || geo.bottom() < 0)) {
  1557                         && (geo.right() < 0 || geo.bottom() < 0)) {
  1555                 emit dw->visibilityChanged(true);
  1558                 emit dw->visibilityChanged(true);
  1556             }
  1559             }
  1557         }
  1560         }
  1558     }
  1561     }
  1559 
  1562 #ifndef QT_NO_TABBAR
  1560     if (sep == 1)
  1563     if (sep == 1)
  1561         updateSeparatorWidgets();
  1564         updateSeparatorWidgets();
       
  1565 #endif //QT_NO_TABBAR
  1562 }
  1566 }
  1563 
  1567 
  1564 static void paintSep(QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over)
  1568 static void paintSep(QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over)
  1565 {
  1569 {
  1566     QStyleOption opt(0);
  1570     QStyleOption opt(0);
  1838             item.subinfo->saveState(stream);
  1842             item.subinfo->saveState(stream);
  1839         }
  1843         }
  1840     }
  1844     }
  1841 }
  1845 }
  1842 
  1846 
  1843 #ifdef Q_WS_MAC
       
  1844 static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos)
  1847 static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos)
  1845 {
  1848 {
  1846     switch (pos) {
  1849     switch (pos) {
  1847         case QInternal::LeftDock:   return Qt::LeftDockWidgetArea;
  1850         case QInternal::LeftDock:   return Qt::LeftDockWidgetArea;
  1848         case QInternal::RightDock:  return Qt::RightDockWidgetArea;
  1851         case QInternal::RightDock:  return Qt::RightDockWidgetArea;
  1850         case QInternal::BottomDock: return Qt::BottomDockWidgetArea;
  1853         case QInternal::BottomDock: return Qt::BottomDockWidgetArea;
  1851         default: break;
  1854         default: break;
  1852     }
  1855     }
  1853     return Qt::NoDockWidgetArea;
  1856     return Qt::NoDockWidgetArea;
  1854 }
  1857 }
  1855 #endif
       
  1856 
  1858 
  1857 static QRect constrainedRect(QRect rect, const QRect &desktop)
  1859 static QRect constrainedRect(QRect rect, const QRect &desktop)
  1858 {
  1860 {
  1859     if (desktop.isValid()) {
  1861     if (desktop.isValid()) {
  1860         rect.setWidth(qMin(rect.width(), desktop.width()));
  1862         rect.setWidth(qMin(rect.width(), desktop.width()));
  1967                         widget->resize(r.size());
  1969                         widget->resize(r.size());
  1968                     }
  1970                     }
  1969 
  1971 
  1970                     if (!testing) {
  1972                     if (!testing) {
  1971                         widget->setVisible(flags & StateFlagVisible);
  1973                         widget->setVisible(flags & StateFlagVisible);
       
  1974                         item_list.append(item);
  1972                     }
  1975                     }
  1973                 } else {
  1976                 } else {
  1974                     int dummy;
  1977                     int dummy;
  1975                     stream >> item.pos >> item.size >> dummy >> dummy;
  1978                     stream >> item.pos >> item.size >> dummy >> dummy;
  1976                     if (!testing) {
  1979                     if (!testing) {
       
  1980                         item_list.append(item);
  1977                         widget->setFloating(false);
  1981                         widget->setFloating(false);
  1978                         widget->setVisible(flags & StateFlagVisible);
  1982                         widget->setVisible(flags & StateFlagVisible);
       
  1983                         emit widget->dockLocationChanged(toDockWidgetArea(dockPos));
  1979                     }
  1984                     }
  1980                 }
  1985                 }
  1981 
  1986 
  1982                 if (!testing) {
       
  1983                     item_list.append(item);
       
  1984                 }
       
  1985             }
  1987             }
  1986         } else if (nextMarker == SequenceMarker) {
  1988         } else if (nextMarker == SequenceMarker) {
  1987             int dummy;
  1989             int dummy;
  1988 #ifdef QT_NO_TABBAR
  1990 #ifdef QT_NO_TABBAR
  1989             const int tabBarShape = 0;
  1991             const int tabBarShape = 0;
  2006 #ifndef QT_NO_TABBAR
  2008 #ifndef QT_NO_TABBAR
  2007     if (!testing && tabbed && index >= 0 && index < item_list.count()) {
  2009     if (!testing && tabbed && index >= 0 && index < item_list.count()) {
  2008         updateTabBar();
  2010         updateTabBar();
  2009         setCurrentTabId(tabId(item_list.at(index)));
  2011         setCurrentTabId(tabId(item_list.at(index)));
  2010     }
  2012     }
  2011 #endif
       
  2012     if (!testing && sep == 1)
  2013     if (!testing && sep == 1)
  2013         updateSeparatorWidgets();
  2014         updateSeparatorWidgets();
       
  2015 #endif
  2014 
  2016 
  2015     return true;
  2017     return true;
  2016 }
  2018 }
  2017 
  2019 
       
  2020 #ifndef QT_NO_TABBAR
  2018 void QDockAreaLayoutInfo::updateSeparatorWidgets() const
  2021 void QDockAreaLayoutInfo::updateSeparatorWidgets() const
  2019 {
  2022 {
  2020     if (tabbed) {
  2023     if (tabbed) {
  2021         separatorWidgets.clear();
  2024         separatorWidgets.clear();
  2022         return;
  2025         return;
  2063         separatorWidgets[k]->hide();
  2066         separatorWidgets[k]->hide();
  2064     }
  2067     }
  2065     separatorWidgets.resize(j);
  2068     separatorWidgets.resize(j);
  2066     Q_ASSERT(separatorWidgets.size() == j);
  2069     Q_ASSERT(separatorWidgets.size() == j);
  2067 }
  2070 }
       
  2071 #endif //QT_NO_TABBAR
  2068 
  2072 
  2069 #ifndef QT_NO_TABBAR
  2073 #ifndef QT_NO_TABBAR
  2070 void QDockAreaLayoutInfo::updateTabBar() const
  2074 void QDockAreaLayoutInfo::updateTabBar() const
  2071 {
  2075 {
  2072     if (!tabbed)
  2076     if (!tabbed)
  2257 
  2261 
  2258 /******************************************************************************
  2262 /******************************************************************************
  2259 ** QDockAreaLayout
  2263 ** QDockAreaLayout
  2260 */
  2264 */
  2261 
  2265 
  2262 QDockAreaLayout::QDockAreaLayout(QMainWindow *win)
  2266 QDockAreaLayout::QDockAreaLayout(QMainWindow *win) : fallbackToSizeHints(true)
  2263 {
  2267 {
  2264     mainWindow = win;
  2268     mainWindow = win;
  2265     sep = win->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, win);
  2269     sep = win->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, win);
  2266 #ifndef QT_NO_TABBAR
  2270 #ifndef QT_NO_TABBAR
  2267     const int tabShape = QTabBar::RoundedSouth;
  2271     const int tabShape = QTabBar::RoundedSouth;
  2344             stream >> cornerData[i];
  2348             stream >> cornerData[i];
  2345         if (stream.status() == QDataStream::Ok) {
  2349         if (stream.status() == QDataStream::Ok) {
  2346             for (int i = 0; i < 4; ++i)
  2350             for (int i = 0; i < 4; ++i)
  2347                 corners[i] = static_cast<Qt::DockWidgetArea>(cornerData[i]);
  2351                 corners[i] = static_cast<Qt::DockWidgetArea>(cornerData[i]);
  2348         }
  2352         }
       
  2353 
       
  2354         if (!testing)
       
  2355             fallbackToSizeHints = false;
  2349     }
  2356     }
  2350 
  2357 
  2351     return ok;
  2358     return ok;
  2352 }
  2359 }
  2353 
  2360 
  2580 void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,
  2587 void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,
  2581                                 QVector<QLayoutStruct> *_hor_struct_list)
  2588                                 QVector<QLayoutStruct> *_hor_struct_list)
  2582 {
  2589 {
  2583     QSize center_hint(0, 0);
  2590     QSize center_hint(0, 0);
  2584     QSize center_min(0, 0);
  2591     QSize center_min(0, 0);
  2585     bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty();
  2592     const bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty();
  2586     if (have_central) {
  2593     if (have_central) {
  2587         center_hint = centralWidgetRect.size();
  2594         center_hint = centralWidgetRect.size();
  2588         if (!center_hint.isValid())
  2595         if (!center_hint.isValid())
  2589             center_hint = centralWidgetItem->sizeHint();
  2596             center_hint = centralWidgetItem->sizeHint();
  2590         center_min = centralWidgetItem->minimumSize();
  2597         center_min = centralWidgetItem->minimumSize();
  2599         center_rect.setRight(rect.right() - docks[QInternal::RightDock].rect.width() - sep);
  2606         center_rect.setRight(rect.right() - docks[QInternal::RightDock].rect.width() - sep);
  2600     if (!docks[QInternal::BottomDock].isEmpty())
  2607     if (!docks[QInternal::BottomDock].isEmpty())
  2601         center_rect.setBottom(rect.bottom() - docks[QInternal::BottomDock].rect.height() - sep);
  2608         center_rect.setBottom(rect.bottom() - docks[QInternal::BottomDock].rect.height() - sep);
  2602 
  2609 
  2603     QSize left_hint = docks[QInternal::LeftDock].size();
  2610     QSize left_hint = docks[QInternal::LeftDock].size();
  2604     if (left_hint.isNull())
  2611     if (left_hint.isNull() || fallbackToSizeHints)
  2605         left_hint = docks[QInternal::LeftDock].sizeHint();
  2612         left_hint = docks[QInternal::LeftDock].sizeHint();
  2606     QSize left_min = docks[QInternal::LeftDock].minimumSize();
  2613     QSize left_min = docks[QInternal::LeftDock].minimumSize();
  2607     QSize left_max = docks[QInternal::LeftDock].maximumSize();
  2614     QSize left_max = docks[QInternal::LeftDock].maximumSize();
  2608     left_hint = left_hint.boundedTo(left_max).expandedTo(left_min);
  2615     left_hint = left_hint.boundedTo(left_max).expandedTo(left_min);
  2609 
  2616 
  2610     QSize right_hint = docks[QInternal::RightDock].size();
  2617     QSize right_hint = docks[QInternal::RightDock].size();
  2611     if (right_hint.isNull())
  2618     if (right_hint.isNull() || fallbackToSizeHints)
  2612         right_hint = docks[QInternal::RightDock].sizeHint();
  2619         right_hint = docks[QInternal::RightDock].sizeHint();
  2613     QSize right_min = docks[QInternal::RightDock].minimumSize();
  2620     QSize right_min = docks[QInternal::RightDock].minimumSize();
  2614     QSize right_max = docks[QInternal::RightDock].maximumSize();
  2621     QSize right_max = docks[QInternal::RightDock].maximumSize();
  2615     right_hint = right_hint.boundedTo(right_max).expandedTo(right_min);
  2622     right_hint = right_hint.boundedTo(right_max).expandedTo(right_min);
  2616 
  2623 
  2617     QSize top_hint = docks[QInternal::TopDock].size();
  2624     QSize top_hint = docks[QInternal::TopDock].size();
  2618     if (top_hint.isNull())
  2625     if (top_hint.isNull() || fallbackToSizeHints)
  2619         top_hint = docks[QInternal::TopDock].sizeHint();
  2626         top_hint = docks[QInternal::TopDock].sizeHint();
  2620     QSize top_min = docks[QInternal::TopDock].minimumSize();
  2627     QSize top_min = docks[QInternal::TopDock].minimumSize();
  2621     QSize top_max = docks[QInternal::TopDock].maximumSize();
  2628     QSize top_max = docks[QInternal::TopDock].maximumSize();
  2622     top_hint = top_hint.boundedTo(top_max).expandedTo(top_min);
  2629     top_hint = top_hint.boundedTo(top_max).expandedTo(top_min);
  2623 
  2630 
  2624     QSize bottom_hint = docks[QInternal::BottomDock].size();
  2631     QSize bottom_hint = docks[QInternal::BottomDock].size();
  2625     if (bottom_hint.isNull())
  2632     if (bottom_hint.isNull() || fallbackToSizeHints)
  2626         bottom_hint = docks[QInternal::BottomDock].sizeHint();
  2633         bottom_hint = docks[QInternal::BottomDock].sizeHint();
  2627     QSize bottom_min = docks[QInternal::BottomDock].minimumSize();
  2634     QSize bottom_min = docks[QInternal::BottomDock].minimumSize();
  2628     QSize bottom_max = docks[QInternal::BottomDock].maximumSize();
  2635     QSize bottom_max = docks[QInternal::BottomDock].maximumSize();
  2629     bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min);
  2636     bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min);
       
  2637 
       
  2638     fallbackToSizeHints = !have_central;
  2630 
  2639 
  2631     if (_ver_struct_list != 0) {
  2640     if (_ver_struct_list != 0) {
  2632         QVector<QLayoutStruct> &ver_struct_list = *_ver_struct_list;
  2641         QVector<QLayoutStruct> &ver_struct_list = *_ver_struct_list;
  2633         ver_struct_list.resize(3);
  2642         ver_struct_list.resize(3);
  2634 
  2643 
  3071         docks[i].apply(animate);
  3080         docks[i].apply(animate);
  3072     if (centralWidgetItem != 0 && !centralWidgetItem->isEmpty()) {
  3081     if (centralWidgetItem != 0 && !centralWidgetItem->isEmpty()) {
  3073         widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect,
  3082         widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect,
  3074                                 animate);
  3083                                 animate);
  3075     }
  3084     }
  3076 
  3085 #ifndef QT_NO_TABBAR
  3077     if (sep == 1)
  3086     if (sep == 1)
  3078         updateSeparatorWidgets();
  3087         updateSeparatorWidgets();
       
  3088 #endif //QT_NO_TABBAR
  3079 }
  3089 }
  3080 
  3090 
  3081 void QDockAreaLayout::paintSeparators(QPainter *p, QWidget *widget,
  3091 void QDockAreaLayout::paintSeparators(QPainter *p, QWidget *widget,
  3082                                                 const QRegion &clip,
  3092                                                 const QRegion &clip,
  3083                                                 const QPoint &mouse) const
  3093                                                 const QPoint &mouse) const
  3151     apply(false);
  3161     apply(false);
  3152 
  3162 
  3153     return delta;
  3163     return delta;
  3154 }
  3164 }
  3155 
  3165 
       
  3166 #ifndef QT_NO_TABBAR
  3156 // Sets the correct positions for the seperator widgets
  3167 // Sets the correct positions for the seperator widgets
  3157 // Allocates new sepearator widgets with getSeparatorWidget
  3168 // Allocates new sepearator widgets with getSeparatorWidget
  3158 void QDockAreaLayout::updateSeparatorWidgets() const
  3169 void QDockAreaLayout::updateSeparatorWidgets() const
  3159 {
  3170 {
  3160     int j = 0;
  3171     int j = 0;
  3184     for (int i = j; i < separatorWidgets.size(); ++i)
  3195     for (int i = j; i < separatorWidgets.size(); ++i)
  3185         separatorWidgets.at(i)->hide();
  3196         separatorWidgets.at(i)->hide();
  3186 
  3197 
  3187     separatorWidgets.resize(j);
  3198     separatorWidgets.resize(j);
  3188 }
  3199 }
       
  3200 #endif //QT_NO_TABBAR
  3189 
  3201 
  3190 QLayoutItem *QDockAreaLayout::itemAt(int *x, int index) const
  3202 QLayoutItem *QDockAreaLayout::itemAt(int *x, int index) const
  3191 {
  3203 {
  3192     Q_ASSERT(x != 0);
  3204     Q_ASSERT(x != 0);
  3193 
  3205 
  3236         const QDockAreaLayoutInfo &dock = docks[i];
  3248         const QDockAreaLayoutInfo &dock = docks[i];
  3237         result += dock.usedTabBars();
  3249         result += dock.usedTabBars();
  3238     }
  3250     }
  3239     return result;
  3251     return result;
  3240 }
  3252 }
  3241 #endif
       
  3242 
  3253 
  3243 // Returns the set of all used separator widgets
  3254 // Returns the set of all used separator widgets
  3244 QSet<QWidget*> QDockAreaLayout::usedSeparatorWidgets() const
  3255 QSet<QWidget*> QDockAreaLayout::usedSeparatorWidgets() const
  3245 {
  3256 {
  3246     QSet<QWidget*> result;
  3257     QSet<QWidget*> result;
  3251         const QDockAreaLayoutInfo &dock = docks[i];
  3262         const QDockAreaLayoutInfo &dock = docks[i];
  3252         result += dock.usedSeparatorWidgets();
  3263         result += dock.usedSeparatorWidgets();
  3253     }
  3264     }
  3254     return result;
  3265     return result;
  3255 }
  3266 }
       
  3267 #endif
  3256 
  3268 
  3257 QRect QDockAreaLayout::gapRect(const QList<int> &path) const
  3269 QRect QDockAreaLayout::gapRect(const QList<int> &path) const
  3258 {
  3270 {
  3259     const QDockAreaLayoutInfo *info = this->info(path);
  3271     const QDockAreaLayoutInfo *info = this->info(path);
  3260     if (info == 0)
  3272     if (info == 0)