From ad7bc6326dd088832ea5aedfcce19c492b4808cc Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 12 Oct 2022 22:18:02 +0300 Subject: [PATCH] Added context menu to usernames list. --- .../boxes/peers/edit_peer_usernames_list.cpp | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp index 139bba5f69..fe7db2e7ad 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_user_names.h" #include "apiwrap.h" +#include "base/event_filter.h" #include "data/data_peer.h" #include "lang/lang_keys.h" #include "main/main_session.h" @@ -16,15 +17,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/confirm_box.h" #include "ui/layers/show.h" #include "ui/painter.h" +#include "ui/toast/toast.h" #include "ui/widgets/buttons.h" +#include "ui/widgets/popup_menu.h" #include "ui/wrap/vertical_layout_reorder.h" #include "styles/style_boxes.h" // contactsStatusFont. #include "styles/style_info.h" #include "styles/style_settings.h" +#include "styles/style_menu_icons.h" + +#include class UsernamesList::Row final : public Ui::SettingsButton { public: - Row(not_null parent, const Data::Username &data); + Row( + not_null parent, + const Data::Username &data, + std::shared_ptr show, + QString link); [[nodiscard]] const Data::Username &username() const; @@ -38,13 +48,17 @@ private: const Data::Username _data; const QString _status; const QRect _iconRect; + std::shared_ptr _show; Ui::Text::String _title; + base::unique_qptr _menu; }; UsernamesList::Row::Row( not_null parent, - const Data::Username &data) + const Data::Username &data, + std::shared_ptr show, + QString link) : Ui::SettingsButton(parent, rpl::never()) , _st(st::inviteLinkListItem) , _data(data) @@ -56,7 +70,27 @@ UsernamesList::Row::Row( _st.photoPosition.y() + st::inviteLinkIconSkip, _st.photoSize - st::inviteLinkIconSkip * 2, _st.photoSize - st::inviteLinkIconSkip * 2) +, _show(show) , _title(_st.nameStyle, '@' + data.username) { + base::install_event_filter(this, [=](not_null e) { + if (e->type() != QEvent::ContextMenu) { + return base::EventFilterResult::Continue; + } + _menu = base::make_unique_q( + this, + st::popupMenuWithIcons); + _menu->addAction( + tr::lng_group_invite_context_copy(tr::now), + [=] { + QGuiApplication::clipboard()->setText(link); + Ui::Toast::Show( + show->toastParent(), + tr::lng_create_channel_link_copied(tr::now)); + }, + &st::menuIconCopy); + _menu->popup(QCursor::pos()); + return base::EventFilterResult::Cancel; + }); } const Data::Username &UsernamesList::Row::username() const { @@ -159,8 +193,10 @@ void UsernamesList::rebuild(const Data::Usernames &usernames) { const auto content = _container->add( object_ptr(_container)); for (const auto &username : usernames) { + const auto link = _peer->session().createInternalLinkFull( + username.username); const auto row = content->add( - object_ptr(content, username)); + object_ptr(content, username, _show, link)); _rows.push_back(row); row->addClickHandler([=] { if (_reordering || (!_peer->isSelf() && !_peer->isChannel())) {