Subscribe window widget resize to window state changes

This commit is contained in:
Ilya Fedin 2021-08-08 00:34:42 +04:00 committed by John Preston
parent 3f85ce53d6
commit 381bfc43c5
2 changed files with 14 additions and 7 deletions

View file

@ -155,8 +155,12 @@ void DefaultWindowHelper::init() {
rpl::combine( rpl::combine(
window()->widthValue(), window()->widthValue(),
_windowState.value(),
_title->shownValue() _title->shownValue()
) | rpl::start_with_next([=](int width, bool shown) { ) | rpl::start_with_next([=](
int width,
Qt::WindowStates windowState,
bool shown) {
const auto area = resizeArea(); const auto area = resizeArea();
_title->setGeometry( _title->setGeometry(
area.left(), area.left(),
@ -167,10 +171,12 @@ void DefaultWindowHelper::init() {
rpl::combine( rpl::combine(
window()->sizeValue(), window()->sizeValue(),
_windowState.value(),
_title->heightValue(), _title->heightValue(),
_title->shownValue() _title->shownValue()
) | rpl::start_with_next([=]( ) | rpl::start_with_next([=](
QSize size, QSize size,
Qt::WindowStates windowState,
int titleHeight, int titleHeight,
bool titleShown) { bool titleShown) {
const auto area = resizeArea(); const auto area = resizeArea();
@ -207,8 +213,10 @@ void DefaultWindowHelper::init() {
} }
}, window()->lifetime()); }, window()->lifetime());
window()->shownValue( rpl::combine(
) | rpl::start_with_next([=](bool shown) { window()->shownValue(),
_windowState.value()
) | rpl::start_with_next([=](bool shown, Qt::WindowStates windowState) {
if (shown) { if (shown) {
updateWindowExtents(); updateWindowExtents();
} }
@ -223,10 +231,8 @@ void DefaultWindowHelper::init() {
if (mouseEvent->button() == Qt::LeftButton && edges) { if (mouseEvent->button() == Qt::LeftButton && edges) {
window()->windowHandle()->startSystemResize(edges); window()->windowHandle()->startSystemResize(edges);
} }
} else if (e->type() == QEvent::Move } else if (e->type() == QEvent::WindowStateChange) {
|| e->type() == QEvent::Resize _windowState = window()->windowState();
|| e->type() == QEvent::WindowStateChange) {
updateWindowExtents();
} }
}, window()->lifetime()); }, window()->lifetime());

View file

@ -91,6 +91,7 @@ private:
const not_null<RpWidget*> _body; const not_null<RpWidget*> _body;
bool _extentsSet = false; bool _extentsSet = false;
bool _nativeFrame = false; bool _nativeFrame = false;
rpl::variable<Qt::WindowStates> _windowState = Qt::WindowNoState;
}; };