Support sharing speaker/listener link.

This commit is contained in:
John Preston 2021-03-10 21:06:34 +04:00
parent 6786d44b69
commit 16e1c740ce
3 changed files with 38 additions and 7 deletions

View File

@ -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 {

View File

@ -68,6 +68,7 @@ public:
Window::SessionNavigation *navigation = nullptr;
Fn<void(not_null<Ui::InputField*>)> initSpellchecker;
Fn<void(not_null<Ui::InputField*>)> initEditLink;
object_ptr<Ui::RpWidget> bottomWidget = { nullptr };
};
ShareBox(QWidget*, Descriptor &&descriptor);
@ -113,6 +114,7 @@ private:
object_ptr<Ui::MultiSelect> _select;
object_ptr<Ui::SlideWrap<Ui::InputField>> _comment;
object_ptr<Ui::RpWidget> _bottomWidget;
class Inner;
QPointer<Inner> _inner;

View File

@ -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<ShareBox> ShareInviteLinkBox(
const auto sending = std::make_shared<bool>();
const auto box = std::make_shared<QPointer<ShareBox>>();
auto bottom = object_ptr<Ui::PaddingWrap<Ui::Checkbox>>(
nullptr,
object_ptr<Ui::Checkbox>(
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<ShareBox> 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;
}