undocking/detaching toolviews to regular windows instead of tool windows
René J.V. Bertin
rjvbertin at gmail.com
Thu Oct 12 16:05:41 BST 2017
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);
+ }
}
}
More information about the KDevelop
mailing list