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

View File

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

View File

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