Improve BottomInfo layout.

This commit is contained in:
John Preston 2019-09-12 15:14:12 +03:00
parent 2b0cd2a611
commit b5d80a3c15
11 changed files with 85 additions and 23 deletions

View file

@ -753,6 +753,7 @@ void HistoryItem::addReaction(const QString &reaction) {
_reactions = std::make_unique<Data::MessageReactions>(this);
}
_reactions->add(reaction);
history()->owner().notifyItemDataChange(this);
}
void HistoryItem::updateReactions(const MTPMessageReactions &reactions) {
@ -764,6 +765,7 @@ void HistoryItem::updateReactions(const MTPMessageReactions &reactions) {
_reactions = std::make_unique<Data::MessageReactions>(this);
}
_reactions->set(data.vresults().v, data.is_min());
history()->owner().notifyItemDataChange(this);
});
}

View file

@ -14,12 +14,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/view/history_view_message.h"
#include "data/data_message_reactions.h"
#include "styles/style_chat.h"
#include "styles/style_dialogs.h"
namespace HistoryView {
BottomInfo::BottomInfo(Data &&data) : _data(std::move(data)) {
BottomInfo::BottomInfo(Data &&data)
: _data(std::move(data))
, _reactions(st::msgMinWidth / 2) {
layout();
}
@ -39,6 +42,17 @@ QSize BottomInfo::size() const {
return _size;
}
int BottomInfo::firstLineWidth() const {
if (_size.height() == _optimalSize.height()) {
return _size.width();
}
const auto reactionsWidth = _reactions.maxWidth();
const auto noReactionsWidth = _optimalSize.width()
- st::historyReactionsSkip
- reactionsWidth;
return noReactionsWidth;
}
bool BottomInfo::pointInTime(QPoint position) const {
return QRect(
_size.width() - _dateWidth,
@ -144,7 +158,7 @@ void BottomInfo::paint(
} else {
const auto available = _size.width();
const auto use = std::min(available, _reactions.maxWidth());
_reactions.drawLeftElided(
_reactions.drawLeft(
p,
position.x() + _size.width() - use,
position.y() + st::msgDateFont->height,
@ -157,12 +171,25 @@ void BottomInfo::paint(
int BottomInfo::resizeToWidth(int newWidth) {
if (newWidth >= _optimalSize.width()) {
_size = _optimalSize;
return _size.height();
} else {
const auto reactionsWidth = _reactions.maxWidth();
const auto noReactionsWidth = _optimalSize.width()
- st::historyReactionsSkip
- reactionsWidth;
accumulate_min(newWidth, std::max(noReactionsWidth, reactionsWidth));
_size = QSize(
newWidth,
st::msgDateFont->height + _reactions.countHeight(newWidth));
}
return 2 * st::msgDateFont->height;
return _size.height();
}
void BottomInfo::layout() {
//const auto good = ::Data::MessageReactions::SuggestList();
//for (const auto &item : good) {
// _data.reactions.emplace(item, rand_value<uint8>() + 1);
//}
layoutDateText();
layoutViewsText();
layoutRepliesText();
@ -234,6 +261,9 @@ void BottomInfo::layoutReactionsText() {
auto fullCount = 0;
auto text = QString();
for (const auto &[string, count] : sorted) {
//for (auto i = 0, n = rand_value<uint8>() % 8 + 1; i != n; ++i) {
// text.append(string);
//}
text.append(string);
fullCount += count;
}

View file

@ -46,6 +46,7 @@ public:
[[nodiscard]] QSize optimalSize() const;
[[nodiscard]] QSize size() const;
[[nodiscard]] int firstLineWidth() const;
[[nodiscard]] bool pointInTime(QPoint position) const;
[[nodiscard]] bool isSignedAuthorElided() const;

View file

@ -466,6 +466,10 @@ int Element::infoWidth() const {
return 0;
}
int Element::bottomInfoFirstLineWidth() const {
return 0;
}
bool Element::isHiddenByGroup() const {
return _flags & Flag::HiddenByGroup;
}

View file

@ -261,6 +261,7 @@ public:
int skipBlockHeight() const;
QString skipBlock() const;
virtual int infoWidth() const;
virtual int bottomInfoFirstLineWidth() const;
bool isHiddenByGroup() const;
virtual bool isHidden() const;

View file

@ -634,6 +634,10 @@ void Message::draw(Painter &p, const PaintContext &context) const {
if (entry) {
trect.setHeight(trect.height() - entry->height());
}
const auto needDrawInfo = needInfoDisplay();
if (needDrawInfo) {
trect.setHeight(trect.height() - (_bottomInfo.size().height() - st::msgDateFont->height));
}
paintText(p, trect, context);
if (mediaDisplayed) {
auto mediaHeight = media->height();
@ -660,11 +664,6 @@ void Message::draw(Painter &p, const PaintContext &context) const {
entry->draw(p, entryContext);
p.translate(-entryLeft, -entryTop);
}
const auto needDrawInfo = entry
? !entry->customInfoLayout()
: (mediaDisplayed
? !media->customInfoLayout()
: true);
if (needDrawInfo) {
const auto bottomSelected = context.selected()
|| (!mediaSelectionIntervals.empty()
@ -1802,6 +1801,10 @@ int Message::infoWidth() const {
return _bottomInfo.optimalSize().width();
}
int Message::bottomInfoFirstLineWidth() const {
return _bottomInfo.firstLineWidth();
}
bool Message::isSignedAuthorElided() const {
return _bottomInfo.isSignedAuthorElided();
}
@ -2464,8 +2467,10 @@ int Message::resizeContentGetHeight(int newWidth) {
}
}
}
_bottomInfo.resizeToWidth(
std::min(_bottomInfo.optimalSize().width(), contentWidth));
const auto bottomInfoHeight = _bottomInfo.resizeToWidth(
std::min(
_bottomInfo.optimalSize().width(),
contentWidth - st::msgPadding.left() - st::msgPadding.right() - 2 * st::msgDateDelta.x()));
if (bubble) {
auto reply = displayedReply();
@ -2536,6 +2541,9 @@ int Message::resizeContentGetHeight(int newWidth) {
reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
}
if (needInfoDisplay()) {
newHeight += (bottomInfoHeight - st::msgDateFont->height);
}
if (item->repliesAreComments() || item->externalReply()) {
newHeight += st::historyCommentsButtonHeight;
@ -2556,6 +2564,20 @@ int Message::resizeContentGetHeight(int newWidth) {
return newHeight;
}
bool Message::needInfoDisplay() const {
const auto media = this->media();
const auto mediaDisplayed = media ? media->isDisplayed() : false;
const auto entry = logEntryOriginal();
// Entry page is always a bubble bottom.
const auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
return entry
? !entry->customInfoLayout()
: (mediaDisplayed
? !media->customInfoLayout()
: true);
}
bool Message::hasVisibleText() const {
if (message()->emptyText()) {
return false;

View file

@ -106,14 +106,15 @@ public:
int left,
int top,
int outerWidth) const override;
ClickHandlerPtr rightActionLink() const override;
bool displayEditedBadge() const override;
TimeId displayedEditDate() const override;
HistoryMessageReply *displayedReply() const override;
bool toggleSelectionByHandlerClick(
[[nodiscard]] ClickHandlerPtr rightActionLink() const override;
[[nodiscard]] bool displayEditedBadge() const override;
[[nodiscard]] TimeId displayedEditDate() const override;
[[nodiscard]] HistoryMessageReply *displayedReply() const override;
[[nodiscard]] bool toggleSelectionByHandlerClick(
const ClickHandlerPtr &handler) const override;
int infoWidth() const override;
bool isSignedAuthorElided() const override;
[[nodiscard]] int infoWidth() const override;
[[nodiscard]] int bottomInfoFirstLineWidth() const override;
[[nodiscard]] bool isSignedAuthorElided() const override;
void itemDataChanged() override;
@ -202,6 +203,7 @@ private:
QSize performCountOptimalSize() override;
QSize performCountCurrentSize(int newWidth) override;
bool hasVisibleText() const override;
[[nodiscard]] bool needInfoDisplay() const;
[[nodiscard]] bool isPinnedContext() const;
@ -219,7 +221,7 @@ private:
void updateViewButtonExistence();
[[nodiscard]] int viewButtonHeight() const;
WebPage *logEntryOriginal() const;
[[nodiscard]] WebPage *logEntryOriginal() const;
[[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const;
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;

View file

@ -217,7 +217,7 @@ QSize Gif::countCurrentSize(int newWidth) {
newWidth = std::clamp(
std::max(tw, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())),
st::minPhotoSize,
maxSize);
std::min(newWidth, maxSize));
auto newHeight = qMax(th, st::minPhotoSize);
if (!activeCurrentStreamed()) {
accumulate_max(newWidth, gifMaxStatusWidth(_data) + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));

View file

@ -124,7 +124,7 @@ QSize Location::countCurrentSize(int newWidth) {
auto minWidth = std::clamp(
_parent->minWidthForMedia(),
st::minPhotoSize,
st::maxMediaSize);
std::min(newWidth, st::maxMediaSize));
accumulate_max(newWidth, minWidth);
accumulate_max(newHeight, st::minPhotoSize);
if (_parent->hasBubble()) {

View file

@ -210,7 +210,7 @@ QSize Photo::countCurrentSize(int newWidth) {
const auto minWidth = std::clamp(
_parent->minWidthForMedia(),
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
st::maxMediaSize);
std::min(newWidth, st::maxMediaSize));
newWidth = qMax(_pixw, minWidth);
auto newHeight = qMax(_pixh, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {

View file

@ -799,7 +799,7 @@ void Poll::paintInlineFooter(
top,
std::min(
_totalVotesLabel.maxWidth(),
paintw - _parent->infoWidth()),
paintw - _parent->bottomInfoFirstLineWidth()),
width());
}