From 361654a4e0345b30a163b4d587424f509c7483bf Mon Sep 17 00:00:00 2001 From: aleksusklim Date: Tue, 11 May 2021 18:32:46 +0500 Subject: [PATCH] Second attempt to resolve #7931. Make controls hiding time much shorter if the image was zoomed --- .../SourceFiles/media/view/media_view.style | 3 + .../media/view/media_view_overlay_widget.cpp | 76 ++++++------------- .../media/view/media_view_overlay_widget.h | 2 +- 3 files changed, 26 insertions(+), 55 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view.style b/Telegram/SourceFiles/media/view/media_view.style index 40efafa809b406..99e1c60253718c 100644 --- a/Telegram/SourceFiles/media/view/media_view.style +++ b/Telegram/SourceFiles/media/view/media_view.style @@ -247,6 +247,9 @@ mediaviewWaitHide: 2000; mediaviewHideDuration: 1000; mediaviewShowDuration: 200; mediaviewFadeDuration: 150; +mediaviewZoomWait: 150; +mediaviewZoomHide: 150; +mediaviewZoomShow: 150; mediaviewDeltaFromLastAction: 5px; mediaviewSwipeDistance: 80px; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 65dba9ec9f0219..4c8fb5bb409279 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -928,8 +928,8 @@ bool OverlayWidget::updateControlsAnimation(crl::time now) { return false; } const auto duration = (_controlsState == ControlsShowing) - ? st::mediaviewShowDuration - : st::mediaviewHideDuration; + ? (isZoomedIn() ? st::mediaviewZoomShow : st::mediaviewShowDuration) + : (isZoomedIn() ? st::mediaviewZoomHide : st::mediaviewHideDuration); const auto dt = float64(now - _controlsAnimStarted) / duration; if (dt >= 1) { @@ -1036,11 +1036,6 @@ void OverlayWidget::resizeContentByScreenSize() { _x = (width() - _w) / 2; _y = (height() - _h) / 2; _initialZoom = _zoom; - if (_controlsState == ControlsDisabled) { - _controlsState = ControlsHidden; - activateControls(); - updateCursor(); - } } float64 OverlayWidget::radialProgress() const { @@ -1161,7 +1156,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 && qRound(full) != 0) { + if (qFloor(full) == qCeil(full) && qRound(full) >= -kMaxZoomLevel && qRound(full) <= kMaxZoomLevel && full != 0.0) { newZoom = qRound(full); } else { newZoom = kZoomToScreenLevel; @@ -1277,11 +1272,8 @@ void OverlayWidget::close() { } void OverlayWidget::activateControls() { - if (_controlsState == ControlsDisabled) { - return; - } - if (!_menu && !_mousePressed) { - _controlsHideTimer.callOnce(st::mediaviewWaitHide); + if (!_menu && !_mousePressed && (_over == OverNone || _over == OverVideo)) { + _controlsHideTimer.callOnce(isZoomedIn() ? st::mediaviewZoomWait : st::mediaviewWaitHide); } if (_fullScreenVideo) { if (_streamed) { @@ -1304,6 +1296,7 @@ void OverlayWidget::onHideControls(bool force) { || (_streamed && _streamed->controls.hasMenu()) || _menu || _mousePressed + || (_over != OverNone && _over != OverVideo) || (_fullScreenVideo && !videoIsGifOrUserpic() && _streamed->controls.geometry().contains(_lastMouseMovePos))) { @@ -1313,11 +1306,7 @@ void OverlayWidget::onHideControls(bool force) { if (_fullScreenVideo) { _streamed->controls.hideAnimated(); } - if (_controlsState == ControlsHiding - || _controlsState == ControlsHidden - || _controlsState == ControlsDisabled) { - return; - } + if (_controlsState == ControlsHiding || _controlsState == ControlsHidden) return; _lastMouseMovePos = mapFromGlobal(QCursor::pos()); _controlsState = ControlsHiding; @@ -3631,8 +3620,6 @@ void OverlayWidget::keyPressEvent(QKeyEvent *e) { playbackPauseResume(); } else if (_document && !_document->loading() && (documentBubbleShown() || !_documentMedia->loaded())) { onDocClick(); - } else { - zoomReset(); } } else if (e->key() == Qt::Key_Left) { if (_controlsHideTimer.isActive()) { @@ -3644,22 +3631,16 @@ void OverlayWidget::keyPressEvent(QKeyEvent *e) { activateControls(); } moveToNext(1); - } else if (ctrl) { + } else if (ctrl || !_streamed) { if (e->key() == Qt::Key_Plus || e->key() == Qt::Key_Equal || e->key() == Qt::Key_Asterisk || e->key() == ']') { zoomIn(); - } else if (e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore) { + } else if (e->key() == Qt::Key_Minus || e->key() == Qt::Key_Underscore || e->key() == '[') { zoomOut(); } else if (e->key() == Qt::Key_0) { zoomReset(); } else if (e->key() == Qt::Key_I) { update(); } - } else if (e->key() == Qt::Key_Plus) { - zoomIn(); - } else if (e->key() == Qt::Key_Minus) { - zoomOut(); - } else if (e->key() == Qt::Key_Asterisk) { - zoomReset(); } } @@ -3702,22 +3683,6 @@ 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; @@ -3746,6 +3711,12 @@ void OverlayWidget::setZoomLevel(int newZoom, bool force) { _x = qRound(nx / (-z + 1) + width() / 2.); _y = qRound(ny / (-z + 1) + height() / 2.); } + if(isZoomedIn()){ + if(_controlsState == ControlsHiding){ + _controlsState = ControlsShown; + } + onHideControls(); + } snapXY(); update(); } @@ -4071,15 +4042,6 @@ void OverlayWidget::updateOverRect(OverState state) { bool OverlayWidget::updateOverState(OverState newState) { bool result = true; - if (_controlsState == ControlsDisabled - && newState != OverLeftNav - && newState != OverRightNav - && newState != OverClose - && newState != OverVideo) { - _over = OverNone; - updateCursor(); - return false; - } if (_over != newState) { if (newState == OverMore && !_ignoringDropdown) { _dropdownShowTimer.callOnce(0); @@ -4114,6 +4076,7 @@ bool OverlayWidget::updateOverState(OverState newState) { if (!_stateAnimation.animating()) { _stateAnimation.start(); } + activateControls(); } updateCursor(); } @@ -4250,7 +4213,7 @@ void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) { _pressed = false; } _down = OverNone; - if (!isHidden()) { + if (isHidden() && _controlsState == ControlsHidden) { activateControls(); } } @@ -4570,5 +4533,10 @@ float64 OverlayWidget::overLevel(OverState control) const { : i->second.current(); } +bool OverlayWidget::isZoomedIn() { + return ((_initialZoom == 0 && _zoom > 0) + || (_initialZoom != 0 && _zoom >= 0 && _zoom != _initialZoom)); +} + } // namespace View } // namespace Media diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 0d0ed13585e691..5ce8da01216f02 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -361,6 +361,7 @@ private Q_SLOTS: void updateOverRect(OverState state); bool updateOverState(OverState newState); float64 overLevel(OverState control) const; + bool isZoomedIn(); void checkGroupThumbsAnimation(); void initGroupThumbs(); @@ -499,7 +500,6 @@ private Q_SLOTS: ControlsShown, ControlsHiding, ControlsHidden, - ControlsDisabled }; ControlsState _controlsState = ControlsShown; crl::time _controlsAnimStarted = 0;