Pause video while caption is expanded.

This commit is contained in:
John Preston 2023-07-21 16:40:20 +04:00
parent 75dc7e6e81
commit 21fa3264e3
6 changed files with 40 additions and 8 deletions

View File

@ -68,13 +68,17 @@ void CaptionFullView::resizeEvent(QResizeEvent *e) {
void CaptionFullView::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
_close();
if (const auto onstack = _close) {
onstack();
}
}
}
void CaptionFullView::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::LeftButton) {
_close();
if (const auto onstack = _close) {
onstack();
}
}
}

View File

@ -345,10 +345,11 @@ Controller::~Controller() {
}
void Controller::updateContentFaded() {
if (_contentFaded == _replyActive) {
const auto faded = _replyActive || _captionFullView || _captionExpanded;
if (_contentFaded == faded) {
return;
}
_contentFaded = _replyActive;
_contentFaded = faded;
_contentFadeAnimation.start(
[=] { _delegate->storiesRepaint(); },
_contentFaded ? 0. : 1.,
@ -570,16 +571,24 @@ TextWithEntities Controller::captionText() const {
return _captionText;
}
void Controller::setCaptionExpanded(bool expanded) {
if (_captionExpanded == expanded) {
return;
}
_captionExpanded = expanded;
updateContentFaded();
}
void Controller::showFullCaption() {
if (_captionText.empty()) {
return;
}
togglePaused(true);
_captionFullView = std::make_unique<CaptionFullView>(
wrap(),
&_delegate->storiesShow()->session(),
_captionText,
[=] { togglePaused(false); });
[=] { _captionFullView = nullptr; updateContentFaded(); });
updateContentFaded();
}
std::shared_ptr<ChatHelpers::Show> Controller::uiShow() const {
@ -796,6 +805,9 @@ void Controller::show(
_captionText = story->caption();
_captionFullView = nullptr;
_captionExpanded = false;
_contentFaded = false;
_contentFadeAnimation.stop();
const auto document = story->document();
_header->show({
.user = user,
@ -942,6 +954,8 @@ void Controller::updatePlayingAllowed() {
&& _windowActive
&& !_paused
&& !_replyActive
&& !_captionFullView
&& !_captionExpanded
&& !_layerShown
&& !_menuShown);
}

View File

@ -122,6 +122,7 @@ public:
[[nodiscard]] bool closeByClickAt(QPoint position) const;
[[nodiscard]] Data::FileOrigin fileOrigin() const;
[[nodiscard]] TextWithEntities captionText() const;
void setCaptionExpanded(bool expanded);
void showFullCaption();
[[nodiscard]] std::shared_ptr<ChatHelpers::Show> uiShow() const;
@ -241,6 +242,7 @@ private:
Ui::Animations::Simple _contentFadeAnimation;
bool _contentFaded = false;
bool _captionExpanded = false;
bool _windowActive = false;
bool _replyFocused = false;
bool _replyActive = false;

View File

@ -123,6 +123,10 @@ TextWithEntities View::captionText() const {
return _controller->captionText();
}
void View::setCaptionExpanded(bool expanded) {
_controller->setCaptionExpanded(expanded);
}
void View::showFullCaption() {
_controller->showFullCaption();
}

View File

@ -64,6 +64,7 @@ public:
[[nodiscard]] SiblingView sibling(SiblingType type) const;
[[nodiscard]] Data::FileOrigin fileOrigin() const;
[[nodiscard]] TextWithEntities captionText() const;
void setCaptionExpanded(bool expanded);
void showFullCaption();
void updatePlayback(const Player::TrackState &state);

View File

@ -486,6 +486,10 @@ OverlayWidget::OverlayWidget()
return base::EventFilterResult::Cancel;
} else if (type == QEvent::ThemeChange && Platform::IsLinux()) {
_window->setWindowIcon(Window::CreateIcon(_session));
} else if (type == QEvent::FocusOut) {
if (const auto popup = QApplication::activePopupWidget()) {
int a = popup->x();
}
}
return base::EventFilterResult::Continue;
});
@ -1384,8 +1388,9 @@ void OverlayWidget::refreshCaptionGeometry() {
_captionFitsIfExpanded = _stories
&& (wantedHeight <= maxExpandedHeight);
_captionShownFull = (wantedHeight <= maxCollapsedHeight);
if (_captionShownFull) {
if (_captionShownFull && _captionExpanded && _stories) {
_captionExpanded = false;
_stories->setCaptionExpanded(false);
}
_captionRect = QRect(
(width() - captionWidth) / 2,
@ -3120,7 +3125,7 @@ void OverlayWidget::setCursor(style::cursor cursor) {
}
void OverlayWidget::setFocus() {
_widget->setFocus();
_body->setFocus();
}
bool OverlayWidget::takeFocusFrom(not_null<QWidget*> window) const {
@ -5570,10 +5575,12 @@ ClickHandlerPtr OverlayWidget::ensureCaptionExpandLink() {
return;
} else if (_captionExpanded) {
_captionExpanded = false;
_stories->setCaptionExpanded(false);
refreshCaptionGeometry();
update();
} else if (_captionFitsIfExpanded) {
_captionExpanded = true;
_stories->setCaptionExpanded(true);
refreshCaptionGeometry();
update();
} else {