src/gui/widgets/qdockwidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   454     }
   454     }
   455 #endif
   455 #endif
   456 
   456 
   457     int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
   457     int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
   458 
   458 
   459     return qMax(buttonHeight + 2, titleFontMetrics.lineSpacing() + 2*mw);
   459     return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw);
   460 }
   460 }
   461 
   461 
   462 void QDockWidgetLayout::setGeometry(const QRect &geometry)
   462 void QDockWidgetLayout::setGeometry(const QRect &geometry)
   463 {
   463 {
   464     QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget());
   464     QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget());
   683     q->setFloating(!q->isFloating());
   683     q->setFloating(!q->isFloating());
   684 }
   684 }
   685 
   685 
   686 void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
   686 void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
   687 {
   687 {
   688     Q_Q(QDockWidget);
       
   689 
       
   690     if (state != 0)
   688     if (state != 0)
   691         return;
   689         return;
   692 
   690 
   693     QMainWindow *win = qobject_cast<QMainWindow*>(parent);
   691     QMainWindow *win = qobject_cast<QMainWindow*>(parent);
   694     Q_ASSERT(win != 0);
   692     Q_ASSERT(win != 0);
   695     QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
   693     QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
   696     Q_ASSERT(layout != 0);
   694     Q_ASSERT(layout != 0);
   697     if (layout->layoutState.indexOf(q).isEmpty()) //The dock widget has not been added into the main window
       
   698         return;
       
   699     if (layout->pluggingWidget != 0) // the main window is animating a docking operation
   695     if (layout->pluggingWidget != 0) // the main window is animating a docking operation
   700         return;
   696         return;
   701 
   697 
   702     state = new QDockWidgetPrivate::DragState;
   698     state = new QDockWidgetPrivate::DragState;
   703     state->pressPos = pos;
   699     state->pressPos = pos;
  1010 
  1006 
  1011 void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect &rect)
  1007 void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect &rect)
  1012 {
  1008 {
  1013     Q_Q(QDockWidget);
  1009     Q_Q(QDockWidget);
  1014 
  1010 
       
  1011     if (!floating && parent) {
       
  1012         QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
       
  1013         if (!mwlayout || mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea)
       
  1014             return; // this dockwidget can't be redocked
       
  1015     }
       
  1016 
  1015     bool wasFloating = q->isFloating();
  1017     bool wasFloating = q->isFloating();
  1016     bool hidden = q->isHidden();
  1018     bool hidden = q->isHidden();
  1017 
  1019 
  1018     if (q->isVisible())
  1020     if (q->isVisible())
  1019         q->hide();
  1021         q->hide();
  1221 {
  1223 {
  1222     Q_D(QDockWidget);
  1224     Q_D(QDockWidget);
  1223     features &= DockWidgetFeatureMask;
  1225     features &= DockWidgetFeatureMask;
  1224     if (d->features == features)
  1226     if (d->features == features)
  1225         return;
  1227         return;
       
  1228     const bool closableChanged = (d->features ^ features) & DockWidgetClosable;
  1226     d->features = features;
  1229     d->features = features;
  1227     QDockWidgetLayout *layout
  1230     QDockWidgetLayout *layout
  1228         = qobject_cast<QDockWidgetLayout*>(this->layout());
  1231         = qobject_cast<QDockWidgetLayout*>(this->layout());
  1229     layout->setVerticalTitleBar(features & DockWidgetVerticalTitleBar);
  1232     layout->setVerticalTitleBar(features & DockWidgetVerticalTitleBar);
  1230     d->updateButtons();
  1233     d->updateButtons();
  1231     d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable);
  1234     d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable);
  1232     emit featuresChanged(d->features);
  1235     emit featuresChanged(d->features);
  1233     update();
  1236     update();
       
  1237     if (closableChanged && layout->nativeWindowDeco()) {
       
  1238         //this ensures the native decoration is drawn
       
  1239         d->setWindowState(true /*floating*/, true /*unplug*/);
       
  1240     }
  1234 }
  1241 }
  1235 
  1242 
  1236 QDockWidget::DockWidgetFeatures QDockWidget::features() const
  1243 QDockWidget::DockWidgetFeatures QDockWidget::features() const
  1237 {
  1244 {
  1238     Q_D(const QDockWidget);
  1245     Q_D(const QDockWidget);