From 16e1c740cee4d728104ba3b2e82162cccc195ea7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 10 Mar 2021 21:06:34 +0400 Subject: [PATCH] Support sharing speaker/listener link. --- Telegram/SourceFiles/boxes/share_box.cpp | 29 +++++++++++++++---- Telegram/SourceFiles/boxes/share_box.h | 2 ++ .../calls/calls_group_settings.cpp | 14 +++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 9c99c85dab..530bec7f93 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -168,7 +168,13 @@ ShareBox::ShareBox(QWidget*, Descriptor &&descriptor) Ui::InputField::Mode::MultiLine, tr::lng_photos_comment()), st::shareCommentPadding) +, _bottomWidget(std::move(_descriptor.bottomWidget)) , _searchTimer([=] { searchByUsername(); }) { + if (_bottomWidget) { + _bottomWidget->setParent(this); + _bottomWidget->resizeToWidth(st::boxWideWidth); + _bottomWidget->show(); + } } void ShareBox::prepareCommentField() { @@ -179,9 +185,14 @@ void ShareBox::prepareCommentField() { rpl::combine( heightValue(), _comment->heightValue(), - _1 - _2 - ) | rpl::start_with_next([=](int top) { - _comment->moveToLeft(0, top); + (_bottomWidget + ? _bottomWidget->heightValue() + : (rpl::single(0) | rpl::type_erased())) + ) | rpl::start_with_next([=](int height, int comment, int bottom) { + _comment->moveToLeft(0, height - bottom - comment); + if (_bottomWidget) { + _bottomWidget->moveToLeft(0, height - bottom); + } }, _comment->lifetime()); const auto field = _comment->entity(); @@ -210,6 +221,9 @@ void ShareBox::prepareCommentField() { InitSpellchecker(_descriptor.navigation->parentController(), field); } Ui::SendPendingMoveResizeEvents(_comment); + if (_bottomWidget) { + Ui::SendPendingMoveResizeEvents(_bottomWidget); + } } void ShareBox::prepare() { @@ -251,7 +265,11 @@ void ShareBox::prepare() { _inner->selectActive(); } }); - _comment->heightValue( + rpl::combine( + _comment->heightValue(), + (_bottomWidget + ? _bottomWidget->heightValue() + : rpl::single(0) | rpl::type_erased()) ) | rpl::start_with_next([=] { updateScrollSkips(); }, _comment->lifetime()); @@ -283,7 +301,8 @@ int ShareBox::getTopScrollSkip() const { } int ShareBox::getBottomScrollSkip() const { - return _comment->isHidden() ? 0 : _comment->height(); + return (_comment->isHidden() ? 0 : _comment->height()) + + (_bottomWidget ? _bottomWidget->height() : 0); } int ShareBox::contentHeight() const { diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index c680c32b72..186d9254eb 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -68,6 +68,7 @@ public: Window::SessionNavigation *navigation = nullptr; Fn)> initSpellchecker; Fn)> initEditLink; + object_ptr bottomWidget = { nullptr }; }; ShareBox(QWidget*, Descriptor &&descriptor); @@ -113,6 +114,7 @@ private: object_ptr _select; object_ptr> _comment; + object_ptr _bottomWidget; class Inner; QPointer _inner; diff --git a/Telegram/SourceFiles/calls/calls_group_settings.cpp b/Telegram/SourceFiles/calls/calls_group_settings.cpp index 6155320ad8..49d3d2a5ce 100644 --- a/Telegram/SourceFiles/calls/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/calls_group_settings.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/level_meter.h" #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/buttons.h" +#include "ui/widgets/checkbox.h" #include "ui/widgets/input_fields.h" #include "ui/wrap/slide_wrap.h" #include "ui/text/text_utilities.h" @@ -99,8 +100,16 @@ object_ptr ShareInviteLinkBox( const auto sending = std::make_shared(); const auto box = std::make_shared>(); + auto bottom = object_ptr>( + nullptr, + object_ptr( + nullptr, + tr::lng_group_call_share_listener(tr::now), + true), + style::margins(16, 16, 16, 16));// #TODO calls style + const auto listenerCheckbox = bottom->entity(); const auto currentLink = [=] { - return linkListener; + return listenerCheckbox->checked() ? linkListener : linkSpeaker; }; auto copyCallback = [=] { QGuiApplication::clipboard()->setText(currentLink()); @@ -176,7 +185,8 @@ object_ptr ShareInviteLinkBox( .session = &peer->session(), .copyCallback = std::move(copyCallback), .submitCallback = std::move(submitCallback), - .filterCallback = std::move(filterCallback) }); + .filterCallback = std::move(filterCallback), + .bottomWidget = std::move(bottom) }); *box = result.data(); return result; }