Skip to content

Commit

Permalink
Second attempt to resolve telegramdesktop#7931. Make controls hiding …
Browse files Browse the repository at this point in the history
…time much shorter if the image was zoomed
  • Loading branch information
aleksusklim committed May 11, 2021
1 parent c45dc79 commit 361654a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 55 deletions.
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/media/view/media_view.style
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ mediaviewWaitHide: 2000;
mediaviewHideDuration: 1000;
mediaviewShowDuration: 200;
mediaviewFadeDuration: 150;
mediaviewZoomWait: 150;
mediaviewZoomHide: 150;
mediaviewZoomShow: 150;

mediaviewDeltaFromLastAction: 5px;
mediaviewSwipeDistance: 80px;
Expand Down
76 changes: 22 additions & 54 deletions Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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))) {
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -4114,6 +4076,7 @@ bool OverlayWidget::updateOverState(OverState newState) {
if (!_stateAnimation.animating()) {
_stateAnimation.start();
}
activateControls();
}
updateCursor();
}
Expand Down Expand Up @@ -4250,7 +4213,7 @@ void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) {
_pressed = false;
}
_down = OverNone;
if (!isHidden()) {
if (isHidden() && _controlsState == ControlsHidden) {
activateControls();
}
}
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -499,7 +500,6 @@ private Q_SLOTS:
ControlsShown,
ControlsHiding,
ControlsHidden,
ControlsDisabled
};
ControlsState _controlsState = ControlsShown;
crl::time _controlsAnimStarted = 0;
Expand Down

0 comments on commit 361654a

Please sign in to comment.