Fix admin custom status text in supergroups.

This commit is contained in:
John Preston 2017-06-28 08:57:58 +03:00
parent b398444b91
commit 8ee5c70708
3 changed files with 22 additions and 11 deletions

View File

@ -330,7 +330,7 @@ bool PeerListRow::checked() const {
} }
void PeerListRow::setCustomStatus(const QString &status) { void PeerListRow::setCustomStatus(const QString &status) {
_status = status; setStatusText(status);
_statusType = StatusType::Custom; _statusType = StatusType::Custom;
} }
@ -345,7 +345,7 @@ void PeerListRow::refreshStatus() {
} }
if (auto user = peer()->asUser()) { if (auto user = peer()->asUser()) {
auto time = unixtime(); auto time = unixtime();
_status = App::onlineText(user, time); setStatusText(App::onlineText(user, time));
_statusType = App::onlineColorUse(user, time) ? StatusType::Online : StatusType::LastSeen; _statusType = App::onlineColorUse(user, time) ? StatusType::Online : StatusType::LastSeen;
} }
} }
@ -365,10 +365,11 @@ void PeerListRow::invalidatePixmapsCache() {
} }
} }
void PeerListRow::paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) { void PeerListRow::paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) {
auto statusHasOnlineColor = (_statusType == PeerListRow::StatusType::Online); auto statusHasOnlineColor = (_statusType == PeerListRow::StatusType::Online);
p.setFont(st::contactsStatusFont);
p.setPen(statusHasOnlineColor ? st::contactsStatusFgOnline : (selected ? st::contactsStatusFgOver : st::contactsStatusFg)); p.setPen(statusHasOnlineColor ? st::contactsStatusFgOnline : (selected ? st::contactsStatusFgOver : st::contactsStatusFg));
p.drawTextLeft(x, y, outerWidth, _status); p.drawTextLeft(x, y, outerWidth, (_statusWidth <= availableWidth) ? _status : st::contactsStatusFont->elided(_status, availableWidth));
} }
template <typename UpdateCallback> template <typename UpdateCallback>
@ -442,6 +443,11 @@ void PeerListRow::paintDisabledCheckUserpic(Painter &p, int x, int y, int outerW
st::contactsPhotoCheckbox.check.check.paint(p, iconEllipse.topLeft(), outerWidth); st::contactsPhotoCheckbox.check.check.paint(p, iconEllipse.topLeft(), outerWidth);
} }
void PeerListRow::setStatusText(const QString &text) {
_status = text;
_statusWidth = st::contactsStatusFont->width(_status);
}
float64 PeerListRow::checkedRatio() { float64 PeerListRow::checkedRatio() {
return _checkbox ? _checkbox->checkedAnimationRatio() : 0.; return _checkbox ? _checkbox->checkedAnimationRatio() : 0.;
} }
@ -828,6 +834,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) {
if (!actionSize.isEmpty()) { if (!actionSize.isEmpty()) {
namew -= actionMargins.left() + actionSize.width() + actionMargins.right(); namew -= actionMargins.left() + actionSize.width() + actionMargins.right();
} }
auto statusw = namew;
if (row->needsVerifiedIcon()) { if (row->needsVerifiedIcon()) {
auto icon = &st::dialogsVerifiedIcon; auto icon = &st::dialogsVerifiedIcon;
namew -= icon->width(); namew -= icon->width();
@ -845,7 +852,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) {
p.setFont(st::contactsStatusFont); p.setFont(st::contactsStatusFont);
if (row->isSearchResult() && !_mentionHighlight.isEmpty() && peer->userName().startsWith(_mentionHighlight, Qt::CaseInsensitive)) { if (row->isSearchResult() && !_mentionHighlight.isEmpty() && peer->userName().startsWith(_mentionHighlight, Qt::CaseInsensitive)) {
auto username = peer->userName(); auto username = peer->userName();
auto availableWidth = width() - namex - st::contactsPadding.right(); auto availableWidth = statusw;
auto highlightedPart = '@' + username.mid(0, _mentionHighlight.size()); auto highlightedPart = '@' + username.mid(0, _mentionHighlight.size());
auto grayedPart = username.mid(_mentionHighlight.size()); auto grayedPart = username.mid(_mentionHighlight.size());
auto highlightedWidth = st::contactsStatusFont->width(highlightedPart); auto highlightedWidth = st::contactsStatusFont->width(highlightedPart);
@ -864,7 +871,7 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) {
p.drawTextLeft(namex + highlightedWidth, st::contactsPadding.top() + st::contactsStatusTop, width(), grayedPart); p.drawTextLeft(namex + highlightedWidth, st::contactsPadding.top() + st::contactsStatusTop, width(), grayedPart);
} }
} else { } else {
row->paintStatusText(p, namex, st::contactsPadding.top() + st::contactsStatusTop, width(), selected); row->paintStatusText(p, namex, st::contactsPadding.top() + st::contactsStatusTop, statusw, width(), selected);
} }
} }

