From ca7c50fbcd1f14d2cb9b8abe5dd8f7864457a88e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 12 Jun 2019 22:11:41 +0200 Subject: [PATCH] Remove pseudo-HTML from langpacks and Ui::Text::String. --- Telegram/Resources/langs/lang.strings | 18 +++-- Telegram/SourceFiles/boxes/about_box.cpp | 54 +++++++++---- .../SourceFiles/boxes/add_contact_box.cpp | 1 - .../SourceFiles/boxes/change_phone_box.cpp | 21 +++-- Telegram/SourceFiles/boxes/confirm_box.cpp | 15 ++-- Telegram/SourceFiles/boxes/confirm_box.h | 4 +- Telegram/SourceFiles/boxes/connection_box.cpp | 4 - .../SourceFiles/boxes/create_poll_box.cpp | 1 - .../SourceFiles/boxes/local_storage_box.cpp | 3 - Telegram/SourceFiles/boxes/passcode_box.cpp | 2 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 7 +- .../boxes/peers/edit_contact_box.cpp | 4 +- .../boxes/peers/edit_linked_chat_box.cpp | 24 +++--- .../boxes/peers/edit_participant_box.cpp | 1 - .../boxes/self_destruction_box.cpp | 3 - Telegram/SourceFiles/boxes/stickers_box.cpp | 2 +- Telegram/SourceFiles/boxes/url_auth_box.cpp | 1 - Telegram/SourceFiles/boxes/username_box.cpp | 2 +- .../chat_helpers/emoji_sets_manager.cpp | 1 - .../chat_helpers/tabbed_selector.cpp | 1 - .../SourceFiles/codegen/lang/generator.cpp | 1 + Telegram/SourceFiles/data/data_document.cpp | 5 +- .../view/export_view_panel_controller.cpp | 2 - .../export/view/export_view_progress.cpp | 3 - .../export/view/export_view_settings.cpp | 6 +- .../SourceFiles/history/history_widget.cpp | 1 - Telegram/SourceFiles/info/info_top_bar.cpp | 2 +- .../inline_bots/inline_results_widget.cpp | 2 +- Telegram/SourceFiles/intro/introcode.cpp | 7 +- Telegram/SourceFiles/intro/introphone.cpp | 42 ---------- Telegram/SourceFiles/intro/introphone.h | 4 - Telegram/SourceFiles/intro/intropwdcheck.cpp | 2 +- Telegram/SourceFiles/intro/introwidget.cpp | 35 ++++++--- Telegram/SourceFiles/intro/introwidget.h | 7 +- .../SourceFiles/lang/lang_cloud_manager.cpp | 4 +- .../media/view/media_view_overlay_widget.cpp | 17 ++-- .../SourceFiles/passport/passport_panel.cpp | 1 - .../passport/passport_panel_details_row.cpp | 3 - .../passport/passport_panel_edit_contact.cpp | 6 -- .../passport/passport_panel_edit_document.cpp | 7 +- .../passport/passport_panel_edit_scans.cpp | 6 -- .../passport/passport_panel_form.cpp | 28 +++---- .../passport/passport_panel_password.cpp | 8 -- .../settings/settings_information.cpp | 1 - Telegram/SourceFiles/ui/text/text.cpp | 77 +------------------ Telegram/SourceFiles/ui/text/text.h | 5 +- .../SourceFiles/ui/text/text_utilities.cpp | 50 +++++++++++- Telegram/SourceFiles/ui/text/text_utilities.h | 26 +++++-- Telegram/SourceFiles/ui/widgets/labels.cpp | 22 ++++-- Telegram/SourceFiles/ui/widgets/labels.h | 6 +- .../SourceFiles/window/window_main_menu.cpp | 9 ++- .../window/window_outdated_bar.cpp | 1 - .../SourceFiles/window/window_peer_menu.cpp | 2 +- 53 files changed, 253 insertions(+), 314 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 48bb9e8a7..071468461 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -174,7 +174,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_phone_title" = "Your Phone Number"; "lng_phone_desc" = "Please confirm your country code and\nenter your mobile phone number."; -"lng_phone_notreg" = "If you don't have a Telegram account yet,\nplease [b]sign up[/b] with {link_start}Android / iPhone{link_end} or {signup_start}here{signup_end}"; "lng_country_code" = "Country Code"; "lng_bad_country_code" = "Invalid Country Code"; "lng_country_ph" = "Search"; @@ -183,7 +182,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_code_ph" = "Your code"; "lng_code_desc" = "We have sent you a message with activation\ncode to your phone. Please enter it below."; -"lng_code_telegram" = "Please enter the code you've just received\nin your previous [b]Telegram[/b] app."; +"lng_code_from_telegram" = "Please enter the code you've just received\nin your previous **Telegram** app."; "lng_code_no_telegram" = "Send code via SMS"; "lng_code_call" = "Telegram will call you in {minutes}:{seconds}"; "lng_code_calling" = "Requesting a call from Telegram..."; @@ -687,7 +686,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_self_destruct_years#other" = "{count} years"; "lng_change_phone_title" = "Change phone number"; -"lng_change_phone_description" = "You can change your Telegram number\nhere. Your account and all your cloud data\n— messages, media, contacts, etc. will be\nmoved to the new number.\n\n[b]Important[/b]: all your Telegram contacts will\nget your [b]new number[/b] added to their address\nbook, provided they had your old number and\nyou haven't blocked them in Telegram."; +"lng_change_phone_about" = "You can change your Telegram number\nhere. Your account and all your cloud data\n— messages, media, contacts, etc. will be\nmoved to the new number.\n\n**Important**: all your Telegram contacts will\nget your **new number** added to their address\nbook, provided they had your old number and\nyou haven't blocked them in Telegram."; "lng_change_phone_warning" = "All your Telegram contacts will get your new number added to their address book, provided they had your old number and you haven't blocked them in Telegram."; "lng_change_phone_occupied" = "The number {phone} is already connected to a Telegram account. Please delete that account before migrating to the new number."; "lng_change_phone_button" = "Change number"; @@ -1473,9 +1472,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_box_leave" = "Leave"; "lng_about_version" = "version {version}"; -"lng_about_text_1" = "Official free messaging app based on [a href=\"https://core.telegram.org/api\"]Telegram API[/a]\nfor speed and security."; -"lng_about_text_2" = "This software is licensed under [a href=\"https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE\"]GNU GPL[/a] version 3.\nSource code is available on [a href=\"https://github.com/telegramdesktop/tdesktop\"]GitHub[/a]."; -"lng_about_text_3" = "Visit {faq_open}Telegram FAQ{faq_close} for more info."; +"lng_about_text1" = "Official free messaging app based on {api_link}\nfor speed and security."; +"lng_about_text1_api" = "Telegram API"; +"lng_about_text2" = "This software is licensed under {gpl_link} version 3.\nSource code is available on {github_link}."; +"lng_about_text2_gpl" = "GNU GPL"; +"lng_about_text2_github" = "GitHub"; +"lng_about_text3" = "Visit {faq_link} for more info."; +"lng_about_text3_faq" = "Telegram FAQ"; "lng_about_done" = "Done"; "lng_search_no_results" = "No messages found"; @@ -1502,7 +1505,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_mediaview_yesterday" = "yesterday at {time}"; "lng_mediaview_date_time" = "{date} at {time}"; -"lng_mediaview_saved" = "Image was saved to your [c]Downloads[/c] folder"; +"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder"; +"lng_mediaview_downloads" = "Downloads"; "lng_mediaview_video_loading" = "Loading - {percent}"; "lng_theme_preview_title" = "Theme Preview"; diff --git a/Telegram/SourceFiles/boxes/about_box.cpp b/Telegram/SourceFiles/boxes/about_box.cpp index a254125c9..dab1da72d 100644 --- a/Telegram/SourceFiles/boxes/about_box.cpp +++ b/Telegram/SourceFiles/boxes/about_box.cpp @@ -13,17 +13,48 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" -#include "styles/style_boxes.h" +#include "ui/text/text_utilities.h" #include "platform/platform_file_utilities.h" #include "platform/platform_info.h" #include "core/click_handler_types.h" #include "core/update_checker.h" +#include "styles/style_boxes.h" + +namespace { + +rpl::producer Text1() { + return rpl::single(lng_about_text1__rich( + lt_api_link, + Ui::Text::Link( + lang(lng_about_text1_api), + "https://core.telegram.org/api"))); +} + +rpl::producer Text2() { + return rpl::single(lng_about_text2__rich( + lt_gpl_link, + Ui::Text::Link( + lang(lng_about_text2_gpl), + "https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE"), + lt_github_link, + Ui::Text::Link( + lang(lng_about_text2_github), + "https://github.com/telegramdesktop/tdesktop"))); +} + +rpl::producer Text3() { + return rpl::single(lng_about_text3__rich( + lt_faq_link, + Ui::Text::Link(lang(lng_about_text3_faq), telegramFaqLink()))); +} + +} // namespace AboutBox::AboutBox(QWidget *parent) : _version(this, lng_about_version(lt_version, currentVersionText()), st::aboutVersionLink) -, _text1(this, lang(lng_about_text_1), Ui::FlatLabel::InitType::Rich, st::aboutLabel) -, _text2(this, lang(lng_about_text_2), Ui::FlatLabel::InitType::Rich, st::aboutLabel) -, _text3(this, st::aboutLabel) { +, _text1(this, Text1(), st::aboutLabel) +, _text2(this, Text2(), st::aboutLabel) +, _text3(this, Text3(), st::aboutLabel) { } void AboutBox::prepare() { @@ -31,18 +62,9 @@ void AboutBox::prepare() { addButton(langFactory(lng_close), [this] { closeBox(); }); - const auto linkFilter = [](const ClickHandlerPtr &link, auto button) { - if (const auto url = dynamic_cast(link.get())) { - url->UrlClickHandler::onClick({ button }); - return false; - } - return true; - }; - - _text3->setRichText(lng_about_text_3(lt_faq_open, qsl("[a href=\"%1\"]").arg(telegramFaqLink()), lt_faq_close, qsl("[/a]"))); - _text1->setClickHandlerFilter(linkFilter); - _text2->setClickHandlerFilter(linkFilter); - _text3->setClickHandlerFilter(linkFilter); + _text1->setLinksTrusted(); + _text2->setLinksTrusted(); + _text3->setLinksTrusted(); _version->setClickedCallback([this] { showVersionHistory(); }); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 22d288c90..360b385ca 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1249,7 +1249,6 @@ RevokePublicLinkBox::RevokePublicLinkBox( : _aboutRevoke( this, lang(lng_channels_too_much_public_about), - Ui::FlatLabel::InitType::Simple, st::aboutRevokePublicLabel) , _revokeCallback(std::move(revokeCallback)) { } diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index de90dbcec..6b31780e4 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -11,8 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/input_fields.h" #include "ui/wrap/fade_wrap.h" -#include "boxes/confirm_phone_box.h" #include "ui/toast/toast.h" +#include "ui/text/text_utilities.h" +#include "boxes/confirm_phone_box.h" #include "boxes/confirm_box.h" #include "auth_session.h" #include "data/data_session.h" @@ -48,7 +49,6 @@ void createErrorLabel( object_ptr( parent, text, - Ui::FlatLabel::InitType::Simple, st::changePhoneError)); label->hide(anim::type::instant); label->moveToLeft(x, y); @@ -129,7 +129,7 @@ void ChangePhoneBox::EnterPhone::prepare() { _phone->moveToLeft(st::boxPadding.left(), st::boxLittleSkip); connect(_phone, &Ui::PhoneInput::submitted, [=] { submit(); }); - auto description = object_ptr(this, lang(lng_change_phone_new_description), Ui::FlatLabel::InitType::Simple, st::changePhoneLabel); + auto description = object_ptr(this, lang(lng_change_phone_new_description), st::changePhoneLabel); auto errorSkip = st::boxLittleSkip + st::changePhoneError.style.font->height; description->moveToLeft(st::boxPadding.left(), _phone->y() + _phone->height() + errorSkip + st::boxLittleSkip); @@ -237,8 +237,10 @@ ChangePhoneBox::EnterCode::EnterCode(QWidget*, const QString &phone, const QStri void ChangePhoneBox::EnterCode::prepare() { setTitle(langFactory(lng_change_phone_title)); - auto descriptionText = lng_change_phone_code_description(lt_phone, textcmdStartSemibold() + App::formatPhone(_phone) + textcmdStopSemibold()); - auto description = object_ptr(this, descriptionText, Ui::FlatLabel::InitType::Rich, st::changePhoneLabel); + auto descriptionText = lng_change_phone_code_description__rich( + lt_phone, + Ui::Text::Bold(App::formatPhone(_phone))); + auto description = object_ptr(this, rpl::single(descriptionText), st::changePhoneLabel); description->moveToLeft(st::boxPadding.left(), 0); auto phoneValue = QString(); @@ -299,7 +301,7 @@ void ChangePhoneBox::EnterCode::updateCall() { if (text.isEmpty()) { _callLabel.destroy(); } else if (!_callLabel) { - _callLabel.create(this, text, Ui::FlatLabel::InitType::Simple, st::changePhoneLabel); + _callLabel.create(this, text, st::changePhoneLabel); _callLabel->moveToLeft(st::boxPadding.left(), countHeight() - _callLabel->height()); _callLabel->show(); } else { @@ -346,7 +348,12 @@ void ChangePhoneBox::prepare() { closeBox(); }); - auto label = object_ptr(this, lang(lng_change_phone_description), Ui::FlatLabel::InitType::Rich, st::changePhoneDescription); + const auto label = Ui::CreateChild( + this, + Lang::Viewer( + lng_change_phone_about + ) | Ui::Text::ToRichLangValue(), + st::changePhoneDescription); label->moveToLeft((st::boxWideWidth - label->width()) / 2, st::changePhoneDescriptionTop); setDimensions(st::boxWideWidth, label->bottomNoMargins() + st::boxLittleSkip); diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 4ad95ac0b..92c13f0c9 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -392,7 +392,7 @@ PinMessageBox::PinMessageBox( MsgId msgId) : _peer(peer) , _msgId(msgId) -, _text(this, lang(lng_pinned_pin_sure), Ui::FlatLabel::InitType::Simple, st::boxLabel) { +, _text(this, lang(lng_pinned_pin_sure), st::boxLabel) { } void PinMessageBox::prepare() { @@ -649,11 +649,11 @@ auto DeleteMessagesBox::revokeText(not_null peer) const boldName.entities.push_back( { EntityType::Bold, 0, boldName.text.size() }); if (canRevokeOutgoingCount == 1) { - result.description = lng_selected_unsend_about_user_one__generic( + result.description = lng_selected_unsend_about_user_one__rich( lt_user, boldName); } else { - result.description = lng_selected_unsend_about_user__generic( + result.description = lng_selected_unsend_about_user__rich( lt_count, canRevokeOutgoingCount, lt_user, @@ -911,12 +911,12 @@ ConfirmInviteBox::~ConfirmInviteBox() = default; ConfirmDontWarnBox::ConfirmDontWarnBox( QWidget*, - const QString &text, + rpl::producer text, const QString &checkbox, const QString &confirm, FnMut callback) : _confirm(confirm) -, _content(setupContent(text, checkbox, std::move(callback))) { +, _content(setupContent(std::move(text), checkbox, std::move(callback))) { } void ConfirmDontWarnBox::prepare() { @@ -926,15 +926,14 @@ void ConfirmDontWarnBox::prepare() { } not_null ConfirmDontWarnBox::setupContent( - const QString &text, + rpl::producer text, const QString &checkbox, FnMut callback) { const auto result = Ui::CreateChild(this); result->add( object_ptr( result, - text, - Ui::FlatLabel::InitType::Rich, + std::move(text), st::boxLabel), st::boxPadding); const auto control = result->add( diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index 1d9e09e60..a6d5f6218 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -224,7 +224,7 @@ class ConfirmDontWarnBox : public BoxContent { public: ConfirmDontWarnBox( QWidget*, - const QString &text, + rpl::producer text, const QString &checkbox, const QString &confirm, FnMut callback); @@ -234,7 +234,7 @@ protected: private: not_null setupContent( - const QString &text, + rpl::producer text, const QString &checkbox, FnMut callback); diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 748775660..4eef66538 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -534,7 +534,6 @@ void ProxiesBox::setupContent() { object_ptr( inner, lang(lng_proxy_about), - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel), st::proxyAboutPadding), style::margins(0, 0, 0, st::proxyRowPadding.top())); @@ -652,7 +651,6 @@ void ProxiesBox::createNoRowsLabel() { const auto label = Ui::CreateChild( _noRows.get(), lang(lng_proxy_description), - Ui::FlatLabel::InitType::Simple, st::proxyEmptyListLabel); _noRows->widthValue( ) | rpl::start_with_next([=](int width) { @@ -780,7 +778,6 @@ void ProxyBox::setupTypes() { object_ptr( _content, lang(lng_proxy_sponsor_warning), - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel), st::proxyAboutSponsorPadding))); } @@ -911,7 +908,6 @@ void ProxyBox::addLabel( object_ptr( parent, text, - Ui::FlatLabel::InitType::Simple, st::proxyEditTitle), st::proxyEditTitlePadding); } diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 960f82418..74c4b4941 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -150,7 +150,6 @@ not_null CreateWarningLabel( const auto result = Ui::CreateChild( parent.get(), QString(), - Ui::FlatLabel::InitType::Simple, st::createPollWarning); result->setAttribute(Qt::WA_TransparentForMouseEvents); QObject::connect(field, &Ui::InputField::changed, [=] { diff --git a/Telegram/SourceFiles/boxes/local_storage_box.cpp b/Telegram/SourceFiles/boxes/local_storage_box.cpp index 08b88a5cd..ab788129b 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.cpp +++ b/Telegram/SourceFiles/boxes/local_storage_box.cpp @@ -160,12 +160,10 @@ LocalStorageBox::Row::Row( , _title( this, titleText(data), - Ui::FlatLabel::InitType::Simple, st::localStorageRowTitle) , _description( this, sizeText(data), - Ui::FlatLabel::InitType::Simple, st::localStorageRowSize) , _clear(this, std::move(clear), st::localStorageClear) { _clear->setVisible(data.count != 0); @@ -192,7 +190,6 @@ void LocalStorageBox::Row::toggleProgress(bool shown) { _clearing = object_ptr( this, lang(lng_local_storage_clearing), - Ui::FlatLabel::InitType::Simple, st::localStorageRowSize); _clearing->show(); _description->hide(); diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 94e54e9b5..4a7a0cadd 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -87,7 +87,7 @@ void PasscodeBox::prepare() { addButton(langFactory(_turningOff ? lng_passcode_remove_button : lng_settings_save), [=] { save(); }); addButton(langFactory(lng_cancel), [=] { closeBox(); }); - _about.setRichText(st::passcodeTextStyle, lang(_cloudPwd ? lng_cloud_password_about : lng_passcode_about)); + _about.setText(st::passcodeTextStyle, lang(_cloudPwd ? lng_cloud_password_about : lng_passcode_about)); _aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5); if (_turningOff) { _oldPasscode->show(); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 97943fd02..c25efafc8 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -246,7 +246,7 @@ void PeerListController::setDescriptionText(const QString &text) { if (text.isEmpty()) { setDescription(nullptr); } else { - setDescription(object_ptr(nullptr, text, Ui::FlatLabel::InitType::Simple, st::membersAbout)); + setDescription(object_ptr(nullptr, text, st::membersAbout)); } } @@ -254,7 +254,7 @@ void PeerListController::setSearchLoadingText(const QString &text) { if (text.isEmpty()) { setSearchLoading(nullptr); } else { - setSearchLoading(object_ptr(nullptr, text, Ui::FlatLabel::InitType::Simple, st::membersAbout)); + setSearchLoading(object_ptr(nullptr, text, st::membersAbout)); } } @@ -262,7 +262,7 @@ void PeerListController::setSearchNoResultsText(const QString &text) { if (text.isEmpty()) { setSearchNoResults(nullptr); } else { - setSearchNoResults(object_ptr(nullptr, text, Ui::FlatLabel::InitType::Simple, st::membersAbout)); + setSearchNoResults(object_ptr(nullptr, text, st::membersAbout)); } } @@ -886,7 +886,6 @@ void PeerListContent::setSearchMode(PeerListSearchMode mode) { setSearchLoading(object_ptr( this, lang(lng_contacts_loading), - Ui::FlatLabel::InitType::Simple, st::membersAbout)); } } else { diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 5d2546c51..62fc5a213 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -214,14 +214,14 @@ void Builder::setupWarning() { const auto name = _user->shortName(); const auto nameWithEntities = TextWithEntities{ name }; const auto text = _phone.isEmpty() - ? lng_contact_phone_after__generic( + ? lng_contact_phone_after__rich( lt_user, nameWithEntities, lt_visible, Ui::Text::Bold(lang(lng_contact_phone_visible)), lt_name, nameWithEntities) - : lng_contact_phone_show__generic( + : lng_contact_phone_show__rich( lt_button, Ui::Text::Bold(lang(lng_box_done).toUpper()), lt_user, diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index f7bc4919b..3ea56878d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -117,9 +117,7 @@ void Controller::rowClicked(not_null row) { } void Controller::choose(not_null chat) { - auto text = lng_manage_discussion_group_sure__generic< - TextWithEntities - >( + auto text = lng_manage_discussion_group_sure__rich( lt_group, Ui::Text::Bold(chat->name), lt_channel, @@ -132,7 +130,7 @@ void Controller::choose(not_null chat) { text.append("\n\n" + lang(lng_manage_discussion_group_private)); if (chat->hiddenPreHistory()) { text.append("\n\n"); - text.append(lng_manage_discussion_group_warning__generic( + text.append(lng_manage_discussion_group_warning__rich( lt_visible, Ui::Text::Bold(lang(lng_manage_discussion_group_visible)))); } @@ -154,9 +152,7 @@ void Controller::choose(not_null chat) { } void Controller::choose(not_null chat) { - auto text = lng_manage_discussion_group_sure__generic< - TextWithEntities - >( + auto text = lng_manage_discussion_group_sure__rich( lt_group, Ui::Text::Bold(chat->name), lt_channel, @@ -196,17 +192,16 @@ object_ptr SetupAbout( auto about = object_ptr( parent, QString(), - Ui::FlatLabel::InitType::Simple, st::linkedChatAbout); about->setMarkedText([&]() -> TextWithEntities { if (!channel->isBroadcast()) { - return lng_manage_linked_channel_about__generic< - TextWithEntities - >(lt_channel, Ui::Text::Bold(chat->name)); + return lng_manage_linked_channel_about__rich( + lt_channel, + Ui::Text::Bold(chat->name)); } else if (chat != nullptr) { - return lng_manage_discussion_group_about_chosen__generic< - TextWithEntities - >(lt_group, Ui::Text::Bold(chat->name)); + return lng_manage_discussion_group_about_chosen__rich( + lt_group, + Ui::Text::Bold(chat->name)); } else { return { lang(lng_manage_discussion_group_about) }; } @@ -222,7 +217,6 @@ object_ptr SetupFooter( lang(channel->isBroadcast() ? lng_manage_discussion_group_posted : lng_manage_linked_channel_posted), - Ui::FlatLabel::InitType::Simple, st::linkedChatAbout); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index bb5d8760e..bdc1f316a 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -365,7 +365,6 @@ void EditRestrictedBox::prepare() { object_ptr( this, lang(lng_rights_chat_banned_until_header), - Ui::FlatLabel::InitType::Simple, st::rightsHeaderLabel), st::rightsHeaderMargin); setRestrictUntil(_until); diff --git a/Telegram/SourceFiles/boxes/self_destruction_box.cpp b/Telegram/SourceFiles/boxes/self_destruction_box.cpp index 628c15902..13083aeb6 100644 --- a/Telegram/SourceFiles/boxes/self_destruction_box.cpp +++ b/Telegram/SourceFiles/boxes/self_destruction_box.cpp @@ -21,7 +21,6 @@ SelfDestructionBox::SelfDestructionBox( , _loading( this, lang(lng_contacts_loading), - Ui::FlatLabel::InitType::Simple, st::membersAbout) { std::move( preloaded @@ -55,7 +54,6 @@ void SelfDestructionBox::showContent() { _description.create( this, lang(lng_self_destruct_description), - Ui::FlatLabel::InitType::Simple, st::boxLabel); _description->moveToLeft(st::boxPadding.left(), y); y += _description->height() + st::boxMediumSkip; @@ -93,7 +91,6 @@ void SelfDestructionBox::prepare() { auto fake = object_ptr( this, lang(lng_self_destruct_description), - Ui::FlatLabel::InitType::Simple, st::boxLabel); const auto boxHeight = st::boxOptionListPadding.top() + fake->height() + st::boxMediumSkip diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 594bac46c..90561a7f8 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -675,7 +675,7 @@ StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) : T , _megagroupSetInput(_megagroupSet->mgInfo->stickerSet) , _megagroupSetField(this, st::groupStickersField, [] { return qsl("stickerset"); }, QString(), true) , _megagroupDivider(this) -, _megagroupSubTitle(this, lang(lng_stickers_group_from_your), Ui::FlatLabel::InitType::Simple, st::boxTitle) { +, _megagroupSubTitle(this, lang(lng_stickers_group_from_your), st::boxTitle) { _megagroupSetField->setLinkPlaceholder(Core::App().createInternalLink(qsl("addstickers/"))); _megagroupSetField->setPlaceholderHidden(false); _megagroupSetAddressChangedTimer.setCallback([this] { handleMegagroupSetAddressChange(); }); diff --git a/Telegram/SourceFiles/boxes/url_auth_box.cpp b/Telegram/SourceFiles/boxes/url_auth_box.cpp index 2af7b2ed6..bc2730b5b 100644 --- a/Telegram/SourceFiles/boxes/url_auth_box.cpp +++ b/Telegram/SourceFiles/boxes/url_auth_box.cpp @@ -149,7 +149,6 @@ not_null UrlAuthBox::setupContent( object_ptr( result, lng_url_auth_open_confirm(lt_link, url), - Ui::FlatLabel::InitType::Simple, st::boxLabel), st::boxPadding); const auto addCheckbox = [&](const QString &text) { diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index 19354ccf0..e0c032daf 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -51,7 +51,7 @@ void UsernameBox::prepare() { connect(_username, &Ui::MaskedInputField::submitted, [=] { save(); }); _link->addClickHandler([=] { linkClick(); }); - _about.setRichText(st::usernameTextStyle, lang(lng_username_about)); + _about.setText(st::usernameTextStyle, lang(lng_username_about)); setDimensions(st::boxWidth, st::usernamePadding.top() + _username->height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom()); _checkTimer->setSingleShot(true); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 6001062fb..3e77f5a28 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -541,7 +541,6 @@ void Row::setupLabels(const Set &set) { const auto name = Ui::CreateChild( this, set.name, - Ui::FlatLabel::InitType::Simple, st::localStorageRowTitle); name->setAttribute(Qt::WA_TransparentForMouseEvents); _status = Ui::CreateChild( diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index d4fb39235..1bec2ac10 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -685,7 +685,6 @@ void TabbedSelector::checkRestrictedPeer() { _restrictedLabel.create( this, lang(*errorKey), - Ui::FlatLabel::InitType::Simple, st::stickersRestrictedLabel); _restrictedLabel->show(); updateRestrictedLabelGeometry(); diff --git a/Telegram/SourceFiles/codegen/lang/generator.cpp b/Telegram/SourceFiles/codegen/lang/generator.cpp index 9d4baa00e..7a144a12e 100644 --- a/Telegram/SourceFiles/codegen/lang/generator.cpp +++ b/Telegram/SourceFiles/codegen/lang/generator.cpp @@ -169,6 +169,7 @@ inline ResultString " << (isPlural ? entry.keyBase : key) << "__generic(" << gen return result;\n\ }\n\ constexpr auto " << (isPlural ? entry.keyBase : key) << " = &" << (isPlural ? entry.keyBase : key) << "__generic;\n\ +constexpr auto " << (isPlural ? entry.keyBase : key) << "__rich = &" << (isPlural ? entry.keyBase : key) << "__generic;\n\ \n"; } } diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index cf646d1d0..55eb72f15 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "ui/image/image.h" #include "ui/image/image_source.h" +#include "ui/text/text_utilities.h" #include "mainwindow.h" #include "core/application.h" #include "lottie/lottie_animation.h" @@ -96,9 +97,9 @@ void LaunchWithWarning(const QString &name, HistoryItem *item) { File::Launch(name); }; Ui::show(Box( - lng_launch_exe_warning( + rpl::single(lng_launch_exe_warning__rich( lt_extension, - textcmdStartSemibold() + extension + textcmdStopSemibold()), + Ui::Text::Bold(extension))), lang(lng_launch_exe_dont_ask), lang(lng_launch_exe_sure), callback)); diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 96b927fff..8b3f66fb3 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -53,7 +53,6 @@ void SuggestBox::prepare() { const auto content = Ui::CreateChild( this, lang(lng_export_suggest_text), - Ui::FlatLabel::InitType::Simple, st::boxLabel); widthValue( ) | rpl::start_with_next([=](int width) { @@ -233,7 +232,6 @@ void PanelController::showCriticalError(const QString &text) { object_ptr( _panel.get(), text, - Ui::FlatLabel::InitType::Simple, st::exportErrorLabel), style::margins(0, st::exportPanelSize.height() / 4, 0, 0)); container->widthValue( diff --git a/Telegram/SourceFiles/export/view/export_view_progress.cpp b/Telegram/SourceFiles/export/view/export_view_progress.cpp index 517bed064..9a95daf06 100644 --- a/Telegram/SourceFiles/export/view/export_view_progress.cpp +++ b/Telegram/SourceFiles/export/view/export_view_progress.cpp @@ -91,14 +91,12 @@ void ProgressWidget::Row::fillCurrentInstance() { object_ptr( this, _data.label, - Ui::FlatLabel::InitType::Simple, st::exportProgressLabel)); _current.info = base::make_unique_q>( this, object_ptr( this, _data.info, - Ui::FlatLabel::InitType::Simple, st::exportProgressInfoLabel)); _current.label->hide(anim::type::instant); _current.info->hide(anim::type::instant); @@ -248,7 +246,6 @@ ProgressWidget::ProgressWidget( object_ptr( this, lang(lng_export_progress), - Ui::FlatLabel::InitType::Simple, st::exportAboutLabel), st::exportAboutPadding); diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index 37559fbef..228c2585f 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -262,7 +262,7 @@ void SettingsWidget::addLocationLabel( 0, text.size(), QString("internal:edit_export_path") }); - return lng_export_option_location__generic( + return lng_export_option_location__rich( lt_path, pathLink); }); @@ -303,7 +303,7 @@ void SettingsWidget::addLimitsLabel( 0, end.size(), QString("internal:edit_till") }); - return lng_export_limits__generic( + return lng_export_limits__rich( lt_from, fromLink, lt_till, @@ -454,7 +454,6 @@ void SettingsWidget::addHeader( object_ptr( container, lang(key), - Ui::FlatLabel::InitType::Simple, st::exportHeaderLabel), st::exportHeaderPadding); } @@ -493,7 +492,6 @@ not_null SettingsWidget::addOptionWithAbout( object_ptr( container, lang(about), - Ui::FlatLabel::InitType::Simple, st::exportAboutOptionLabel), st::exportAboutOptionPadding); return result; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d8ab9c8a1..e4a150f50 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2100,7 +2100,6 @@ void HistoryWidget::refreshAboutProxyPromotion() { object_ptr( this, lang(lng_proxy_sponsor_about), - Ui::FlatLabel::InitType::Simple, st::historyAboutProxy), st::historyAboutProxyPadding); } diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index 06e660818..7e72ce9c7 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -486,7 +486,7 @@ bool TopBar::computeCanDelete() const { Ui::StringWithNumbers TopBar::generateSelectedText() const { using Data = Ui::StringWithNumbers; using Type = Storage::SharedMediaType; - auto phrase = [&] { + const auto phrase = [&] { switch (_selectedItems.type) { case Type::Photo: return lng_media_selected_photo__generic; case Type::Video: return lng_media_selected_video__generic; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 1f386b552..51642bdbb 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -90,7 +90,7 @@ void Inner::checkRestrictedPeer() { ChatRestriction::f_send_inline); if (errorKey) { if (!_restrictedLabel) { - _restrictedLabel.create(this, lang(*errorKey), Ui::FlatLabel::InitType::Simple, st::stickersRestrictedLabel); + _restrictedLabel.create(this, lang(*errorKey), st::stickersRestrictedLabel); _restrictedLabel->show(); _restrictedLabel->move(st::inlineResultsLeft - st::buttonRadius, st::stickerPanPadding); if (_switchPmButton) { diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index fcd8d64c4..ff1b36788 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "ui/text/text_utilities.h" #include "boxes/confirm_box.h" #include "styles/style_intro.h" @@ -101,7 +102,11 @@ void CodeWidget::refreshLang() { } void CodeWidget::updateDescText() { - setDescriptionText(langFactory(getData()->codeByTelegram ? lng_code_telegram : lng_code_desc)); + const auto byTelegram = getData()->codeByTelegram; + setDescriptionText([=] { + return Ui::Text::RichLangValue( + lang(byTelegram ? lng_code_from_telegram : lng_code_desc)); + }); if (getData()->codeByTelegram) { _noTelegramCode->show(); _callTimer->stop(); diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 56e9240c7..33f0e42de 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -85,23 +85,6 @@ void PhoneWidget::hidePhoneError() { } } -//void PhoneWidget::showSignup() { -// showPhoneError(langFactory(lng_bad_phone_noreg)); -// if (!_signup) { -// auto signupText = lng_phone_notreg(lt_link_start, textcmdStartLink(1), lt_link_end, textcmdStopLink(), lt_signup_start, textcmdStartLink(2), lt_signup_end, textcmdStopLink()); -// auto inner = object_ptr(this, signupText, Ui::FlatLabel::InitType::Rich, st::introDescription); -// _signup.create(this, std::move(inner)); -// _signup->entity()->setLink(1, std::make_shared(qsl("https://telegram.org"), false)); -// _signup->entity()->setLink(2, std::make_shared([this] { -// toSignUp(); -// })); -// _signup->hide(anim::type::instant); -// updateSignupGeometry(); -// } -// _signup->show(anim::type::normal); -// hideDescription(); -//} - void PhoneWidget::countryChanged() { if (!_changed) { selectCountry(getData()->country); @@ -129,7 +112,6 @@ void PhoneWidget::submit() { _sentPhone = phone; Core::App().mtp()->setUserPhone(_sentPhone); - //_sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&PhoneWidget::phoneCheckDone), rpcFail(&PhoneWidget::phoneSubmitFail)); _sentRequest = MTP::send( MTPauth_SendCode( MTP_string(_sentPhone), @@ -158,22 +140,6 @@ void PhoneWidget::onCheckRequest() { stopCheck(); } } -// -//void PhoneWidget::phoneCheckDone(const MTPauth_CheckedPhone &result) { -// stopCheck(); -// -// auto &d = result.c_auth_checkedPhone(); -// if (mtpIsTrue(d.vphone_registered)) { -// hidePhoneError(); -// -// _checkRequest->start(1000); -// -// _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail)); -// } else { -// showSignup(); -// _sentRequest = 0; -// } -//} void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) { stopCheck(); @@ -199,14 +165,6 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) { goNext(new Intro::CodeWidget(parentWidget(), getData())); } -//void PhoneWidget::toSignUp() { -// hideError(); // Hide error, but leave the signup label visible. -// -// _checkRequest->start(1000); -// -// _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(0), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&PhoneWidget::phoneSubmitDone), rpcFail(&PhoneWidget::phoneSubmitFail)); -//} - bool PhoneWidget::phoneSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); diff --git a/Telegram/SourceFiles/intro/introphone.h b/Telegram/SourceFiles/intro/introphone.h index be12eb4f1..3fefac306 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -48,18 +48,14 @@ private: void updateSignupGeometry(); void countryChanged(); - //void phoneCheckDone(const MTPauth_CheckedPhone &result); void phoneSubmitDone(const MTPauth_SentCode &result); bool phoneSubmitFail(const RPCError &error); - //void toSignUp(); - QString fullNumber() const; void stopCheck(); void showPhoneError(Fn textFactory); void hidePhoneError(); - //void showSignup(); bool _changed = false; diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index 8a44828a5..0466329af 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -326,7 +326,7 @@ void PwdCheckWidget::showReset() { void PwdCheckWidget::updateDescriptionText() { auto pwdHidden = _pwdField->isHidden(); auto emailPattern = _emailPattern; - setDescriptionText([pwdHidden, emailPattern] { + setDescriptionText([=] { return pwdHidden ? lng_signin_recover_desc(lt_email, emailPattern) : lang(lng_signin_desc); }); } diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 4cb8d9fc4..210e05c92 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "boxes/confirm_box.h" #include "ui/text/text.h" +#include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/wrap/fade_wrap.h" @@ -324,17 +325,19 @@ void Widget::showTerms() { } else if (!_terms) { auto entity = object_ptr( this, - lng_terms_signup( + rpl::single(lng_terms_signup__rich( lt_link, - textcmdLink(1, lang(lng_terms_signup_link))), - Ui::FlatLabel::InitType::Rich, + Ui::Text::Link(lang(lng_terms_signup_link)))), st::introTermsLabel); _terms.create(this, std::move(entity)); - _terms->entity()->setLink( - 1, - std::make_shared([=] { + _terms->entity()->setClickHandlerFilter([=]( + const ClickHandlerPtr &handler, + Qt::MouseButton button) { + if (button == Qt::LeftButton) { showTerms(nullptr); - })); + } + return false; + }); updateControlsGeometry(); _terms->hide(anim::type::instant); } @@ -670,24 +673,32 @@ void Widget::Step::updateLabelsPosition() { } } -void Widget::Step::setTitleText(Fn richTitleTextFactory) { - _titleTextFactory = std::move(richTitleTextFactory); +void Widget::Step::setTitleText(Fn titleTextFactory) { + _titleTextFactory = std::move(titleTextFactory); refreshTitle(); updateLabelsPosition(); } void Widget::Step::refreshTitle() { - _title->setRichText(_titleTextFactory()); + _title->setText(_titleTextFactory()); } -void Widget::Step::setDescriptionText(Fn richDescriptionTextFactory) { +void Widget::Step::setDescriptionText(Fn descriptionTextFactory) { + _descriptionTextFactory = [=] { + return TextWithEntities{ descriptionTextFactory() }; + }; + refreshDescription(); + updateLabelsPosition(); +} + +void Widget::Step::setDescriptionText(Fn richDescriptionTextFactory) { _descriptionTextFactory = std::move(richDescriptionTextFactory); refreshDescription(); updateLabelsPosition(); } void Widget::Step::refreshDescription() { - _description->entity()->setRichText(_descriptionTextFactory()); + _description->entity()->setMarkedText(_descriptionTextFactory()); } void Widget::Step::refreshLang() { diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 32a7cffae..416f5c765 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -138,8 +138,9 @@ public: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void setTitleText(Fn richTitleTextFactory); - void setDescriptionText(Fn richDescriptionTextFactory); + void setTitleText(Fn titleTextFactory); + void setDescriptionText(Fn descriptionTextFactory); + void setDescriptionText(Fn richDescriptionTextFactory); bool paintAnimated(Painter &p, QRect clip); void fillSentCodeData(const MTPDauth_sentCode &type); @@ -213,7 +214,7 @@ public: object_ptr _title; Fn _titleTextFactory; object_ptr> _description; - Fn _descriptionTextFactory; + Fn _descriptionTextFactory; bool _errorCentered = false; bool _errorBelowLink = false; diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 11c75e55a..5cd013804 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -89,8 +89,8 @@ void ConfirmSwitchBox::prepare() { 0, percent.text.size() }); const auto text = (_official - ? lng_language_switch_about_official__generic - : lng_language_switch_about_unofficial__generic)( + ? lng_language_switch_about_official__rich + : lng_language_switch_about_unofficial__rich)( lt_lang_name, name, lt_percent, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 3d991c6d9..b7555c841 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/widgets/buttons.h" #include "ui/image/image.h" +#include "ui/text/text_utilities.h" #include "ui/text_options.h" #include "boxes/confirm_box.h" #include "media/audio/media_audio.h" @@ -235,11 +236,13 @@ OverlayWidget::OverlayWidget() setWindowIcon(Window::CreateIcon(&Core::App().activeAccount())); setWindowTitle(qsl("Media viewer")); - TextCustomTagsMap custom; - custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink())); - _saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), Ui::DialogTextOptions(), custom); + const auto text = lng_mediaview_saved_to__rich( + lt_downloads, + Ui::Text::Link( + lang(lng_mediaview_downloads), + "internal:show_saved_message")); + _saveMsgText.setMarkedText(st::mediaviewSaveMsgStyle, text, Ui::DialogTextOptions()); _saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom()); - _saveMsgText.setLink(1, std::make_shared([this] { showSaveMsgFile(); })); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); @@ -3441,7 +3444,11 @@ void OverlayWidget::updateOver(QPoint pos) { void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) { updateOver(e->pos()); - if (ClickHandlerPtr activated = ClickHandler::unpressed()) { + if (const auto activated = ClickHandler::unpressed()) { + if (activated->dragText() == qstr("internal:show_saved_message")) { + showSaveMsgFile(); + return; + } App::activateClickHandler(activated, e->button()); return; } diff --git a/Telegram/SourceFiles/passport/passport_panel.cpp b/Telegram/SourceFiles/passport/passport_panel.cpp index fbf159f53..4ed1b138e 100644 --- a/Telegram/SourceFiles/passport/passport_panel.cpp +++ b/Telegram/SourceFiles/passport/passport_panel.cpp @@ -71,7 +71,6 @@ void Panel::showCriticalError(const QString &error) { object_ptr( _widget.get(), error, - Ui::FlatLabel::InitType::Simple, st::passportErrorLabel), style::margins(0, st::passportPanelSize.height() / 3, 0, 0)); container->widthValue( diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 1bf733cd8..234be2830 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -530,7 +530,6 @@ DateRow::DateRow( object_ptr( this, QString(" / "), - Ui::FlatLabel::InitType::Simple, st::passportDetailsSeparator), st::passportDetailsSeparatorPadding) , _month( @@ -543,7 +542,6 @@ DateRow::DateRow( object_ptr( this, QString(" / "), - Ui::FlatLabel::InitType::Simple, st::passportDetailsSeparator), st::passportDetailsSeparatorPadding) , _year( @@ -1066,7 +1064,6 @@ void PanelDetailsRow::showError(std::optional error) { object_ptr( this, *error, - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel)); } else { _error->entity()->setText(*error); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp index 8ca71db74..6d15e7e07 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp @@ -102,7 +102,6 @@ void VerifyBox::setupControls( object_ptr( _content, text, - Ui::FlatLabel::InitType::Simple, st::boxLabel), small); _code = _content->add( @@ -118,7 +117,6 @@ void VerifyBox::setupControls( object_ptr( _content, QString(), - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel)), small); const auto waiter = _content->add( @@ -256,14 +254,12 @@ void PanelEditContact::setupControls( object_ptr( _content, _scheme.aboutExisting, - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel), st::passportFormLabelPadding)); _content->add( object_ptr( _content, _scheme.newHeader, - Ui::FlatLabel::InitType::Simple, st::passportFormHeader), st::passportDetailsHeaderPadding); } @@ -308,7 +304,6 @@ void PanelEditContact::setupControls( object_ptr( _content, QString(), - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel), st::passportContactErrorPadding), st::passportContactErrorMargin); @@ -320,7 +315,6 @@ void PanelEditContact::setupControls( object_ptr( _content, _scheme.aboutNew, - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel), st::passportFormLabelPadding)); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index b032ffadc..eac8651e1 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -101,14 +101,13 @@ void RequestTypeBox::setupControls( const auto header = Ui::CreateChild( this, lang(lng_passport_document_type), - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel); const auto group = std::make_shared(0); auto buttons = std::vector>(); auto index = 0; for (const auto &label : labels) { - buttons.push_back(Ui::CreateChild( + buttons.emplace_back(Ui::CreateChild( this, group, index++, @@ -119,7 +118,6 @@ void RequestTypeBox::setupControls( const auto description = Ui::CreateChild( this, about, - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel); auto y = 0; @@ -169,7 +167,6 @@ void DeleteDocumentBox::setupControls( const auto label = Ui::CreateChild( this, text, - Ui::FlatLabel::InitType::Simple, st::boxLabel); const auto details = !detailsCheckbox.isEmpty() ? Ui::CreateChild( @@ -377,7 +374,6 @@ not_null PanelEditDocument::setupContent( object_ptr( inner, *error, - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel), st::passportValueErrorPadding)); _commonError->toggle(true, anim::type::instant); @@ -386,7 +382,6 @@ not_null PanelEditDocument::setupContent( object_ptr( inner, data ? _scheme.detailsHeader : _scheme.fieldsHeader, - Ui::FlatLabel::InitType::Simple, st::passportFormHeader), st::passportDetailsHeaderPadding); enumerateRows([&]( diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index c3d979302..a28fdd2fc 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -519,7 +519,6 @@ void EditScans::setupScans(const QString &header) { object_ptr( inner, _error, - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel), st::passportValueErrorPadding)); _commonError->toggle(true, anim::type::instant); @@ -555,7 +554,6 @@ void EditScans::setupList( object_ptr( container, header, - Ui::FlatLabel::InitType::Simple, st::passportFormHeader), st::passportUploadHeaderPadding)); list.header->toggle( @@ -568,7 +566,6 @@ void EditScans::setupList( object_ptr( container, list.errorMissing, - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel), st::passportUploadErrorPadding)); list.uploadMoreError->toggle(true, anim::type::instant); @@ -659,7 +656,6 @@ void EditScans::setupSpecialScans( object_ptr( inner, _error, - Ui::FlatLabel::InitType::Simple, st::passportVerifyErrorLabel), st::passportValueErrorPadding)); _commonError->toggle(true, anim::type::instant); @@ -678,7 +674,6 @@ void EditScans::setupSpecialScans( object_ptr( inner, header, - Ui::FlatLabel::InitType::Simple, st::passportFormHeader), st::passportUploadHeaderPadding)); scan.header->toggle(scan.file.key.id != 0, anim::type::instant); @@ -707,7 +702,6 @@ void EditScans::setupSpecialScans( object_ptr( inner, description(type), - Ui::FlatLabel::InitType::Simple, st::boxDividerLabel), st::passportFormLabelPadding)); } diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index 05a704c7d..f1d2a705e 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/wrap/fade_wrap.h" #include "ui/wrap/padding_wrap.h" +#include "ui/text/text_utilities.h" #include "ui/text_options.h" #include "ui/special_buttons.h" #include "styles/style_passport.h" @@ -232,7 +233,6 @@ not_null PanelForm::setupContent() { object_ptr( inner, lng_passport_request1(lt_bot, App::peerName(bot)), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabelBold)), st::passportFormAbout1Padding)->entity(); @@ -242,7 +242,6 @@ not_null PanelForm::setupContent() { object_ptr( inner, lang(lng_passport_request2), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabel)), st::passportFormAbout2Padding)->entity(); @@ -253,7 +252,6 @@ not_null PanelForm::setupContent() { object_ptr( inner, lang(lng_passport_header), - Ui::FlatLabel::InitType::Simple, st::passportFormHeader), st::passportFormHeaderPadding); @@ -294,24 +292,22 @@ not_null PanelForm::setupContent() { }); }, lifetime()); const auto policyUrl = _controller->privacyPolicyUrl(); + const auto richText = policyUrl.isEmpty() + ? TextWithEntities{ lng_passport_allow(lt_bot, '@' + bot->username) } + : lng_passport_accept_allow__rich( + lt_policy, + Ui::Text::Link( + lng_passport_policy(lt_bot, App::peerName(bot)), + policyUrl), + lt_bot, + TextWithEntities{ '@' + bot->username }); const auto policy = inner->add( object_ptr( inner, - (policyUrl.isEmpty() - ? lng_passport_allow(lt_bot, '@' + bot->username) - : lng_passport_accept_allow( - lt_policy, - textcmdLink( - 1, - lng_passport_policy(lt_bot, App::peerName(bot))), - lt_bot, - '@' + bot->username)), - Ui::FlatLabel::InitType::Rich, + rpl::single(richText), st::passportFormPolicy), st::passportFormPolicyPadding); - if (!policyUrl.isEmpty()) { - policy->setLink(1, std::make_shared(policyUrl)); - } + policy->setLinksTrusted(); return inner; } diff --git a/Telegram/SourceFiles/passport/passport_panel_password.cpp b/Telegram/SourceFiles/passport/passport_panel_password.cpp index dc381e65a..093dadf50 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_password.cpp @@ -36,12 +36,10 @@ PanelAskPassword::PanelAskPassword( , _about1( this, lng_passport_request1(lt_bot, App::peerName(_controller->bot())), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabelBold) , _about2( this, lang(lng_passport_request2), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabel) , _password( this, @@ -59,7 +57,6 @@ PanelAskPassword::PanelAskPassword( _hint.create( this, hint, - Ui::FlatLabel::InitType::Simple, st::passportPasswordHintLabel); } _controller->passwordError( @@ -84,7 +81,6 @@ void PanelAskPassword::showError(const QString &error) { _error.create( this, error, - Ui::FlatLabel::InitType::Simple, st::passportErrorLabel); _error->show(); updateControlsGeometry(); @@ -180,7 +176,6 @@ void PanelNoPassword::setupContent() { lng_passport_request1( lt_bot, App::peerName(_controller->bot())), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabelBold)), st::passportPasswordAbout1Padding)->entity(); @@ -190,7 +185,6 @@ void PanelNoPassword::setupContent() { object_ptr( _inner, lang(lng_passport_request2), - Ui::FlatLabel::InitType::Simple, st::passportPasswordLabel)), st::passportPasswordAbout2Padding)->entity(); @@ -212,7 +206,6 @@ void PanelNoPassword::setupContent() { object_ptr( _inner, lang(lng_passport_create_password), - Ui::FlatLabel::InitType::Simple, st::passportPasswordSetupLabel)), st::passportFormAbout2Padding)->entity(); @@ -229,7 +222,6 @@ void PanelNoPassword::refreshBottom() { (pattern.isEmpty() ? lang(lng_passport_about_password) : lng_passport_code_sent(lt_email, pattern)), - Ui::FlatLabel::InitType::Simple, st::passportPasswordSetupLabel)), st::passportFormAbout2Padding)->entity()); if (pattern.isEmpty()) { diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 50dcd8c65..256e5453a 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -304,7 +304,6 @@ BioManager SetupBio( const auto countdown = Ui::CreateChild( container.get(), QString(), - Ui::FlatLabel::InitType::Simple, st::settingsBioCountdown); rpl::combine( diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index 3de8ef874..33711137f 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -2652,82 +2652,9 @@ void String::setMarkedText(const style::TextStyle &st, const TextWithEntities &t recountNaturalSize(true, options.dir); } -void String::setRichText(const style::TextStyle &st, const QString &text, TextParseOptions options, const TextCustomTagsMap &custom) { - QString parsed; - parsed.reserve(text.size()); - const QChar *s = text.constData(), *ch = s; - for (const QChar *b = s, *e = b + text.size(); ch != e; ++ch) { - if (ch->unicode() == '\\') { - if (ch > s) parsed.append(s, ch - s); - s = ch + 1; - - if (s < e) ++ch; - continue; - } - if (ch->unicode() == '[') { - if (ch > s) parsed.append(s, ch - s); - s = ch; - - const QChar *tag = ch + 1; - if (tag >= e) continue; - - bool closing = false, other = false; - if (tag->unicode() == '/') { - closing = true; - if (++tag >= e) continue; - } - - TextCommands cmd; - switch (tag->unicode()) { - case 'b': cmd = closing ? TextCommandNoBold : TextCommandBold; break; - case 'i': cmd = closing ? TextCommandNoItalic : TextCommandItalic; break; - case 'u': cmd = closing ? TextCommandNoUnderline : TextCommandUnderline; break; - default : other = true; break; - } - - if (!other) { - if (++tag >= e || tag->unicode() != ']') continue; - parsed.append(TextCommand).append(QChar(cmd)).append(TextCommand); - ch = tag; - s = ch + 1; - continue; - } - - if (tag->unicode() != 'a') { - TextCustomTagsMap::const_iterator i = custom.constFind(*tag); - if (++tag >= e || tag->unicode() != ']' || i == custom.cend()) continue; - parsed.append(closing ? i->second : i->first); - ch = tag; - s = ch + 1; - continue; - } - - if (closing) { - if (++tag >= e || tag->unicode() != ']') continue; - parsed.append(textcmdStopLink()); - ch = tag; - s = ch + 1; - continue; - } - if (++tag >= e || tag->unicode() != ' ') continue; - while (tag < e && tag->unicode() == ' ') ++tag; - if (tag + 5 < e && text.midRef(tag - b, 6) == qsl("href=\"")) { - tag += 6; - const QChar *tagend = tag; - while (tagend < e && tagend->unicode() != '"') ++tagend; - if (++tagend >= e || tagend->unicode() != ']') continue; - parsed.append(textcmdStartLink(QString(tag, tagend - 1 - tag))); - ch = tagend; - s = ch + 1; - continue; - } - } - } - if (ch > s) parsed.append(s, ch - s); - s = ch; - +void String::setRichText(const style::TextStyle &st, const QString &text, TextParseOptions options) { options.flags |= TextParseRichText; - setText(st, parsed, options); + setText(st, text, options); } void String::setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk) { diff --git a/Telegram/SourceFiles/ui/text/text.h b/Telegram/SourceFiles/ui/text/text.h index 90af49b51..7f50bb6d6 100644 --- a/Telegram/SourceFiles/ui/text/text.h +++ b/Telegram/SourceFiles/ui/text/text.h @@ -64,9 +64,6 @@ inline bool operator!=(TextSelection a, TextSelection b) { static constexpr TextSelection AllTextSelection = { 0, 0xFFFF }; -typedef QPair TextCustomTag; // open str and close str -typedef QMap TextCustomTagsMap; - namespace Ui { namespace Text { @@ -118,7 +115,7 @@ public: int countHeight(int width) const; void countLineWidths(int width, QVector *lineWidths) const; void setText(const style::TextStyle &st, const QString &text, const TextParseOptions &options = _defaultOptions); - void setRichText(const style::TextStyle &st, const QString &text, TextParseOptions options = _defaultOptions, const TextCustomTagsMap &custom = TextCustomTagsMap()); + void setRichText(const style::TextStyle &st, const QString &text, TextParseOptions options = _defaultOptions); void setMarkedText(const style::TextStyle &st, const TextWithEntities &textWithEntities, const TextParseOptions &options = _defaultOptions); void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk); diff --git a/Telegram/SourceFiles/ui/text/text_utilities.cpp b/Telegram/SourceFiles/ui/text/text_utilities.cpp index 4ca4b040f..2eb58f39e 100644 --- a/Telegram/SourceFiles/ui/text/text_utilities.cpp +++ b/Telegram/SourceFiles/ui/text/text_utilities.cpp @@ -9,10 +9,56 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { namespace Text { +namespace { + +TextWithEntities WithSingleEntity( + const QString &text, + EntityType type, + const QString &data = QString()) { + auto result = TextWithEntities{ text }; + result.entities.push_back({ type, 0, text.size(), data }); + return result; +} + +} // namespace TextWithEntities Bold(const QString &text) { - auto result = TextWithEntities{ text }; - result.entities.push_back({ EntityType::Bold, 0, text.size() }); + return WithSingleEntity(text, EntityType::Bold); +} + +TextWithEntities Link(const QString &text, const QString &url) { + return WithSingleEntity(text, EntityType::CustomUrl, url); +} + +TextWithEntities RichLangValue(const QString &text) { + static const auto kStart = QRegularExpression("(\\*\\*|__)"); + + auto result = TextWithEntities(); + auto offset = 0; + while (offset < text.size()) { + const auto m = kStart.match(text, offset); + if (!m.hasMatch()) { + result.text.append(text.midRef(offset)); + break; + } + const auto position = m.capturedStart(); + const auto from = m.capturedEnd(); + const auto tag = m.capturedRef(); + const auto till = text.indexOf(tag, from + 1); + if (till <= from) { + offset = from; + continue; + } + if (position > offset) { + result.text.append(text.midRef(offset, position - offset)); + } + const auto type = (tag == qstr("__")) + ? EntityType::Italic + : EntityType::Bold; + result.entities.push_back({ type, result.text.size(), till - from }); + result.text.append(text.midRef(from, till - from)); + offset = till + tag.size(); + } return result; } diff --git a/Telegram/SourceFiles/ui/text/text_utilities.h b/Telegram/SourceFiles/ui/text/text_utilities.h index b81197c73..164d65eb6 100644 --- a/Telegram/SourceFiles/ui/text/text_utilities.h +++ b/Telegram/SourceFiles/ui/text/text_utilities.h @@ -10,17 +10,31 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { namespace Text { -TextWithEntities Bold(const QString &text); - -inline auto ToBold() { - return rpl::map(Bold); -} - inline auto ToUpper() { return rpl::map([](QString &&text) { return std::move(text).toUpper(); }); } +TextWithEntities Bold(const QString &text); +TextWithEntities Link( + const QString &text, + const QString &url = "internal:action"); +TextWithEntities RichLangValue(const QString &text); + +inline auto ToBold() { + return rpl::map(Bold); +} + +inline auto ToLink(const QString &url = "internal:action") { + return rpl::map([=](const QString &text) { + return Link(text, url); + }); +} + +inline auto ToRichLangValue() { + return rpl::map(RichLangValue); +} + } // namespace Text } // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/labels.cpp b/Telegram/SourceFiles/ui/widgets/labels.cpp index 4e4753f65..9bdf8bbd0 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.cpp +++ b/Telegram/SourceFiles/ui/widgets/labels.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/popup_menu.h" +#include "core/click_handler_types.h" // UrlClickHandler #include "chat_helpers/message_field.h" // SetClipboardText/MimeDataFromText #include "mainwindow.h" #include "lang/lang_keys.h" @@ -140,17 +141,12 @@ FlatLabel::FlatLabel(QWidget *parent, const style::FlatLabel &st) FlatLabel::FlatLabel( QWidget *parent, const QString &text, - InitType initType, const style::FlatLabel &st) : RpWidget(parent) , _text(st.minWidth ? st.minWidth : QFIXED_MAX) , _st(st) , _contextCopyText(lang(lng_context_copy_text)) { - if (initType == InitType::Rich) { - setRichText(text); - } else { - setText(text); - } + setText(text); init(); } @@ -289,6 +285,20 @@ void FlatLabel::setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk) { _text.setLink(lnkIndex, lnk); } +void FlatLabel::setLinksTrusted() { + static const auto TrustedLinksFilter = []( + const ClickHandlerPtr &link, + Qt::MouseButton button) { + if (const auto url = dynamic_cast(link.get())) { + url->UrlClickHandler::onClick({ button }); + return false; + } + return true; + }; + setClickHandlerFilter(TrustedLinksFilter); + +} + void FlatLabel::setClickHandlerFilter(ClickHandlerFilter &&filter) { _clickHandlerFilter = std::move(filter); } diff --git a/Telegram/SourceFiles/ui/widgets/labels.h b/Telegram/SourceFiles/ui/widgets/labels.h index 18fce8a88..7741992c3 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.h +++ b/Telegram/SourceFiles/ui/widgets/labels.h @@ -77,14 +77,9 @@ class FlatLabel : public RpWidget, public ClickHandlerHost { public: FlatLabel(QWidget *parent, const style::FlatLabel &st = st::defaultFlatLabel); - enum class InitType { - Simple, - Rich, - }; FlatLabel( QWidget *parent, const QString &text, - InitType initType, const style::FlatLabel &st = st::defaultFlatLabel); FlatLabel( @@ -112,6 +107,7 @@ public: QMargins getMargins() const override; void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk); + void setLinksTrusted(); using ClickHandlerFilter = Fn; void setClickHandlerFilter(ClickHandlerFilter &&filter); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 6f9020831..09f3390d0 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/menu.h" #include "ui/widgets/popup_menu.h" +#include "ui/text/text_utilities.h" #include "ui/special_buttons.h" #include "ui/empty_userpic.h" #include "mainwindow.h" @@ -58,7 +59,7 @@ bool IsShadowShown(const QImage &img, const QRect r, float64 intensityText) { return false; } -} +} // namespace namespace Window { @@ -192,8 +193,10 @@ MainMenu::MainMenu( refreshMenu(); refreshBackground(); - _telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop"))); - _telegram->setLink(1, std::make_shared(qsl("https://desktop.telegram.org"))); + _telegram->setMarkedText(Ui::Text::Link( + qsl("Telegram Desktop"), + qsl("https://desktop.telegram.org"))); + _telegram->setLinksTrusted(); _version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about))); _version->setLink(1, std::make_shared(qsl("https://desktop.telegram.org/changelog"))); _version->setLink(2, std::make_shared([] { Ui::show(Box()); })); diff --git a/Telegram/SourceFiles/window/window_outdated_bar.cpp b/Telegram/SourceFiles/window/window_outdated_bar.cpp index 37649416b..8614f32fd 100644 --- a/Telegram/SourceFiles/window/window_outdated_bar.cpp +++ b/Telegram/SourceFiles/window/window_outdated_bar.cpp @@ -50,7 +50,6 @@ Bar::Bar(not_null parent, QDate date) st::windowOutdatedTitle) , _details(this, QString(), - Ui::FlatLabel::InitType::Simple, st::windowOutdatedDetails) , _close(this, st::windowOutdatedClose) , _soon(_date >= QDate::currentDate()) { diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index fa89ff510..eeaaead92 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -715,7 +715,7 @@ void PeerMenuBlockUserBox( box->addRow(object_ptr( box, rpl::single( - lng_blocked_list_confirm_text__generic( + lng_blocked_list_confirm_text__rich( lt_name, Ui::Text::Bold(name))), st::blockUserConfirmation));