Delegated display of InviteLinkQrBox to caller.

This commit is contained in:
23rd 2022-03-06 08:54:48 +03:00
parent dc6788706c
commit 71ee2de354
3 changed files with 25 additions and 15 deletions

View File

@ -271,11 +271,15 @@ QImage QrForShare(const QString &text) {
void QrBox( void QrBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
const QString &link, const QString &link,
Fn<void(QImage)> share) { Fn<void(QImage, std::shared_ptr<Ui::BoxShow>)> share) {
box->setTitle(tr::lng_group_invite_qr_title()); box->setTitle(tr::lng_group_invite_qr_title());
box->addButton(tr::lng_about_done(), [=] { box->closeBox(); }); box->addButton(tr::lng_about_done(), [=] { box->closeBox(); });
const auto copyCallback = [=, show = std::make_shared<Ui::BoxShow>(box)] {
share(QrForShare(link), show);
};
const auto qr = Qr( const auto qr = Qr(
link, link,
st::inviteLinkQrPixel, st::inviteLinkQrPixel,
@ -295,9 +299,7 @@ void QrBox(
) | rpl::start_with_next([=](int width) { ) | rpl::start_with_next([=](int width) {
button->move((width - size) / 2, st::inviteLinkQrSkip); button->move((width - size) / 2, st::inviteLinkQrSkip);
}, button->lifetime()); }, button->lifetime());
button->setClickedCallback([=] { button->setClickedCallback(copyCallback);
share(QrForShare(link));
});
box->addRow( box->addRow(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
@ -306,9 +308,7 @@ void QrBox(
st::boxLabel), st::boxLabel),
st::inviteLinkQrValuePadding); st::inviteLinkQrValuePadding);
box->addLeftButton( box->addLeftButton(tr::lng_group_invite_context_copy(), copyCallback);
tr::lng_group_invite_context_copy(),
[=] { share(QrForShare(link)); });
} }
Controller::Controller( Controller::Controller(
@ -348,7 +348,9 @@ void Controller::addHeaderBlock(not_null<Ui::VerticalLayout*> container) {
ShareInviteLinkBox(_peer, link); ShareInviteLinkBox(_peer, link);
}); });
const auto getLinkQr = crl::guard(weak, [=] { const auto getLinkQr = crl::guard(weak, [=] {
InviteLinkQrBox(link); delegate()->peerListShowBox(
InviteLinkQrBox(link),
Ui::LayerOption::KeepOther);
}); });
const auto revokeLink = crl::guard(weak, [=] { const auto revokeLink = crl::guard(weak, [=] {
delegate()->peerListShowBox( delegate()->peerListShowBox(
@ -957,7 +959,9 @@ void AddPermanentLinkBlock(
}); });
const auto getLinkQr = crl::guard(weak, [=] { const auto getLinkQr = crl::guard(weak, [=] {
if (const auto current = value->current(); !current.link.isEmpty()) { if (const auto current = value->current(); !current.link.isEmpty()) {
InviteLinkQrBox(current.link); show->showBox(
InviteLinkQrBox(current.link),
Ui::LayerOption::KeepOther);
} }
}); });
const auto revokeLink = crl::guard(weak, [=] { const auto revokeLink = crl::guard(weak, [=] {
@ -1189,14 +1193,18 @@ void ShareInviteLinkBox(not_null<PeerData*> peer, const QString &link) {
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
} }
void InviteLinkQrBox(const QString &link) { object_ptr<Ui::BoxContent> InviteLinkQrBox(const QString &link) {
Ui::show(Box(QrBox, link, [=](const QImage &image) { return Box(QrBox, link, [=](
const QImage &image,
std::shared_ptr<Ui::BoxShow> show) {
auto mime = std::make_unique<QMimeData>(); auto mime = std::make_unique<QMimeData>();
mime->setImageData(image); mime->setImageData(image);
QGuiApplication::clipboard()->setMimeData(mime.release()); QGuiApplication::clipboard()->setMimeData(mime.release());
Ui::Toast::Show(tr::lng_group_invite_qr_copied(tr::now)); Ui::Toast::Show(
})); show->toastParent(),
tr::lng_group_invite_qr_copied(tr::now));
});
} }
object_ptr<Ui::BoxContent> EditLinkBox( object_ptr<Ui::BoxContent> EditLinkBox(

View File

@ -36,7 +36,7 @@ void AddPermanentLinkBlock(
void CopyInviteLink(const QString &link); void CopyInviteLink(const QString &link);
void ShareInviteLinkBox(not_null<PeerData*> peer, const QString &link); void ShareInviteLinkBox(not_null<PeerData*> peer, const QString &link);
void InviteLinkQrBox(const QString &link); [[nodiscard]] object_ptr<Ui::BoxContent> InviteLinkQrBox(const QString &link);
[[nodiscard]] object_ptr<Ui::BoxContent> RevokeLinkBox( [[nodiscard]] object_ptr<Ui::BoxContent> RevokeLinkBox(
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<UserData*> admin, not_null<UserData*> admin,

View File

@ -591,7 +591,9 @@ base::unique_qptr<Ui::PopupMenu> LinksController::createRowContextMenu(
ShareInviteLinkBox(_peer, link); ShareInviteLinkBox(_peer, link);
}, &st::menuIconShare); }, &st::menuIconShare);
result->addAction(tr::lng_group_invite_context_qr(tr::now), [=] { result->addAction(tr::lng_group_invite_context_qr(tr::now), [=] {
InviteLinkQrBox(link); delegate()->peerListShowBox(
InviteLinkQrBox(link),
Ui::LayerOption::KeepOther);
}, &st::menuIconQrCode); }, &st::menuIconQrCode);
result->addAction(tr::lng_group_invite_context_edit(tr::now), [=] { result->addAction(tr::lng_group_invite_context_edit(tr::now), [=] {
delegate()->peerListShowBox( delegate()->peerListShowBox(