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 5 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
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
30 changes: 22 additions & 8 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 @@ -1035,6 +1035,7 @@ void OverlayWidget::resizeContentByScreenSize() {
}
_x = (width() - _w) / 2;
_y = (height() - _h) / 2;
_initialZoom = _zoom;
}

float64 OverlayWidget::radialProgress() const {
Expand Down Expand Up @@ -1155,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) {
if (qFloor(full) == qCeil(full) && qRound(full) >= -kMaxZoomLevel && qRound(full) <= kMaxZoomLevel && full != 0.0) {
newZoom = qRound(full);
} else {
newZoom = kZoomToScreenLevel;
Expand Down Expand Up @@ -1271,8 +1272,8 @@ void OverlayWidget::close() {
}

void OverlayWidget::activateControls() {
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 @@ -1295,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 Down Expand Up @@ -3629,10 +3631,10 @@ 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();
Expand Down Expand Up @@ -3709,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){
aleksusklim marked this conversation as resolved.
Show resolved Hide resolved
_controlsState = ControlsShown;
}
onHideControls();
}
snapXY();
update();
}
Expand Down Expand Up @@ -4068,6 +4076,7 @@ bool OverlayWidget::updateOverState(OverState newState) {
if (!_stateAnimation.animating()) {
_stateAnimation.start();
}
activateControls();
}
updateCursor();
}
Expand Down Expand Up @@ -4204,7 +4213,7 @@ void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) {
_pressed = false;
}
_down = OverNone;
if (!isHidden()) {
if (!isHidden() || (isZoomedIn() && _controlsState == ControlsHidden)) {
activateControls();
}
}
Expand Down Expand Up @@ -4524,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
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 @@ -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 @@ -436,6 +437,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