From 7ff175a81ef71695f38d1e8918fa0f2e086f615c Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 18 Jul 2017 19:03:11 +0300 Subject: [PATCH] Display user Bio in profile. --- Telegram/SourceFiles/profile/profile.style | 4 ++ .../profile/profile_block_info.cpp | 64 +++++++++++++------ .../SourceFiles/profile/profile_block_info.h | 9 +++ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/profile/profile.style b/Telegram/SourceFiles/profile/profile.style index 44c0bb89a5..47a13559ab 100644 --- a/Telegram/SourceFiles/profile/profile.style +++ b/Telegram/SourceFiles/profile/profile.style @@ -105,6 +105,10 @@ profileBlockOneLineTextPart: FlatLabel(profileBlockTextPart) { width: 0px; // No need to set minWidth in one-line text. maxHeight: 20px; } +profileBioLabel: FlatLabel(profileBlockOneLineTextPart) { + width: 120px; + maxHeight: 0px; +} profileBlockOneLineSkip: 9px; profileBlockOneLineWidthMax: 240px; diff --git a/Telegram/SourceFiles/profile/profile_block_info.cpp b/Telegram/SourceFiles/profile/profile_block_info.cpp index b75fa574ba..7f0be60820 100644 --- a/Telegram/SourceFiles/profile/profile_block_info.cpp +++ b/Telegram/SourceFiles/profile/profile_block_info.cpp @@ -110,10 +110,11 @@ int InfoWidget::resizeGetHeight(int newWidth) { text->show(); } } - newHeight += label->height() + st::profileBlockOneLineSkip; + newHeight += qMax(label->height(), text->height() - st::profileBlockTextPart.margin.top() - st::profileBlockTextPart.margin.bottom()) + st::profileBlockOneLineSkip; }; moveLabeledText(_channelLinkLabel, _channelLink, _channelLinkShort); moveLabeledText(_mobileNumberLabel, _mobileNumber, nullptr); + moveLabeledText(_bioLabel, _bio, nullptr); moveLabeledText(_usernameLabel, _username, nullptr); newHeight += st::profileBlockMarginBottom; @@ -135,7 +136,7 @@ void InfoWidget::refreshLabels() { } void InfoWidget::refreshVisibility() { - setVisible(_about || _mobileNumber || _username || _channelLink); + setVisible(_about || _mobileNumber || _username || _bio || _channelLink); } void InfoWidget::refreshAbout() { @@ -149,18 +150,33 @@ void InfoWidget::refreshAbout() { }; _about.destroy(); + _bioLabel.destroy(); + _bio.destroy(); auto aboutText = TextWithEntities { TextUtilities::Clean(getAboutText()) }; + auto displayAsBio = false; + if (auto user = peer()->asUser()) { + if (!user->botInfo) { + displayAsBio = true; + } + } + if (displayAsBio) { + aboutText.text = TextUtilities::SingleLine(aboutText.text); + } if (!aboutText.text.isEmpty()) { - _about.create(this, st::profileBlockTextPart); - _about->show(); + if (displayAsBio) { + setLabeledText(&_bioLabel, lang(lng_profile_bio), &_bio, aboutText, st::profileBioLabel, QString()); + } else { + _about.create(this, st::profileBlockTextPart); + _about->show(); - TextUtilities::ParseEntities(aboutText, TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands); - _about->setMarkedText(aboutText); - _about->setSelectable(true); - _about->setClickHandlerHook([this](const ClickHandlerPtr &handler, Qt::MouseButton button) { - BotCommandClickHandler::setPeerForCommand(peer()); - return true; - }); + TextUtilities::ParseEntities(aboutText, TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands); + _about->setMarkedText(aboutText); + _about->setSelectable(true); + _about->setClickHandlerHook([this](const ClickHandlerPtr &handler, Qt::MouseButton button) { + BotCommandClickHandler::setPeerForCommand(peer()); + return true; + }); + } } } @@ -173,7 +189,7 @@ void InfoWidget::refreshMobileNumber() { phoneText.text = App::phoneFromSharedContact(peerToUser(user->id)); } } - setLabeledText(&_mobileNumberLabel, lang(lng_profile_mobile_number), &_mobileNumber, phoneText, lang(lng_profile_copy_phone)); + setSingleLineLabeledText(&_mobileNumberLabel, lang(lng_profile_mobile_number), &_mobileNumber, phoneText, lang(lng_profile_copy_phone)); } void InfoWidget::refreshUsername() { @@ -183,7 +199,7 @@ void InfoWidget::refreshUsername() { usernameText.text = '@' + user->username; } } - setLabeledText(&_usernameLabel, lang(lng_profile_username), &_username, usernameText, lang(lng_context_copy_mention)); + setSingleLineLabeledText(&_usernameLabel, lang(lng_profile_username), &_username, usernameText, lang(lng_context_copy_mention)); } void InfoWidget::refreshChannelLink() { @@ -197,29 +213,39 @@ void InfoWidget::refreshChannelLink() { channelLinkTextShort.entities.push_back(EntityInText(EntityInTextCustomUrl, 0, channelLinkTextShort.text.size(), Messenger::Instance().createInternalLinkFull(channel->username))); } } - setLabeledText(nullptr, lang(lng_profile_link), &_channelLink, channelLinkText, QString()); - setLabeledText(&_channelLinkLabel, lang(lng_profile_link), &_channelLinkShort, channelLinkTextShort, QString()); + setSingleLineLabeledText(nullptr, lang(lng_profile_link), &_channelLink, channelLinkText, QString()); + setSingleLineLabeledText(&_channelLinkLabel, lang(lng_profile_link), &_channelLinkShort, channelLinkTextShort, QString()); if (_channelLinkShort) { _channelLinkShort->setExpandLinksMode(ExpandLinksUrlOnly); } } void InfoWidget::setLabeledText(object_ptr *labelWidget, const QString &label, - object_ptr *textWidget, const TextWithEntities &textWithEntities, const QString ©Text) { + object_ptr *textWidget, const TextWithEntities &textWithEntities, + const style::FlatLabel &st, const QString ©Text) { if (labelWidget) labelWidget->destroy(); textWidget->destroy(); - if (textWithEntities.text.isEmpty()) return; + if (textWithEntities.text.isEmpty()) { + return; + } if (labelWidget) { labelWidget->create(this, label, Ui::FlatLabel::InitType::Simple, st::profileBlockLabel); (*labelWidget)->show(); } - textWidget->create(this, QString(), Ui::FlatLabel::InitType::Simple, st::profileBlockOneLineTextPart); + textWidget->create(this, QString(), Ui::FlatLabel::InitType::Simple, st); (*textWidget)->show(); (*textWidget)->setMarkedText(textWithEntities); (*textWidget)->setContextCopyText(copyText); (*textWidget)->setSelectable(true); - (*textWidget)->setDoubleClickSelectsParagraph(true); +} + +void InfoWidget::setSingleLineLabeledText(object_ptr *labelWidget, const QString &label, + object_ptr *textWidget, const TextWithEntities &textWithEntities, const QString ©Text) { + setLabeledText(labelWidget, label, textWidget, textWithEntities, st::profileBlockOneLineTextPart, copyText); + if (*textWidget) { + (*textWidget)->setDoubleClickSelectsParagraph(true); + } } } // namespace Profile diff --git a/Telegram/SourceFiles/profile/profile_block_info.h b/Telegram/SourceFiles/profile/profile_block_info.h index 1b35e0122f..8873c13d53 100644 --- a/Telegram/SourceFiles/profile/profile_block_info.h +++ b/Telegram/SourceFiles/profile/profile_block_info.h @@ -22,6 +22,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "profile/profile_block_widget.h" +namespace style { +struct FlatLabel; +} // namespace style + namespace Ui { class FlatLabel; } // namespace Ui @@ -55,6 +59,9 @@ private: // labelWidget may be nullptr. void setLabeledText(object_ptr *labelWidget, const QString &label, + object_ptr *textWidget, const TextWithEntities &textWithEntities, + const style::FlatLabel &st, const QString ©Text); + void setSingleLineLabeledText(object_ptr *labelWidget, const QString &label, object_ptr *textWidget, const TextWithEntities &textWithEntities, const QString ©Text); object_ptr _about = { nullptr }; @@ -63,6 +70,8 @@ private: object_ptr _channelLinkShort = { nullptr }; object_ptr _mobileNumberLabel = { nullptr }; object_ptr _mobileNumber = { nullptr }; + object_ptr _bioLabel = { nullptr }; + object_ptr _bio = { nullptr }; object_ptr _usernameLabel = { nullptr }; object_ptr _username = { nullptr };