diff --git a/src/DockWidgetBase.cpp b/src/DockWidgetBase.cpp index e492d94a..e8950f84 100644 --- a/src/DockWidgetBase.cpp +++ b/src/DockWidgetBase.cpp @@ -23,7 +23,6 @@ #include "Frame_p.h" #include "FloatingWindow_p.h" #include "Logging_p.h" -#include "TabWidget_p.h" #include "Utils_p.h" #include "DockRegistry_p.h" #include "WidgetResizeHandler_p.h" @@ -94,7 +93,6 @@ public: void updateFloatAction(); void onDockWidgetShown(); void onDockWidgetHidden(); - TabWidget *parentTabWidget() const; void show(); void close(); void restoreToPreviousPosition(); @@ -327,8 +325,8 @@ void DockWidgetBase::setOptions(Options options) bool DockWidgetBase::isTabbed() const { - if (TabWidget* tabWidget = d->parentTabWidget()) { - return frame()->alwaysShowsTabs() || tabWidget->numDockWidgets() > 1; + if (Frame *frame = this->frame()) { + return frame->alwaysShowsTabs() || frame->dockWidgetCount() > 1; } else { if (!isFloating()) qWarning() << "DockWidget::isTabbed() Couldn't find any tab widget."; @@ -338,8 +336,8 @@ bool DockWidgetBase::isTabbed() const bool DockWidgetBase::isCurrentTab() const { - if (TabWidget* tabWidget = d->parentTabWidget()) { - return tabWidget->currentIndex() == tabWidget->indexOfDockWidget(const_cast(this)); + if (Frame *frame = this->frame()) { + return frame->currentIndex() == frame->indexOfDockWidget(const_cast(this)); } else { return true; } @@ -347,8 +345,8 @@ bool DockWidgetBase::isCurrentTab() const void DockWidgetBase::setAsCurrentTab() { - if (TabWidget* tabWidget = d->parentTabWidget()) - tabWidget->setCurrentDockWidget(this); + if (Frame *frame = this->frame()) + frame->setCurrentDockWidget(this); } void DockWidgetBase::setIcon(const QIcon &icon) @@ -547,9 +545,9 @@ void DockWidgetBase::Private::updateToggleAction() { QScopedValueRollback recursionGuard(m_updatingToggleAction, true); // Guard against recursiveness m_updatingToggleAction = true; - if ((q->isVisible() || parentTabWidget()) && !toggleAction->isChecked()) { + if ((q->isVisible() || q->frame()) && !toggleAction->isChecked()) { toggleAction->setChecked(true); - } else if ((!q->isVisible() && !parentTabWidget()) && toggleAction->isChecked()) { + } else if ((!q->isVisible() && !q->frame()) && toggleAction->isChecked()) { toggleAction->setChecked(false); } } @@ -583,14 +581,6 @@ void DockWidgetBase::Private::onDockWidgetHidden() qCDebug(hiding) << Q_FUNC_INFO << "parent=" << q->parentWidget(); } -TabWidget *DockWidgetBase::Private::parentTabWidget() const -{ - if (auto f = q->frame()) - return f->tabWidget(); - - return nullptr; -} - void DockWidgetBase::Private::close() { if (!m_isForceClosing && q->isFloating() && q->isVisible()) { // only user-closing is interesting to save the geometry @@ -602,8 +592,8 @@ void DockWidgetBase::Private::close() saveTabIndex(); // Do some cleaning. Widget is hidden, but we must hide the tab containing it. - if (auto tabWidget = parentTabWidget()) { - tabWidget->removeDockWidget(q); + if (Frame *frame = q->frame()) { + frame->removeWidget(q); q->setParent(nullptr); } } @@ -660,8 +650,8 @@ void DockWidgetBase::Private::maybeRestoreToPreviousPosition() int DockWidgetBase::Private::currentTabIndex() const { - TabWidget *tabWidget = parentTabWidget(); - return tabWidget ? tabWidget->indexOfDockWidget(q) : 0; + Frame *frame = q->frame(); + return frame ? frame->indexOfDockWidget(q) : 0; } void DockWidgetBase::Private::saveTabIndex() diff --git a/src/private/Frame_p.h b/src/private/Frame_p.h index 8497c500..baa84b6d 100644 --- a/src/private/Frame_p.h +++ b/src/private/Frame_p.h @@ -88,6 +88,15 @@ public: ///@brief detaches this dock widget virtual void detachTab(DockWidgetBase *) = 0; + ///@brief returns the index of the specified dock widget + virtual int indexOfDockWidget(DockWidgetBase *) = 0; + + ///@brief returns the index of the current tab + virtual int currentIndex() = 0; + + ///@brief Sets the specified dock widget to be the current tab + virtual void setCurrentDockWidget(DockWidgetBase *) = 0; + void updateTitleAndIcon(); void updateTitleBarVisibility(); bool containsMouse(QPoint globalPos) const; diff --git a/src/private/widgets/FrameWidget.cpp b/src/private/widgets/FrameWidget.cpp index 22956887..07f4202f 100644 --- a/src/private/widgets/FrameWidget.cpp +++ b/src/private/widgets/FrameWidget.cpp @@ -88,6 +88,21 @@ void FrameWidget::detachTab(DockWidgetBase *dw) tabWidget()->detachTab(dw); } +int FrameWidget::indexOfDockWidget(DockWidgetBase *dw) +{ + return tabWidget()->indexOfDockWidget(dw); +} + +void FrameWidget::setCurrentDockWidget(DockWidgetBase *dw) +{ + tabWidget()->setCurrentDockWidget(dw); +} + +int FrameWidget::currentIndex() +{ + return tabWidget()->currentIndex(); +} + QTabBar *FrameWidget::tabBar() const { auto tw = static_cast(tabWidget()->asWidget()); diff --git a/src/private/widgets/FrameWidget_p.h b/src/private/widgets/FrameWidget_p.h index 799632af..3c49677e 100644 --- a/src/private/widgets/FrameWidget_p.h +++ b/src/private/widgets/FrameWidget_p.h @@ -43,6 +43,9 @@ protected: void paintEvent(QPaintEvent *) override; QSize maxSizeHint() const override; void detachTab(DockWidgetBase *) override; + int indexOfDockWidget(DockWidgetBase *) override; + void setCurrentDockWidget(DockWidgetBase *) override; + int currentIndex() override; };