From c00f2f96ecdef061a226696f46383aa35aab741e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 7 Sep 2022 20:39:57 +0400 Subject: [PATCH] Replace phone number with "Set Emoji Status". --- Telegram/Resources/langs/lang.strings | 1 + .../info_profile_emoji_status_panel.cpp | 2 +- Telegram/SourceFiles/window/window.style | 2 +- .../SourceFiles/window/window_main_menu.cpp | 54 ++++++++----------- .../SourceFiles/window/window_main_menu.h | 6 +-- 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 8a8d725e7..72e1de759 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_menu_night_mode" = "Night Mode"; "lng_menu_add_account" = "Add Account"; "lng_menu_activate" = "Activate"; +"lng_menu_set_status" = "Set Emoji Status"; "lng_disable_notifications_from_tray" = "Disable notifications"; "lng_enable_notifications_from_tray" = "Enable notifications"; diff --git a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp index 238f5d35a..ef9ecb605 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp @@ -213,7 +213,7 @@ void EmojiStatusPanel::show( const auto global = button->mapToGlobal(QPoint()); const auto local = parent->mapFromGlobal(global); _panel->moveTopRight( - local.y() + button->height(), + local.y() + button->height() - (st::normalFont->height / 2), local.x() + button->width() * 3); _panel->toggleAnimated(); } diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index 5326c5280..b54937ad9 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -114,7 +114,7 @@ mainMenuResetScaleTop: 2px; mainMenuResetScaleIconLeft: 5px; mainMenuCoverNameLeft: 26px; mainMenuCoverNameTop: 84px; -mainMenuCoverStatusLeft: 24px; +mainMenuCoverStatusLeft: mainMenuCoverNameLeft; mainMenuCoverStatusTop: 103px; mainMenuPhoneFont: font(12px); mainMenuSkip: 6px; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 011b06919..2d0fec1de 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/about_box.h" #include "ui/boxes/confirm_box.h" #include "boxes/peer_list_controllers.h" +#include "boxes/premium_preview_box.h" #include "calls/calls_box_controller.h" #include "lang/lang_keys.h" #include "core/click_handler_types.h" @@ -339,6 +340,9 @@ MainMenu::MainMenu( Ui::UserpicButton::Role::Custom, st::mainMenuUserpic) , _toggleAccounts(this) +, _setEmojiStatus(this, tr::lng_menu_set_status([](const QString &text) { + return Ui::Text::Link(text); +})) , _emojiStatusPanel(std::make_unique()) , _badge(std::make_unique( this, @@ -373,6 +377,7 @@ MainMenu::MainMenu( setupUserpicButton(); setupAccountsToggle(); + setupSetEmojiStatus(); setupAccounts(); setupArchive(); setupMenu(); @@ -440,10 +445,7 @@ MainMenu::MainMenu( moveBadge(); }, lifetime()); _badge->setPremiumClickCallback([=] { - _emojiStatusPanel->show( - _controller, - _badge->widget(), - _badge->sizeTag()); + chooseEmojiStatus(); }); _controller->session().downloaderTaskFinished( @@ -451,14 +453,6 @@ MainMenu::MainMenu( update(); }, lifetime()); - _controller->session().changes().peerUpdates( - _controller->session().user(), - Data::PeerUpdate::Flag::PhoneNumber - ) | rpl::start_with_next([=] { - updatePhone(); - }, lifetime()); - - updatePhone(); initResetScaleButton(); } @@ -624,18 +618,16 @@ void MainMenu::setupAccountsToggle() { _toggleAccounts->addClickHandler([=](Qt::MouseButton button) { if (button == Qt::LeftButton) { toggleAccounts(); - } else if (button == Qt::RightButton) { - const auto menu = Ui::CreateChild( - _toggleAccounts.data()); - - menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] { - QGuiApplication::clipboard()->setText(_phoneText); - }); - menu->popup(QCursor::pos()); } }); } +void MainMenu::setupSetEmojiStatus() { + _setEmojiStatus->overrideLinkClickHandler([=] { + chooseEmojiStatus(); + }); +} + void MainMenu::parentResized() { resize(st::mainMenuWidth, parentWidget()->height()); } @@ -755,8 +747,6 @@ void MainMenu::setupMenu() { _nightThemeSwitches.fire_copy(*darkMode); } }, _nightThemeToggle->lifetime()); - - updatePhone(); } void MainMenu::resizeEvent(QResizeEvent *e) { @@ -771,6 +761,10 @@ void MainMenu::updateControlsGeometry() { if (_resetScaleButton) { _resetScaleButton->moveToRight(0, 0); } + _setEmojiStatus->moveToLeft( + st::mainMenuCoverStatusLeft, + st::mainMenuCoverStatusTop, + width()); _toggleAccounts->setGeometry( 0, st::mainMenuCoverNameTop, @@ -796,9 +790,12 @@ void MainMenu::updateInnerControlsGeometry() { } } -void MainMenu::updatePhone() { - _phoneText = Ui::FormatPhone(_controller->session().user()->phone()); - update(); +void MainMenu::chooseEmojiStatus() { + if (const auto widget = _badge->widget()) { + _emojiStatusPanel->show(_controller, widget, _badge->sizeTag()); + } else { + ShowPremiumPreviewBox(_controller, PremiumPreview::EmojiStatus); + } } void MainMenu::paintEvent(QPaintEvent *e) { @@ -832,13 +829,6 @@ void MainMenu::paintEvent(QPaintEvent *e) { ? (st::semiboldFont->spacew + _badge->widget()->width()) : 0)), width()); - p.setFont(st::mainMenuPhoneFont); - p.setPen(st::windowSubTextFg); - p.drawTextLeft( - st::mainMenuCoverStatusLeft, - st::mainMenuCoverStatusTop, - width(), - _phoneText); } } diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index b49240c36..5da215391 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -64,19 +64,21 @@ private: void setupUserpicButton(); void setupAccounts(); void setupAccountsToggle(); + void setupSetEmojiStatus(); void setupArchive(); void setupMenu(); void updateControlsGeometry(); void updateInnerControlsGeometry(); - void updatePhone(); void initResetScaleButton(); void toggleAccounts(); + void chooseEmojiStatus(); const not_null _controller; object_ptr _userpicButton; Ui::Text::String _name; int _nameVersion = 0; object_ptr _toggleAccounts; + object_ptr _setEmojiStatus; std::unique_ptr _emojiStatusPanel; std::unique_ptr _badge; object_ptr _resetScaleButton = { nullptr }; @@ -94,8 +96,6 @@ private: base::Timer _nightThemeSwitch; base::unique_qptr _contextMenu; - QString _phoneText; - }; struct OthersUnreadState {