feat: clear selected & close box after shot & scroll to bottom

This commit is contained in:
AlexeyZavar 2024-03-13 15:58:11 +03:00
parent 8bfb7e221b
commit 2414e51a9b
8 changed files with 28 additions and 12 deletions

View file

@ -411,7 +411,7 @@ QImage Make(not_null<QWidget*> box, const ShotConfig &config) {
return newResult; return newResult;
} }
void Wrapper(not_null<HistoryView::ListWidget*> widget) { void Wrapper(not_null<HistoryView::ListWidget*> widget, Fn<void()> clearSelected) {
const auto items = widget->getSelectedIds(); const auto items = widget->getSelectedIds();
if (items.empty()) { if (items.empty()) {
return; return;
@ -436,6 +436,10 @@ void Wrapper(not_null<HistoryView::ListWidget*> widget) {
messages, messages,
}; };
auto box = Box<MessageShotBox>(config); auto box = Box<MessageShotBox>(config);
box->boxClosing() | rpl::start_with_next([=]
{
clearSelected();
}, box->lifetime());
Ui::show(std::move(box)); Ui::show(std::move(box));
} }

View file

@ -19,7 +19,7 @@ struct ShotConfig
std::shared_ptr<Ui::ChatStyle> st; std::shared_ptr<Ui::ChatStyle> st;
std::vector<not_null<HistoryItem*>> messages; std::vector<not_null<HistoryItem*>> messages;
bool showBackground; bool showBackground = true;
bool showDate; bool showDate;
bool showReactions; bool showReactions;
}; };
@ -69,6 +69,6 @@ QColor makeDefaultBackgroundColor();
QImage Make(not_null<QWidget*> box, const ShotConfig &config); QImage Make(not_null<QWidget*> box, const ShotConfig &config);
void Wrapper(not_null<HistoryView::ListWidget*> widget); void Wrapper(not_null<HistoryView::ListWidget*> widget, Fn<void()> clearSelected);
} }

View file

@ -113,7 +113,7 @@ void MessageShotBox::setupContent() {
content, content,
tr::ayu_MessageShotShowBackground(), tr::ayu_MessageShotShowBackground(),
st::settingsButtonNoIcon st::settingsButtonNoIcon
)->toggleOn(rpl::single(false) )->toggleOn(rpl::single(_config.showBackground)
)->toggledValue( )->toggledValue(
) | start_with_next( ) | start_with_next(
[=](bool enabled) [=](bool enabled)
@ -128,7 +128,7 @@ void MessageShotBox::setupContent() {
content, content,
tr::ayu_MessageShotShowDate(), tr::ayu_MessageShotShowDate(),
st::settingsButtonNoIcon st::settingsButtonNoIcon
)->toggleOn(rpl::single(false) )->toggleOn(rpl::single(_config.showDate)
)->toggledValue( )->toggledValue(
) | start_with_next( ) | start_with_next(
[=](bool enabled) [=](bool enabled)
@ -143,7 +143,7 @@ void MessageShotBox::setupContent() {
content, content,
tr::ayu_MessageShotShowReactions(), tr::ayu_MessageShotShowReactions(),
st::settingsButtonNoIcon st::settingsButtonNoIcon
)->toggleOn(rpl::single(false) )->toggleOn(rpl::single(_config.showReactions)
)->toggledValue( )->toggledValue(
) | start_with_next( ) | start_with_next(
[=](bool enabled) [=](bool enabled)
@ -154,11 +154,12 @@ void MessageShotBox::setupContent() {
}, },
content->lifetime()); content->lifetime());
AddButtonWithIcon( const auto latestToggle = AddButtonWithIcon(
content, content,
tr::ayu_MessageShotShowColorfulReplies(), tr::ayu_MessageShotShowColorfulReplies(),
st::settingsButtonNoIcon st::settingsButtonNoIcon
)->toggleOn(rpl::single(savedShowColorfulReplies) );
latestToggle->toggleOn(rpl::single(savedShowColorfulReplies)
)->toggledValue( )->toggledValue(
) | start_with_next( ) | start_with_next(
[=](bool enabled) [=](bool enabled)
@ -186,11 +187,15 @@ void MessageShotBox::setupContent() {
if (!path.isEmpty()) { if (!path.isEmpty()) {
image.save(path); image.save(path);
} }
closeBox();
}); });
addButton(tr::ayu_MessageShotCopy(), addButton(tr::ayu_MessageShotCopy(),
[=] [=]
{ {
QGuiApplication::clipboard()->setImage(imageView->getImage()); QGuiApplication::clipboard()->setImage(imageView->getImage());
closeBox();
}); });
updatePreview(); updatePreview();
@ -210,4 +215,7 @@ void MessageShotBox::setupContent() {
content->lifetime()); content->lifetime());
setDimensionsToContent(boxWidth, content); setDimensionsToContent(boxWidth, content);
// scroll to the end
scrollToWidget(latestToggle);
} }

View file

@ -7927,6 +7927,10 @@ void HistoryWidget::messageShotSelected() {
messages messages
}; };
auto box = Box<MessageShotBox>(config); auto box = Box<MessageShotBox>(config);
box->boxClosing() | rpl::start_with_next([=]
{
clearSelected();
}, box->lifetime());
Ui::show(std::move(box)); Ui::show(std::move(box));
} }

View file

@ -149,7 +149,7 @@ PinnedWidget::PinnedWidget(
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->messageShotSelectionRequest( _topBar->messageShotSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
AyuFeatures::MessageShot::Wrapper(_inner); AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); });
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->forwardSelectionRequest( _topBar->forwardSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {

View file

@ -268,7 +268,7 @@ RepliesWidget::RepliesWidget(
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->messageShotSelectionRequest( _topBar->messageShotSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
AyuFeatures::MessageShot::Wrapper(_inner); AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); });
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->forwardSelectionRequest( _topBar->forwardSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {

View file

@ -127,7 +127,7 @@ ScheduledWidget::ScheduledWidget(
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->messageShotSelectionRequest( _topBar->messageShotSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
AyuFeatures::MessageShot::Wrapper(_inner); AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); });
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->clearSelectionRequest( _topBar->clearSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {

View file

@ -117,7 +117,7 @@ SublistWidget::SublistWidget(
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->messageShotSelectionRequest( _topBar->messageShotSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
AyuFeatures::MessageShot::Wrapper(_inner); AyuFeatures::MessageShot::Wrapper(_inner, [=] { clearSelected(); });
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->forwardSelectionRequest( _topBar->forwardSelectionRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {