From a2ad3568cd8dfa7d7c60748176470ae06f4d6ca5 Mon Sep 17 00:00:00 2001 From: aleksusklim Date: Mon, 10 May 2021 13:34:34 +0500 Subject: [PATCH] Issue #7931, Enhancement: Hide photo viewer overlay after zooming an image --- .../media/view/media_view_overlay_widget.cpp | 40 ++++++++++++++++++- .../media/view/media_view_overlay_widget.h | 2 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 21f04f85dbea22..5f9ed4115be91c 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1035,6 +1035,12 @@ void OverlayWidget::resizeContentByScreenSize() { } _x = (width() - _w) / 2; _y = (height() - _h) / 2; + _initialZoom = _zoom; + if (_controlsState == ControlsDisabled) { + _controlsState = ControlsHidden; + activateControls(); + updateCursor(); + } } float64 OverlayWidget::radialProgress() const { @@ -1155,7 +1161,7 @@ void OverlayWidget::zoomReset() { auto newZoom = _zoom; const auto full = _fullScreenVideo ? _zoomToScreen : _zoomToDefault; if (_zoom == 0) { - if (qFloor(full) == qCeil(full) && qRound(full) >= -kMaxZoomLevel && qRound(full) <= kMaxZoomLevel) { + if (qFloor(full) == qCeil(full) && qRound(full) >= -kMaxZoomLevel && qRound(full) <= kMaxZoomLevel && qRound(full) != 0) { newZoom = qRound(full); } else { newZoom = kZoomToScreenLevel; @@ -1271,6 +1277,9 @@ void OverlayWidget::close() { } void OverlayWidget::activateControls() { + if (_controlsState == ControlsDisabled) { + return; + } if (!_menu && !_mousePressed) { _controlsHideTimer.callOnce(st::mediaviewWaitHide); } @@ -1304,7 +1313,11 @@ void OverlayWidget::onHideControls(bool force) { if (_fullScreenVideo) { _streamed->controls.hideAnimated(); } - if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) return; + if (_controlsState == ControlsHiding + || _controlsState == ControlsHidden + || _controlsState == ControlsDisabled) { + return; + } _lastMouseMovePos = mapFromGlobal(QCursor::pos()); _controlsState = ControlsHiding; @@ -3681,6 +3694,22 @@ void OverlayWidget::setZoomLevel(int newZoom, bool force) { if (!force && _zoom == newZoom) { return; } + if (!_fullScreenVideo) { + if ((_initialZoom == 0 && newZoom > 0) + || (_initialZoom != 0 && newZoom >= 0 && newZoom != _initialZoom)) { + if (_controlsState != ControlsDisabled) { + activateControls(); + onHideControls(true); + updateControlsAnimation(_controlsAnimStarted + st::mediaviewHideDuration); + _controlsState = ControlsDisabled; + updateCursor(); + } + } else if (_controlsState == ControlsDisabled) { + _controlsState = ControlsHidden; + activateControls(); + updateCursor(); + } + } const auto full = _fullScreenVideo ? _zoomToScreen : _zoomToDefault; float64 nx, ny, z = (_zoom == kZoomToScreenLevel) ? full : _zoom; @@ -4034,6 +4063,13 @@ void OverlayWidget::updateOverRect(OverState state) { bool OverlayWidget::updateOverState(OverState newState) { bool result = true; + if (_controlsState == ControlsDisabled) { + if (newState != OverLeftNav && newState != OverRightNav && newState != OverClose){ + _over = OverNone; + updateCursor(); + return false; + } + } if (_over != newState) { if (newState == OverMore && !_ignoringDropdown) { _dropdownShowTimer.callOnce(0); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index dc9234e0adf41c..0d0ed13585e691 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -436,6 +436,7 @@ private Q_SLOTS: int _x = 0, _y = 0, _w = 0, _h = 0; int _xStart = 0, _yStart = 0; int _zoom = 0; // < 0 - out, 0 - none, > 0 - in + int _initialZoom = 0; float64 _zoomToScreen = 0.; // for documents float64 _zoomToDefault = 0.; QPoint _mStart; @@ -498,6 +499,7 @@ private Q_SLOTS: ControlsShown, ControlsHiding, ControlsHidden, + ControlsDisabled }; ControlsState _controlsState = ControlsShown; crl::time _controlsAnimStarted = 0;