From cd062ba451aa4d0fae1dc9e7e414f6e02ad003d3 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 3 Dec 2018 10:54:10 +0100 Subject: [PATCH] Ref T447, allow to set "on top" flag for floating dock widgets --- src/blackgui/dockwidget.cpp | 39 ++++++++++++++++++++++++------------- src/blackgui/dockwidget.h | 12 +++++++++++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/blackgui/dockwidget.cpp b/src/blackgui/dockwidget.cpp index 23d4d320c..14ce70466 100644 --- a/src/blackgui/dockwidget.cpp +++ b/src/blackgui/dockwidget.cpp @@ -249,8 +249,9 @@ namespace BlackGui void CDockWidget::toggleFloating() { const bool floating = !this->isFloating(); - if (!floating) { this->setFrameless(false); } + if (!floating) { this->setFrameless(false); } // remove frameless if not floating this->setFloating(floating); + this->setAlwaysOnTop(m_alwaysOnTop); } void CDockWidget::toggleVisibility() @@ -267,13 +268,28 @@ namespace BlackGui void CDockWidget::toggleFrameless() { - if (this->isFrameless()) + const bool frameless = this->isFrameless(); + this->setFrameless(!frameless); + } + + void CDockWidget::toggleAlwaysOnTop() + { + m_alwaysOnTop = !m_alwaysOnTop; + if (this->isFloating()) { - this->setFrameless(false); + this->setAlwaysOnTopFlag(m_alwaysOnTop); + } + } + + void CDockWidget::setAlwaysOnTopFlag(bool onTop) + { + if (onTop) + { + this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); } else { - this->setFrameless(true); + this->setWindowFlags(this->windowFlags() & ~Qt::WindowStaysOnTopHint); } } @@ -336,16 +352,13 @@ namespace BlackGui { if (this->isFloating()) { + const bool frameless = this->isFrameless(); + const bool onTop = this->windowFlags() | Qt::WindowStaysOnTopHint; + contextMenu->addAction(CIcons::dockTop16(), "Dock", this, &CDockWidget::toggleFloating); - if (this->isFrameless()) - { - contextMenu->addAction(CIcons::tableSheet16(), "Normal window", this, &CDockWidget::toggleFrameless); - } - else - { - contextMenu->addAction(CIcons::tableSheet16(), "Frameless", this, &CDockWidget::toggleFrameless); - } - contextMenu->addAction(CIcons::refresh16(), "Redraw", this, SLOT(update())); + contextMenu->addAction(CIcons::tableSheet16(), frameless ? "Normal window" : "Frameless", this, &CDockWidget::toggleFrameless); + contextMenu->addAction(CIcons::dockTop16(), onTop ? "Not on top" : "Always on top", this, &CDockWidget::toggleAlwaysOnTop); + contextMenu->addAction(CIcons::refresh16(), "Redraw", this, QOverload<>::of(&CDockWidget::update)); } else { diff --git a/src/blackgui/dockwidget.h b/src/blackgui/dockwidget.h index 93fbe90de..8796e6af4 100644 --- a/src/blackgui/dockwidget.h +++ b/src/blackgui/dockwidget.h @@ -108,6 +108,12 @@ namespace BlackGui //! Toggle frameless mode (EXPERIMENTAL) void toggleFrameless(); + //! Toggle always on top + void toggleAlwaysOnTop(); + + //! Set always on top + void setAlwaysOnTop(bool onTop) { m_alwaysOnTop = onTop; } + //! Restore from settings bool restoreFromSettings(); @@ -181,7 +187,10 @@ namespace BlackGui //! Margins when docked QMargins getMarginsWhenDocked() const; - //! Override close event + //! Set the on top flag + void setAlwaysOnTopFlag(bool onTop); + + //! \copydoc QWidget::closeEvent virtual void closeEvent(QCloseEvent *event) override; //! \copydoc QWidget::paintEvent @@ -219,6 +228,7 @@ namespace BlackGui bool m_selected = false; //!< selected when tabbed bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible() bool m_wasFrameless = false; //!< frameless when last floating + bool m_alwaysOnTop = false; //!< only effective if floating CManagedStatusBar m_statusBar; //!< status bar when floating QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes QSize m_preferredSizeWhenFloating; //!< preferred size when floating 1st time