From f2f5de707c5dc01f6c501f701798190e9fd51bd1 Mon Sep 17 00:00:00 2001 From: tanaxiusi <373923276@qq.com> Date: Wed, 16 Mar 2016 20:12:39 +0800 Subject: [PATCH 1/2] Fix bug after saving-restoring a empty container with no SectionWidget. SectionTitleWidget::mousePressEvent call 'grabMouse' to ensure the floaing widget can always follow the mouse after floated. SectionTitleWidget::mouseMoveEvent check Qt::LeftButton. --- AdvancedDockingSystem/src/ContainerWidget.cpp | 33 ++++++++++--------- .../src/SectionTitleWidget.cpp | 5 ++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index db59160..aa6dedb 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -489,25 +489,28 @@ bool ContainerWidget::restoreState(const QByteArray& data) int cnt = 0; in >> cnt; - // Create dummy section, required to call hideSectionContent() later. - SectionWidget* sw = new SectionWidget(this); - sections.append(sw); - - for (int i = 0; i < cnt; ++i) + if(cnt > 0) { - QString uname; - in >> uname; + // Create dummy section, required to call hideSectionContent() later. + SectionWidget* sw = new SectionWidget(this); + sections.append(sw); - const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname); - if (!sc) - continue; + for (int i = 0; i < cnt; ++i) + { + QString uname; + in >> uname; - InternalContentData data; - if (!takeContent(sc, data)) - qFatal("This should never happen!!!"); + const SectionContent::RefPtr sc = SCLookupMapByName(this).value(uname); + if (!sc) + continue; - sw->addContent(data, false); - contentsToHide.append(sc); + InternalContentData data; + if (!takeContent(sc, data)) + qFatal("This should never happen!!!"); + + sw->addContent(data, false); + contentsToHide.append(sc); + } } } else if (mode == 1) diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp index 69feef5..3ce750d 100644 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ b/AdvancedDockingSystem/src/SectionTitleWidget.cpp @@ -68,6 +68,7 @@ void SectionTitleWidget::setActiveTab(bool active) void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) { // qDebug() << Q_FUNC_INFO << ev->pos(); + this->grabMouse(); if (ev->button() == Qt::LeftButton) { _dragStartPos = ev->pos(); @@ -80,6 +81,8 @@ void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) { // qDebug() << Q_FUNC_INFO << ev->pos(); + if(QWidget::mouseGrabber() == this) + this->releaseMouse(); SectionWidget* section = NULL; // Drop contents of FloatingWidget into SectionWidget. @@ -189,7 +192,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) SectionWidget* section = NULL; // Move already existing FloatingWidget - if (_fw) + if (_fw && (ev->buttons() & Qt::LeftButton)) { const QPoint moveToPos = ev->globalPos() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); _fw->move(moveToPos); From 45f269835bc00ca21d07f63ec5eae277f4c788d1 Mon Sep 17 00:00:00 2001 From: mfreiholz Date: Wed, 16 Mar 2016 13:58:57 +0100 Subject: [PATCH 2/2] Using grabMouse() leads to more problems. I think there is a better way to ensure that the mouse sometimes doesn't lose the current dragging floating widget. --- AdvancedDockingSystem/src/SectionTitleWidget.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp index 3ce750d..5d13ca3 100644 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ b/AdvancedDockingSystem/src/SectionTitleWidget.cpp @@ -68,7 +68,6 @@ void SectionTitleWidget::setActiveTab(bool active) void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) { // qDebug() << Q_FUNC_INFO << ev->pos(); - this->grabMouse(); if (ev->button() == Qt::LeftButton) { _dragStartPos = ev->pos(); @@ -81,8 +80,6 @@ void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) { // qDebug() << Q_FUNC_INFO << ev->pos(); - if(QWidget::mouseGrabber() == this) - this->releaseMouse(); SectionWidget* section = NULL; // Drop contents of FloatingWidget into SectionWidget.