diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index e0a52d749..46b7d06c8 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -593,10 +593,13 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { } } if (!_mrows->isEmpty()) { - UserData *user = _mrows->at(i); - QString first = (!filterIsEmpty && user->username.startsWith(filter, Qt::CaseInsensitive)) ? ('@' + user->username.mid(0, filterSize)) : QString(); - QString second = first.isEmpty() ? (user->username.isEmpty() ? QString() : ('@' + user->username)) : user->username.mid(filterSize); - int32 firstwidth = st::mentionFont->width(first), secondwidth = st::mentionFont->width(second), unamewidth = firstwidth + secondwidth, namewidth = user->nameText.maxWidth(); + const auto user = _mrows->at(i); + auto first = (!filterIsEmpty && user->username.startsWith(filter, Qt::CaseInsensitive)) ? ('@' + user->username.mid(0, filterSize)) : QString(); + auto second = first.isEmpty() ? (user->username.isEmpty() ? QString() : ('@' + user->username)) : user->username.mid(filterSize); + auto firstwidth = st::mentionFont->width(first); + auto secondwidth = st::mentionFont->width(second); + auto unamewidth = firstwidth + secondwidth; + auto namewidth = user->nameText().maxWidth(); if (mentionwidth < unamewidth + namewidth) { namewidth = (mentionwidth * namewidth) / (namewidth + unamewidth); unamewidth = mentionwidth - namewidth; @@ -615,7 +618,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { user->paintUserpicLeft(p, st::mentionPadding.left(), i * st::mentionHeight + st::mentionPadding.top(), width(), st::mentionPhotoSize); p.setPen(selected ? st::mentionNameFgOver : st::mentionNameFg); - user->nameText.drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth); + user->nameText().drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth); p.setFont(st::mentionFont); p.setPen(selected ? st::mentionFgOverActive : st::mentionFgActive); diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 0559214d4..be455c3b8 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -100,7 +100,7 @@ PeerData::PeerData(not_null owner, PeerId id) : id(id) , _owner(owner) , _userpicEmpty(createEmptyUserpic()) { - nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions()); + _nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions()); } Data::Session &PeerData::owner() const { @@ -134,7 +134,7 @@ void PeerData::updateNameDelayed( } } name = newName; - nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); + _nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); refreshEmptyUserpic(); Notify::PeerUpdate update(this); if (nameVersion++ > 1) { @@ -592,12 +592,22 @@ not_null PeerData::migrateToOrMe() const { return this; } -const Text &PeerData::dialogName() const { - return migrateTo() - ? migrateTo()->dialogName() - : (isUser() && !asUser()->phoneText.isEmpty()) - ? asUser()->phoneText - : nameText; +const Text &PeerData::topBarNameText() const { + if (const auto to = migrateTo()) { + return to->topBarNameText(); + } else if (const auto user = asUser()) { + if (!user->phoneText.isEmpty()) { + return user->phoneText; + } + } + return _nameText; +} + +const Text &PeerData::nameText() const { + if (const auto to = migrateTo()) { + return to->nameText(); + } + return _nameText; } const QString &PeerData::shortName() const { diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 8d3bb1e55..53a074e6c 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -204,8 +204,9 @@ public: return (_lastFullUpdate != 0); } - [[nodiscard]] const Text &dialogName() const; + [[nodiscard]] const Text &nameText() const; [[nodiscard]] const QString &shortName() const; + [[nodiscard]] const Text &topBarNameText() const; [[nodiscard]] QString userName() const; [[nodiscard]] int32 bareId() const { @@ -324,7 +325,6 @@ public: const PeerId id; QString name; - Text nameText; LoadedStatus loadedStatus = NotLoaded; MTPinputPeer input; @@ -359,6 +359,7 @@ private: PhotoId _userpicPhotoId = kUnknownPhotoId; mutable std::unique_ptr _userpicEmpty; StorageImageLocation _userpicLocation; + Text _nameText; Data::NotifySettings _notify; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index e6da771ea..0072d9407 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -733,7 +733,7 @@ void InnerWidget::paintPeerSearchResult( if (peer->isVerified()) { auto icon = &(active ? st::dialogsVerifiedIconActive : (selected ? st::dialogsVerifiedIconOver : st::dialogsVerifiedIcon)); rectForName.setWidth(rectForName.width() - icon->width()); - icon->paint(p, rectForName.topLeft() + QPoint(qMin(peer->dialogName().maxWidth(), rectForName.width()), 0), fullWidth); + icon->paint(p, rectForName.topLeft() + QPoint(qMin(peer->nameText().maxWidth(), rectForName.width()), 0), fullWidth); } QRect tr(nameleft, st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip, namewidth, st::dialogsTextFont->height); @@ -758,7 +758,7 @@ void InnerWidget::paintPeerSearchResult( } p.setPen(active ? st::dialogsTextFgActive : st::dialogsNameFg); - peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + peer->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } void InnerWidget::paintSearchInChat(Painter &p) const { diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 9f6582d4c..1bae8fcf8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -424,9 +424,9 @@ void paintRow( if (!(flags & Flag::SearchResult) && from->isVerified()) { auto icon = &(active ? st::dialogsVerifiedIconActive : (selected ? st::dialogsVerifiedIconOver : st::dialogsVerifiedIcon)); rectForName.setWidth(rectForName.width() - icon->width()); - icon->paint(p, rectForName.topLeft() + QPoint(qMin(from->dialogName().maxWidth(), rectForName.width()), 0), fullWidth); + icon->paint(p, rectForName.topLeft() + QPoint(qMin(from->nameText().maxWidth(), rectForName.width()), 0), fullWidth); } - from->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + from->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else if (hiddenSenderInfo) { hiddenSenderInfo->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index c1e6fc22b..697236c35 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -117,7 +117,7 @@ void UserCheckbox::paintEvent(QPaintEvent *e) { auto nameTop = userpicTop + st::contactsNameTop; auto nameWidth = width() - nameLeft - st::contactsPadding.right(); p.setPen(st::contactsNameFg); - _user->nameText.drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); + _user->nameText().drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); auto statusLeft = nameLeft; auto statusTop = userpicTop + st::contactsStatusTop; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 4ceed10b0..0d02502ae 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -295,7 +295,7 @@ QSize Message::performCountOptimalSize() { if (displayFromName()) { const auto from = item->displayFrom(); const auto &name = from - ? from->nameText + ? from->nameText() : item->hiddenForwardedInfo()->nameText; auto namew = st::msgPadding.left() + name.maxWidth() @@ -548,10 +548,10 @@ void Message::paintFromName( const auto from = item->displayFrom(); if (item->isPost()) { p.setPen(selected ? st::msgInServiceFgSelected : st::msgInServiceFg); - return &from->nameText; + return &from->nameText(); } else if (from) { p.setPen(FromNameFg(from->id, selected)); - return &from->nameText; + return &from->nameText(); } else if (const auto info = item->hiddenForwardedInfo()) { p.setPen(FromNameFg(info->colorPeerId, selected)); return &info->nameText; @@ -888,7 +888,7 @@ bool Message::getStateFromName( const auto from = item->displayFrom(); const auto nameText = [&]() -> const Text* { if (from) { - return &from->nameText; + return &from->nameText(); } else if (const auto info = item->hiddenForwardedInfo()) { return &info->nameText; } else { @@ -1563,7 +1563,7 @@ void Message::fromNameUpdated(int width) const { if (!displayForwardedFrom()) { const auto nameText = [&]() -> const Text* { if (from) { - return &from->nameText; + return &from->nameText(); } else if (const auto info = item->hiddenForwardedInfo()) { return &info->nameText; } else { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index de45de84a..23e18a013 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -334,7 +334,7 @@ void TopBarWidget::paintTopBar(Painter &p) { width(), text); } else if (const auto history = _activeChat.history()) { - history->peer->dialogName().drawElided(p, nameleft, nametop, namewidth); + history->peer->topBarNameText().drawElided(p, nameleft, nametop, namewidth); p.setFont(st::dialogsTextFont); if (paintConnectingState(p, nameleft, statustop, width())) { diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 1195d9af1..824a350e1 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -716,7 +716,7 @@ void Notification::updateNotifyDisplay() { p.setPen(st::dialogsNameFg); if (!options.hideNameAndPhoto) { - _history->peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); + _history->peer->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width()); } else { p.setFont(st::msgNameFont); static QString notifyTitle = st::msgNameFont->elided(qsl("Telegram Desktop"), rectForName.width()); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 32b3d6f3b..6f9020831 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -332,7 +332,7 @@ void MainMenu::refreshBackground() { st::mainMenuCoverTextLeft, st::mainMenuCoverNameTop, std::max( - st::semiboldFont->width(Auth().user()->nameText.toString()), + st::semiboldFont->width(Auth().user()->nameText().toString()), st::normalFont->width(_phoneText)), st::semiboldFont->height * 2); @@ -405,7 +405,7 @@ void MainMenu::paintEvent(QPaintEvent *e) { } p.setPen(st::mainMenuCoverFg); p.setFont(st::semiboldFont); - Auth().user()->nameText.drawLeftElided( + Auth().user()->nameText().drawLeftElided( p, st::mainMenuCoverTextLeft, st::mainMenuCoverNameTop,