Skip to content

Commit

Permalink
Make redocking floating windows with tabs possible
Browse files Browse the repository at this point in the history
TitleBar::isFloating() was returning false, while it should
have returned true.

Fixed by making isFloating() simpler and dumb. isFloating() should
only say if it belongs to a floating window or not. It shouldn't
contain any logic about whether button should be visible or not.

There's already logic elsewhere that will hide the float button
in case there's nesting.

Fixes issue #96 and #44
  • Loading branch information
iamsergio committed Mar 7, 2022
1 parent e6b8636 commit 0099a19
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/private/TitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void TitleBar::onCloseClicked()
bool TitleBar::isFloating() const
{
if (m_floatingWindow)
return m_floatingWindow->hasSingleDockWidget(); // Debatable! Maybe it's always floating.
return true;

if (m_frame)
return m_frame->isFloating();
Expand Down
2 changes: 1 addition & 1 deletion src/private/TitleBar_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DOCKS_EXPORT TitleBar : public QWidgetAdapter, public Draggable

DockWidgetBase *singleDockWidget() const override;

///@brief Returns true if the dock widget which has this title bar is floating
///@brief Returns true if this title-bar is the title bar of a floating window
bool isFloating() const;

///@brief the list of dockwidgets under this TitleBar.
Expand Down
20 changes: 20 additions & 0 deletions tests/tst_docks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7655,6 +7655,26 @@ void TestDocks::tst_resizePropagatesEvenly()
QVERIFY(qAbs(dock2->height() - dock1->height()) < 3);
}

void TestDocks::tst_unfloatTabbedFloatingWidgets()
{
auto m = createMainWindow(QSize(1000, 1000), MainWindowOption_None);
auto dock0 = createDockWidget("dock0", new MyWidget2());
auto dock1 = createDockWidget("dock1", new MyWidget2());
m->addDockWidget(dock0, Location_OnLeft);
dock0->addDockWidgetAsTab(dock1);

dock0->titleBar()->onFloatClicked();
QVERIFY(dock0->titleBar()->isFloating());
QVERIFY(!dock0->mainWindow());

dock0->titleBar()->onFloatClicked();
QVERIFY(!dock0->titleBar()->isFloating());
QVERIFY(dock0->mainWindow());



}

void TestDocks::tst_addMDIDockWidget()
{
EnsureTopLevelsDeleted e;
Expand Down
1 change: 1 addition & 0 deletions tests/tst_docks.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ private Q_SLOTS:
void tst_toggleTabbed();
void tst_toggleTabbed2();
void tst_resizePropagatesEvenly();
void tst_unfloatTabbedFloatingWidgets();

void tst_addMDIDockWidget();
void tst_redockToMDIRestoresPosition();
Expand Down

0 comments on commit 0099a19

Please sign in to comment.