diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 30f7522c4..e6ae95296 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -1035,6 +1035,22 @@ object_ptr DetailsFiller::setupInfo() { result.text->setContextCopyText(contextCopyText); return result; }; + const auto fitLabelToButton = [&]( + not_null button, + not_null label) { + const auto parent = label->parentWidget(); + result->sizeValue() | rpl::start_with_next([=] { + const auto s = parent->size(); + button->moveToRight( + 0, + (s.height() - button->height()) / 2); + label->resizeToWidth( + s.width() + - label->geometry().left() + - st::lineWidth * 2 + - button->width()); + }, button->lifetime()); + }; if (const auto user = _peer->asUser()) { const auto controller = _controller->parentController(); if (user->session().supportMode()) { @@ -1103,25 +1119,12 @@ object_ptr DetailsFiller::setupInfo() { usernameLine.text->setContextMenuHook(hook); usernameLine.subtext->setContextMenuHook(hook); if (user) { - const auto usernameLabel = usernameLine.text; - const auto parent = usernameLabel->parentWidget(); const auto copyUsername = Ui::CreateChild( - parent, + usernameLine.text->parentWidget(), user->isBot() ? st::infoProfileLabeledButtonCopy : st::infoProfileLabeledButtonQr); - result->sizeValue( - ) | rpl::start_with_next([=] { - const auto s = parent->size(); - copyUsername->moveToRight( - 0, - (s.height() - copyUsername->height()) / 2); - usernameLabel->resizeToWidth( - s.width() - - usernameLabel->geometry().left() - - st::lineWidth * 2 - - copyUsername->width()); - }, copyUsername->lifetime()); + fitLabelToButton(copyUsername, usernameLine.text); copyUsername->setClickedCallback([=] { if (!user->isBot()) { controller->show(Box([=](not_null box) { @@ -1187,7 +1190,7 @@ object_ptr DetailsFiller::setupInfo() { : text) + addToLink, (addToLink.isEmpty() ? link.url : (text + addToLink))); }); - auto linkLine = addInfoOneLine( + const auto linkLine = addInfoOneLine( (topicRootId ? tr::lng_info_link_label(Ui::Text::WithEntities) : UsernamesSubtext(_peer, tr::lng_info_link_label())), @@ -1200,6 +1203,18 @@ object_ptr DetailsFiller::setupInfo() { addToLink); linkLine.text->overrideLinkClickHandler(linkCallback); linkLine.subtext->overrideLinkClickHandler(linkCallback); + { + const auto qr = Ui::CreateChild( + linkLine.text->parentWidget(), + st::infoProfileLabeledButtonQr); + fitLabelToButton(qr, linkLine.text); + qr->setClickedCallback([=, peer = _peer] { + controller->show(Box([=](not_null box) { + Ui::FillPeerQrBox(box, peer); + })); + return false; + }); + } if (const auto channel = _topic ? nullptr : _peer->asChannel()) { auto locationText = LocationValue( diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 3a0f9566e..70719e936 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -154,11 +154,11 @@ rpl::producer PhoneOrHiddenValue(not_null user) { } rpl::producer UsernameValue( - not_null user, + not_null peer, bool primary) { return (primary - ? PlainPrimaryUsernameValue(user) - : (PlainUsernameValue(user) | rpl::type_erased()) + ? PlainPrimaryUsernameValue(peer) + : (PlainUsernameValue(peer) | rpl::type_erased()) ) | rpl::map([](QString &&username) { return username.isEmpty() ? QString() diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h index 72d50055a..f292c80a5 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.h +++ b/Telegram/SourceFiles/info/profile/info_profile_values.h @@ -57,7 +57,7 @@ rpl::producer> MigratedOrMeValue( [[nodiscard]] rpl::producer PhoneOrHiddenValue( not_null user); [[nodiscard]] rpl::producer UsernameValue( - not_null user, + not_null peer, bool primary = false); [[nodiscard]] rpl::producer> UsernamesValue( not_null peer); diff --git a/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp b/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp index 041a4480a..7d9e7b220 100644 --- a/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/peer_qr_box.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_cloud_themes.h" #include "data/data_peer.h" #include "data/data_session.h" -#include "data/data_user.h" #include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget. #include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" @@ -22,12 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image_prepare.h" #include "ui/layers/generic_box.h" #include "ui/painter.h" -#include "ui/widgets/continuous_sliders.h" #include "ui/rect.h" #include "ui/ui_utility.h" #include "ui/vertical_list.h" #include "ui/widgets/box_content_divider.h" #include "ui/widgets/buttons.h" +#include "ui/widgets/continuous_sliders.h" #include "ui/wrap/vertical_layout.h" #include "window/window_controller.h" #include "window/window_session_controller.h" @@ -386,9 +385,9 @@ void FillPeerQrBox( userpic, state->font, state->userpicToggled.value(), - Info::Profile::UsernameValue(peer->asUser()), - Info::Profile::LinkValue(peer) | rpl::map([](const auto &link) { - return link.url; + Info::Profile::UsernameValue(peer, true), + Info::Profile::LinkValue(peer, true) | rpl::map([](const auto &link) { + return link.text; }), state->bgs.value()); @@ -719,12 +718,12 @@ void FillPeerQrBox( : 0; const auto font = createFont(scale); + using namespace Info::Profile; const auto username = rpl::variable( - Info::Profile::UsernameValue( - peer->asUser())).current().text.toUpper(); + UsernameValue(peer, true)).current().text.toUpper(); const auto link = rpl::variable( - Info::Profile::LinkValue(peer) | rpl::map([](const auto &l) { - return l.url; + LinkValue(peer, true) | rpl::map([](const auto &l) { + return l.text; })); const auto textWidth = font->width(username); const auto top = Ui::GrabWidget(