From 8e096d65f24f31b6754632ee0010d937b0702410 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Mon, 30 Aug 2021 11:41:11 +0200
Subject: [PATCH] UI DockWidgetTitleBar: Disable float and close buttons

Those buttons seems to only work with the MPV view for some strange
reasons (don't hover with other views), so disable them for all. Now the
'float' operation is done by double-clicking and the close is done with
the view menu.
---
 src/UI/DockWidgetTitleBar.cc | 42 +-----------------------------------
 src/UI/DockWidgetTitleBar.hh |  6 ------
 2 files changed, 1 insertion(+), 47 deletions(-)

diff --git a/src/UI/DockWidgetTitleBar.cc b/src/UI/DockWidgetTitleBar.cc
index 203bc948..2e1cdaa0 100644
--- a/src/UI/DockWidgetTitleBar.cc
+++ b/src/UI/DockWidgetTitleBar.cc
@@ -14,51 +14,11 @@ DockWidgetTitleBar::DockWidgetTitleBar(QDockWidget *parent) noexcept
     qobject_cast<QHBoxLayout *>(layout())->setStretch(0, 1);
 }
 
-void
-DockWidgetTitleBar::handleFeaturesChanged(QDockWidget::DockWidgetFeatures feature) noexcept
-{
-    clearControls();
-
-    if (feature & QDockWidget::DockWidgetFloatable) {
-        QPushButton *const button = new QPushButton("float", this);
-        button->setEnabled(true);
-        connect(button, &QPushButton::clicked, attachedDock,
-                [this](bool) { attachedDock->setFloating(!attachedDock->isFloating()); });
-        layout()->addWidget(button);
-    }
-
-    if (feature & QDockWidget::DockWidgetClosable) {
-        QPushButton *const button = new QPushButton("close", this);
-        button->setEnabled(true);
-        connect(button, &QPushButton::clicked, attachedDock, [this](bool) {
-            QAction *const act = attachedDock->toggleViewAction();
-            Q_ASSERT(act->isCheckable());
-            act->trigger();
-        });
-        layout()->addWidget(button);
-    }
-}
-
-void
-DockWidgetTitleBar::clearControls() noexcept
-{
-    QHBoxLayout *const box = qobject_cast<QHBoxLayout *>(layout());
-    QLayoutItem *item      = nullptr;
-
-    for (int i = 1; i < box->count(); ++i) {
-        item = box->takeAt(i);
-        delete item->widget();
-        delete item;
-    }
-}
-
 void
 DockWidgetTitleBar::addToDock(QDockWidget *const dock) noexcept
 {
     DockWidgetTitleBar *const titleBar = new DockWidgetTitleBar(dock);
+    qDebug() << "Adding" << dock->windowTitle() << "to dock...";
     Utils::setTransparentBackgroundForWidget(titleBar);
-    connect(dock, &QDockWidget::featuresChanged, titleBar,
-            &DockWidgetTitleBar::handleFeaturesChanged);
     dock->setTitleBarWidget(titleBar);
-    titleBar->handleFeaturesChanged(dock->features());
 }
diff --git a/src/UI/DockWidgetTitleBar.hh b/src/UI/DockWidgetTitleBar.hh
index 97c2ad6d..7b9402c0 100644
--- a/src/UI/DockWidgetTitleBar.hh
+++ b/src/UI/DockWidgetTitleBar.hh
@@ -12,13 +12,7 @@ class DockWidgetTitleBar final : public QWidget {
     VIVY_UNMOVABLE_OBJECT(DockWidgetTitleBar)
 
     QDockWidget *attachedDock{ nullptr };
-    QDockWidget::DockWidgetFeature currentFeatures{ QDockWidget::NoDockWidgetFeatures };
-
     explicit DockWidgetTitleBar(QDockWidget *parent) noexcept;
-    void handleFeaturesChanged(QDockWidget::DockWidgetFeatures) noexcept;
-    void clearControls() noexcept;
-    void addCloseButton() noexcept;
-    void addFloatButton() noexcept;
 
 public:
     static void addToDock(QDockWidget *const) noexcept;
-- 
GitLab