Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Hide photo viewer overlay after zooming an image #16303

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 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 @@ -3618,6 +3631,8 @@ 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 @@ -3639,6 +3654,12 @@ void OverlayWidget::keyPressEvent(QKeyEvent *e) {
} 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 @@ -3681,6 +3702,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 +4071,15 @@ 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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ControlsDisabled
ControlsDisabled,

};
ControlsState _controlsState = ControlsShown;
crl::time _controlsAnimStarted = 0;
Expand Down