View File

@ -134,7 +134,7 @@ public:
} }
virtual void lazyInitialize(); virtual void lazyInitialize();
virtual void paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected); virtual void paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected);
protected: protected:
bool isInitialized() const { bool isInitialized() const {
@ -145,6 +145,7 @@ private:
void createCheckbox(base::lambda<void()> updateCallback); void createCheckbox(base::lambda<void()> updateCallback);
void setCheckedInternal(bool checked, SetStyle style); void setCheckedInternal(bool checked, SetStyle style);
void paintDisabledCheckUserpic(Painter &p, int x, int y, int outerWidth) const; void paintDisabledCheckUserpic(Painter &p, int x, int y, int outerWidth) const;
void setStatusText(const QString &text);
PeerListRowId _id = 0; PeerListRowId _id = 0;
gsl::not_null<PeerData*> _peer; gsl::not_null<PeerData*> _peer;
@ -152,6 +153,7 @@ private:
std::unique_ptr<Ui::RoundImageCheckbox> _checkbox; std::unique_ptr<Ui::RoundImageCheckbox> _checkbox;
Text _name; Text _name;
QString _status; QString _status;
int _statusWidth = 0;
StatusType _statusType = StatusType::Online; StatusType _statusType = StatusType::Online;
OrderedSet<QChar> _nameFirstChars; OrderedSet<QChar> _nameFirstChars;
int _absoluteIndex = -1; int _absoluteIndex = -1;

View File

@ -77,7 +77,7 @@ public:
return _items.front()->id; return _items.front()->id;
} }
void paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) override; void paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) override;
void addActionRipple(QPoint point, base::lambda<void()> updateCallback) override; void addActionRipple(QPoint point, base::lambda<void()> updateCallback) override;
void stopLastActionRipple() override; void stopLastActionRipple() override;
@ -111,7 +111,7 @@ BoxController::Row::Row(HistoryItem *item) : PeerListRow(item->history()->peer,
refreshStatus(); refreshStatus();
} }
void BoxController::Row::paintStatusText(Painter &p, int x, int y, int outerWidth, bool selected) { void BoxController::Row::paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) {
auto icon = ([this] { auto icon = ([this] {
switch (_type) { switch (_type) {
case Type::In: return &st::callArrowIn; case Type::In: return &st::callArrowIn;
@ -121,9 +121,11 @@ void BoxController::Row::paintStatusText(Painter &p, int x, int y, int outerWidt
Unexpected("_type in Calls::BoxController::Row::paintStatusText()."); Unexpected("_type in Calls::BoxController::Row::paintStatusText().");
})(); })();
icon->paint(p, x + st::callArrowPosition.x(), y + st::callArrowPosition.y(), outerWidth); icon->paint(p, x + st::callArrowPosition.x(), y + st::callArrowPosition.y(), outerWidth);
x += + st::callArrowPosition.x() + icon->width() + st::callArrowSkip; auto shift = st::callArrowPosition.x() + icon->width() + st::callArrowSkip;
x += shift;
availableWidth -= shift;
PeerListRow::paintStatusText(p, x, y, outerWidth, selected); PeerListRow::paintStatusText(p, x, y, availableWidth, outerWidth, selected);
} }
void BoxController::Row::paintAction(Painter &p, TimeMs ms, int x, int y, int outerWidth, bool actionSelected) { void BoxController::Row::paintAction(Painter &p, TimeMs ms, int x, int y, int outerWidth, bool actionSelected) {