Skip to content

Commit

Permalink
Issue telegramdesktop#7931, Enhancement: Hide photo viewer overlay af…
Browse files Browse the repository at this point in the history
…ter zooming an image
  • Loading branch information
aleksusklim committed May 10, 2021
1 parent 95b4435 commit a2ad356
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 38 additions & 2 deletions Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1271,6 +1277,9 @@ void OverlayWidget::close() {
}

void OverlayWidget::activateControls() {
if (_controlsState == ControlsDisabled) {
return;
}
if (!_menu && !_mousePressed) {
_controlsHideTimer.callOnce(st::mediaviewWaitHide);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/media/view/media_view_overlay_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -498,6 +499,7 @@ private Q_SLOTS:
ControlsShown,
ControlsHiding,
ControlsHidden,
ControlsDisabled
};
ControlsState _controlsState = ControlsShown;
crl::time _controlsAnimStarted = 0;
Expand Down

0 comments on commit a2ad356

Please sign in to comment.