Display user Bio in profile.

This commit is contained in:
John Preston 2017-07-18 19:03:11 +03:00
parent 34d2e78308
commit 7ff175a81e
3 changed files with 58 additions and 19 deletions

View File

@ -105,6 +105,10 @@ profileBlockOneLineTextPart: FlatLabel(profileBlockTextPart) {
width: 0px; // No need to set minWidth in one-line text. width: 0px; // No need to set minWidth in one-line text.
maxHeight: 20px; maxHeight: 20px;
} }
profileBioLabel: FlatLabel(profileBlockOneLineTextPart) {
width: 120px;
maxHeight: 0px;
}
profileBlockOneLineSkip: 9px; profileBlockOneLineSkip: 9px;
profileBlockOneLineWidthMax: 240px; profileBlockOneLineWidthMax: 240px;

View File

@ -110,10 +110,11 @@ int InfoWidget::resizeGetHeight(int newWidth) {
text->show(); 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(_channelLinkLabel, _channelLink, _channelLinkShort);
moveLabeledText(_mobileNumberLabel, _mobileNumber, nullptr); moveLabeledText(_mobileNumberLabel, _mobileNumber, nullptr);
moveLabeledText(_bioLabel, _bio, nullptr);
moveLabeledText(_usernameLabel, _username, nullptr); moveLabeledText(_usernameLabel, _username, nullptr);
newHeight += st::profileBlockMarginBottom; newHeight += st::profileBlockMarginBottom;
@ -135,7 +136,7 @@ void InfoWidget::refreshLabels() {
} }
void InfoWidget::refreshVisibility() { void InfoWidget::refreshVisibility() {
setVisible(_about || _mobileNumber || _username || _channelLink); setVisible(_about || _mobileNumber || _username || _bio || _channelLink);
} }
void InfoWidget::refreshAbout() { void InfoWidget::refreshAbout() {
@ -149,18 +150,33 @@ void InfoWidget::refreshAbout() {
}; };
_about.destroy(); _about.destroy();
_bioLabel.destroy();
_bio.destroy();
auto aboutText = TextWithEntities { TextUtilities::Clean(getAboutText()) }; 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()) { if (!aboutText.text.isEmpty()) {
_about.create(this, st::profileBlockTextPart); if (displayAsBio) {
_about->show(); 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); TextUtilities::ParseEntities(aboutText, TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands);
_about->setMarkedText(aboutText); _about->setMarkedText(aboutText);
_about->setSelectable(true); _about->setSelectable(true);
_about->setClickHandlerHook([this](const ClickHandlerPtr &handler, Qt::MouseButton button) { _about->setClickHandlerHook([this](const ClickHandlerPtr &handler, Qt::MouseButton button) {
BotCommandClickHandler::setPeerForCommand(peer()); BotCommandClickHandler::setPeerForCommand(peer());
return true; return true;
}); });
}
} }
} }
@ -173,7 +189,7 @@ void InfoWidget::refreshMobileNumber() {
phoneText.text = App::phoneFromSharedContact(peerToUser(user->id)); 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() { void InfoWidget::refreshUsername() {
@ -183,7 +199,7 @@ void InfoWidget::refreshUsername() {
usernameText.text = '@' + user->username; 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() { 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))); channelLinkTextShort.entities.push_back(EntityInText(EntityInTextCustomUrl, 0, channelLinkTextShort.text.size(), Messenger::Instance().createInternalLinkFull(channel->username)));
} }
} }
setLabeledText(nullptr, lang(lng_profile_link), &_channelLink, channelLinkText, QString()); setSingleLineLabeledText(nullptr, lang(lng_profile_link), &_channelLink, channelLinkText, QString());
setLabeledText(&_channelLinkLabel, lang(lng_profile_link), &_channelLinkShort, channelLinkTextShort, QString()); setSingleLineLabeledText(&_channelLinkLabel, lang(lng_profile_link), &_channelLinkShort, channelLinkTextShort, QString());
if (_channelLinkShort) { if (_channelLinkShort) {
_channelLinkShort->setExpandLinksMode(ExpandLinksUrlOnly); _channelLinkShort->setExpandLinksMode(ExpandLinksUrlOnly);
} }
} }
void InfoWidget::setLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label, void InfoWidget::setLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label,
object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities, const QString &copyText) { object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities,
const style::FlatLabel &st, const QString &copyText) {
if (labelWidget) labelWidget->destroy(); if (labelWidget) labelWidget->destroy();
textWidget->destroy(); textWidget->destroy();
if (textWithEntities.text.isEmpty()) return; if (textWithEntities.text.isEmpty()) {
return;
}
if (labelWidget) { if (labelWidget) {
labelWidget->create(this, label, Ui::FlatLabel::InitType::Simple, st::profileBlockLabel); labelWidget->create(this, label, Ui::FlatLabel::InitType::Simple, st::profileBlockLabel);
(*labelWidget)->show(); (*labelWidget)->show();
} }
textWidget->create(this, QString(), Ui::FlatLabel::InitType::Simple, st::profileBlockOneLineTextPart); textWidget->create(this, QString(), Ui::FlatLabel::InitType::Simple, st);
(*textWidget)->show(); (*textWidget)->show();
(*textWidget)->setMarkedText(textWithEntities); (*textWidget)->setMarkedText(textWithEntities);
(*textWidget)->setContextCopyText(copyText); (*textWidget)->setContextCopyText(copyText);
(*textWidget)->setSelectable(true); (*textWidget)->setSelectable(true);
(*textWidget)->setDoubleClickSelectsParagraph(true); }
void InfoWidget::setSingleLineLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label,
object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities, const QString &copyText) {
setLabeledText(labelWidget, label, textWidget, textWithEntities, st::profileBlockOneLineTextPart, copyText);
if (*textWidget) {
(*textWidget)->setDoubleClickSelectsParagraph(true);
}
} }
} // namespace Profile } // namespace Profile

