[5.14.1] UI fixes

* restore settings, 1st toogle, then frameless, THEN restore geometry
* closeEvent: toggleFloating, then close
* setOffsetWhenFloating, also pass "frameless", if ever needed
This commit is contained in:
Klaus Basan
2020-02-09 20:09:15 +01:00
committed by Mat Sutcliffe
parent c3fb91e165
commit 1d5bbb6747
3 changed files with 44 additions and 15 deletions

View File

@@ -204,6 +204,12 @@ namespace BlackGui
m_preferredSizeWhenFloating = size; m_preferredSizeWhenFloating = size;
} }
void CDockWidget::setOffsetWhenFloating(const QPoint &point, bool frameless)
{
Q_UNUSED(frameless)
m_offsetWhenFloating = point;
}
void CDockWidget::setFrameless(bool frameless) void CDockWidget::setFrameless(bool frameless)
{ {
CEnableForFramelessWindow::setFrameless(frameless); CEnableForFramelessWindow::setFrameless(frameless);
@@ -290,6 +296,7 @@ namespace BlackGui
this->setFrameless(!frameless); this->setFrameless(!frameless);
} }
/**
void CDockWidget::toggleFramelessDeferred(int delayMs) void CDockWidget::toggleFramelessDeferred(int delayMs)
{ {
QPointer<CDockWidget> myself(this); QPointer<CDockWidget> myself(this);
@@ -298,6 +305,7 @@ namespace BlackGui
if (myself) { myself->toggleFrameless(); } if (myself) { myself->toggleFrameless(); }
}); });
} }
**/
void CDockWidget::windowAlwaysOnTop() void CDockWidget::windowAlwaysOnTop()
{ {
@@ -335,18 +343,33 @@ namespace BlackGui
if (s.isFloating() != this->isFloating()) if (s.isFloating() != this->isFloating())
{ {
this->toggleFloating(); this->toggleFloating();
QPointer<CDockWidget> myself(this);
QTimer::singleShot(500, this, [ = ]
{
if (myself) { myself->restoreFromSettings(); }
});
return true;
} }
if (s.isFramless() != this->isFrameless())
{
this->toggleFrameless();
QPointer<CDockWidget> myself(this);
QTimer::singleShot(500, this, [ = ]
{
if (myself) { myself->restoreFromSettings(); }
});
return true;
}
// now frameless and floating is correct
const QByteArray geo(s.getGeometry()); const QByteArray geo(s.getGeometry());
if (!geo.isEmpty()) if (!geo.isEmpty())
{ {
const bool ok = this->restoreGeometry(geo); const bool ok = this->restoreGeometry(geo);
if (ok) { this->rememberFloatingSizeAndPosition(); } if (ok) { this->rememberFloatingSizeAndPosition(); }
} }
if (s.isFramless() != this->isFrameless())
{
// not working if directly called
this->toggleFramelessDeferred();
}
this->setMargins(); this->setMargins();
return true; return true;
} }
@@ -356,12 +379,15 @@ namespace BlackGui
if (this->isFloating()) if (this->isFloating())
{ {
this->toggleFloating(); this->toggleFloating();
QPointer<CDockWidget> myself(this);
QTimer::singleShot(500, this, [ = ]
{
if (myself) { myself->close(); }
});
event->setAccepted(false); // refuse -> do not close event->setAccepted(false); // refuse -> do not close
return;
} }
else QDockWidget::closeEvent(event);
{
QDockWidget::closeEvent(event);
}
} }
void CDockWidget::paintEvent(QPaintEvent *event) void CDockWidget::paintEvent(QPaintEvent *event)
@@ -675,9 +701,12 @@ namespace BlackGui
void CDockWidget::saveCurrentStateToSettings() void CDockWidget::saveCurrentStateToSettings()
{ {
CDockWidgetSettings s = this->getSettings(); CDockWidgetSettings s = this->getSettings();
s.setFloating(this->isFloating()); const bool floating = this->isFloating();
s.setFrameless(this->isFrameless()); const bool frameless = this->isFrameless();
s.setGeometry(this->saveGeometry()); const QByteArray geo = this->saveGeometry();
s.setFloating(floating);
s.setFrameless(frameless);
s.setGeometry(geo);
this->saveSettings(s); this->saveSettings(s);
} }

View File

@@ -94,7 +94,7 @@ namespace BlackGui
void setPreferredSizeWhenFloating(const QSize &size); void setPreferredSizeWhenFloating(const QSize &size);
//! Position offset when floating first time //! Position offset when floating first time
void setOffsetWhenFloating(const QPoint &point) { m_offsetWhenFloating = point; } void setOffsetWhenFloating(const QPoint &point, bool frameless);
//! \copydoc CEnableForFramelessWindow::setFrameless //! \copydoc CEnableForFramelessWindow::setFrameless
virtual void setFrameless(bool frameless) override; virtual void setFrameless(bool frameless) override;
@@ -109,7 +109,7 @@ namespace BlackGui
void toggleFrameless(); void toggleFrameless();
//! Toggle frameless deferred //! Toggle frameless deferred
void toggleFramelessDeferred(int delayMs = 1000); // void toggleFramelessDeferred(int delayMs = 1000);
//! Window always on top //! Window always on top
void windowAlwaysOnTop(); void windowAlwaysOnTop();

View File

@@ -578,7 +578,7 @@ namespace BlackGui
const QPoint offset(i * 10, i * 10); const QPoint offset(i * 10, i * 10);
// after->setVisible(false); // after->setVisible(false);
// after->setFloating(true); // after->setFloating(true);
after->setOffsetWhenFloating(offset); after->setOffsetWhenFloating(offset, after->isFrameless());
const QSize floatingSize = this->getPreferredSizeWhenFloating(i); const QSize floatingSize = this->getPreferredSizeWhenFloating(i);
after->setPreferredSizeWhenFloating(floatingSize); after->setPreferredSizeWhenFloating(floatingSize);
after->initialFloating(); after->initialFloating();