Ref T447, allow to set "on top" flag for floating dock widgets

This commit is contained in:
Klaus Basan
2018-12-03 10:54:10 +01:00
parent a8321f3563
commit cd062ba451
2 changed files with 37 additions and 14 deletions

View File

@@ -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
{

View File

@@ -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