View File

@ -22,6 +22,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "profile/profile_block_widget.h" #include "profile/profile_block_widget.h"
namespace style {
struct FlatLabel;
} // namespace style
namespace Ui { namespace Ui {
class FlatLabel; class FlatLabel;
} // namespace Ui } // namespace Ui
@ -55,6 +59,9 @@ private:
// labelWidget may be nullptr. // labelWidget may be nullptr.
void setLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label, void setLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label,
object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities,
const style::FlatLabel &st, const QString &copyText);
void setSingleLineLabeledText(object_ptr<Ui::FlatLabel> *labelWidget, const QString &label,
object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities, const QString &copyText); object_ptr<Ui::FlatLabel> *textWidget, const TextWithEntities &textWithEntities, const QString &copyText);
object_ptr<Ui::FlatLabel> _about = { nullptr }; object_ptr<Ui::FlatLabel> _about = { nullptr };
@ -63,6 +70,8 @@ private:
object_ptr<Ui::FlatLabel> _channelLinkShort = { nullptr }; object_ptr<Ui::FlatLabel> _channelLinkShort = { nullptr };
object_ptr<Ui::FlatLabel> _mobileNumberLabel = { nullptr }; object_ptr<Ui::FlatLabel> _mobileNumberLabel = { nullptr };
object_ptr<Ui::FlatLabel> _mobileNumber = { nullptr }; object_ptr<Ui::FlatLabel> _mobileNumber = { nullptr };
object_ptr<Ui::FlatLabel> _bioLabel = { nullptr };
object_ptr<Ui::FlatLabel> _bio = { nullptr };
object_ptr<Ui::FlatLabel> _usernameLabel = { nullptr }; object_ptr<Ui::FlatLabel> _usernameLabel = { nullptr };
object_ptr<Ui::FlatLabel> _username = { nullptr }; object_ptr<Ui::FlatLabel> _username = { nullptr };