Added ability to copy phone number from main menu.

This commit is contained in:
23rd 2022-04-28 17:29:31 +03:00
parent 1878061c9a
commit 3bdf1634a9
2 changed files with 24 additions and 2 deletions

View File

@ -223,7 +223,7 @@ void ShowMenu(
QWidget *parent,
const QString &copyButton,
const QString &text) {
const auto menu = new Ui::PopupMenu(parent);
const auto menu = Ui::CreateChild<Ui::PopupMenu>(parent);
menu->addAction(copyButton, [=] {
QGuiApplication::clipboard()->setText(text);
@ -568,6 +568,12 @@ void SetupAccountsWrap(
state->menu = base::make_unique_q<Ui::PopupMenu>(
raw,
st::popupMenuWithIcons);
addAction(tr::lng_profile_copy_phone(tr::now), [=] {
const auto phone = rpl::variable<TextWithEntities>(
Info::Profile::PhoneValue(session->user()));
QGuiApplication::clipboard()->setText(phone.current().text);
}, &st::menuIconCopy);
addAction(tr::lng_menu_activate(tr::now), [=] {
Core::App().domain().activate(&session->account());
}, &st::menuIconProfile);

View File

@ -65,6 +65,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QWindow>
#include <QtGui/QScreen>
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
namespace Window {
namespace {
@ -568,7 +571,20 @@ void MainMenu::setupAccounts() {
void MainMenu::setupAccountsToggle() {
_toggleAccounts->show();
_toggleAccounts->setClickedCallback([=] { toggleAccounts(); });
_toggleAccounts->setAcceptBoth();
_toggleAccounts->addClickHandler([=](Qt::MouseButton button) {
if (button == Qt::LeftButton) {
toggleAccounts();
} else if (button == Qt::RightButton) {
const auto menu = Ui::CreateChild<Ui::PopupMenu>(
_toggleAccounts.data());
menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] {
QGuiApplication::clipboard()->setText(_phoneText);
});
menu->popup(QCursor::pos());
}
});
}
void MainMenu::parentResized() {