From 2414e51a9b9a3d672a2b7dea5f0ca6223e69368d Mon Sep 17 00:00:00 2001 From: AlexeyZavar Date: Wed, 13 Mar 2024 15:58:11 +0300 Subject: [PATCH] feat: clear selected & close box after shot & scroll to bottom --- .../ayu/features/messageshot/message_shot.cpp | 6 +++++- .../ayu/features/messageshot/message_shot.h | 4 ++-- .../ayu/ui/boxes/message_shot_box.cpp | 18 +++++++++++++----- .../SourceFiles/history/history_widget.cpp | 4 ++++ .../view/history_view_pinned_section.cpp | 2 +- .../view/history_view_replies_section.cpp | 2 +- .../view/history_view_scheduled_section.cpp | 2 +- .../view/history_view_sublist_section.cpp | 2 +- 8 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp index d6ba46cbb1..1ea11aa040 100644 --- a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp +++ b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp @@ -411,7 +411,7 @@ QImage Make(not_null box, const ShotConfig &config) { return newResult; } -void Wrapper(not_null widget) { +void Wrapper(not_null widget, Fn clearSelected) { const auto items = widget->getSelectedIds(); if (items.empty()) { return; @@ -436,6 +436,10 @@ void Wrapper(not_null widget) { messages, }; auto box = Box(config); + box->boxClosing() | rpl::start_with_next([=] + { + clearSelected(); + }, box->lifetime()); Ui::show(std::move(box)); } diff --git a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h index 4ebe385a6b..4ae57eb291 100644 --- a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h +++ b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h @@ -19,7 +19,7 @@ struct ShotConfig std::shared_ptr st; std::vector> messages; - bool showBackground; + bool showBackground = true; bool showDate; bool showReactions; }; @@ -69,6 +69,6 @@ QColor makeDefaultBackgroundColor(); QImage Make(not_null box, const ShotConfig &config); -void Wrapper(not_null widget); +void Wrapper(not_null widget, Fn clearSelected); } diff --git a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp index 6dd9663cc7..099b626348 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp @@ -113,7 +113,7 @@ void MessageShotBox::setupContent() { content, tr::ayu_MessageShotShowBackground(), st::settingsButtonNoIcon - )->toggleOn(rpl::single(false) + )->toggleOn(rpl::single(_config.showBackground) )->toggledValue( ) | start_with_next( [=](bool enabled) @@ -128,7 +128,7 @@ void MessageShotBox::setupContent() { content, tr::ayu_MessageShotShowDate(), st::settingsButtonNoIcon - )->toggleOn(rpl::single(false) + )->toggleOn(rpl::single(_config.showDate) )->toggledValue( ) | start_with_next( [=](bool enabled) @@ -143,7 +143,7 @@ void MessageShotBox::setupContent() { content, tr::ayu_MessageShotShowReactions(), st::settingsButtonNoIcon - )->toggleOn(rpl::single(false) + )->toggleOn(rpl::single(_config.showReactions) )->toggledValue( ) | start_with_next( [=](bool enabled) @@ -154,11 +154,12 @@ void MessageShotBox::setupContent() { }, content->lifetime()); - AddButtonWithIcon( + const auto latestToggle = AddButtonWithIcon( content, tr::ayu_MessageShotShowColorfulReplies(), st::settingsButtonNoIcon - )->toggleOn(rpl::single(savedShowColorfulReplies) + ); + latestToggle->toggleOn(rpl::single(savedShowColorfulReplies) )->toggledValue( ) | start_with_next( [=](bool enabled) @@ -186,11 +187,15 @@ void MessageShotBox::setupContent() { if (!path.isEmpty()) { image.save(path); } + + closeBox(); }); addButton(tr::ayu_MessageShotCopy(), [=] { QGuiApplication::clipboard()->setImage(imageView->getImage()); + + closeBox(); }); updatePreview(); @@ -210,4 +215,7 @@ void MessageShotBox::setupContent() { content->lifetime()); setDimensionsToContent(boxWidth, content); + + // scroll to the end + scrollToWidget(latestToggle); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a0e154edce..f88f6555a3 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -7927,6 +7927,10 @@ void HistoryWidget::messageShotSelected() { messages }; auto box = Box(config); + box->boxClosing() | rpl::start_with_next([=] + { + clearSelected(); + }, box->lifetime()); Ui::show(std::move(box)); } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 039a5fd4d3..61495a93b0 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -149,7 +149,7 @@ PinnedWidget::PinnedWidget( }, _topBar->lifetime()); _topBar->messageShotSelectionRequest( ) | rpl::start_with_next([=] { - AyuFeatures::MessageShot::Wrapper(_inner); + AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); }); }, _topBar->lifetime()); _topBar->forwardSelectionRequest( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 3f39d58908..69fefa4788 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -268,7 +268,7 @@ RepliesWidget::RepliesWidget( }, _topBar->lifetime()); _topBar->messageShotSelectionRequest( ) | rpl::start_with_next([=] { - AyuFeatures::MessageShot::Wrapper(_inner); + AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); }); }, _topBar->lifetime()); _topBar->forwardSelectionRequest( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index d3f2dc4826..67bbde4b0a 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -127,7 +127,7 @@ ScheduledWidget::ScheduledWidget( }, _topBar->lifetime()); _topBar->messageShotSelectionRequest( ) | rpl::start_with_next([=] { - AyuFeatures::MessageShot::Wrapper(_inner); + AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); }); }, _topBar->lifetime()); _topBar->clearSelectionRequest( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp index 6a67d5a425..001ed666e1 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp @@ -117,7 +117,7 @@ SublistWidget::SublistWidget( }, _topBar->lifetime()); _topBar->messageShotSelectionRequest( ) | rpl::start_with_next([=] { - AyuFeatures::MessageShot::Wrapper(_inner); + AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); }); }, _topBar->lifetime()); _topBar->forwardSelectionRequest( ) | rpl::start_with_next([=] {