Re: undocking/detaching toolviews to regular windows instead of tool windows

René J.V. Bertin <[email protected]>
Newsgroups gmane.comp.kde.users.kdevelop
Message-ID <2677465.Ct1BC1I0qx@bola>
On Thursday October 12 2017 15:43:16 Kevin Funk wrote:
>+        if (auto w = widget()) {
>+            // turn into top-level window
>+            w->setParent(nullptr);
>+            w->setWindowFlag(Qt::Window, true);
>+            w->show();
>

You'd want to add a close() after the w->show() to hide the now empty IdealDockWidget instance. And it (the instance) will need to save w, otherwise you'll get a crash when trying to re-attach the view:

@@ -140,6 +172,23 @@ void IdealDockWidget::contextMenuRequested(const QPoint &point)
     setShortcut->setToolTip(i18n("Use this shortcut to trigger visibility of the toolview."));
 
     menu.addSeparator();
+
+    QAction *separateWindow = nullptr;
+    if (isFloating()) {
+        separateWindow = menu.addAction(i18n("Turn into separate window"));
+        connect(separateWindow, &QAction::triggered, this, [this]() {
+            if (auto w = widget()) {
+                // turn into top-level window
+                qCWarning(SUBLIME) << "reparenting" << this << "->" << w << "away from" << w->parent();
+                m_windowWidget = w;
+                w->setParent(nullptr);
+                w->setWindowFlags(Qt::Window);
+                w->show();
+                close();
+            } } );
+    }
+
+    menu.addSeparator();
     QAction* remove = menu.addAction(QIcon::fromTheme(QStringLiteral("dialog-close")), i18n("Remove Toolview"));
 
     QAction* triggered = menu.exec(senderWidget->mapToGlobal(point));
@@ -176,11 +225,17 @@ void IdealDockWidget::contextMenuRequested(const QPoint &point)
 
             return;
         } else if ( triggered == detach ) {
-            setFloating(true);
-            m_area->raiseToolView(m_view);
+            if (!m_windowWidget) {
+                setFloating(true);
+                m_area->raiseToolView(m_view);
+            }
             return;
         }
 
+        if (m_windowWidget && triggered != separateWindow) {
+            setWidget(m_windowWidget);
+        }
+
         if (isFloating()) {
             setFloating(false);
         }
@@ -197,9 +252,11 @@ void IdealDockWidget::contextMenuRequested(const QPoint &point)
 
         Area *area = m_area;
         View *view = m_view;
-        /* This call will delete *this, so we no longer
-           can access member variables. */
-        m_area->moveToolView(m_view, pos);
-        area->raiseToolView(view);
+        if (m_area) {
+            /* This call will delete *this, so we no longer
+               can access member variables. */
+            m_area->moveToolView(m_view, pos);
+            area->raiseToolView(view);
+        }
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.