mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improve BottomInfo layout.
This commit is contained in:
parent
2b0cd2a611
commit
b5d80a3c15
11 changed files with 85 additions and 23 deletions
|
@ -753,6 +753,7 @@ void HistoryItem::addReaction(const QString &reaction) {
|
||||||
_reactions = std::make_unique<Data::MessageReactions>(this);
|
_reactions = std::make_unique<Data::MessageReactions>(this);
|
||||||
}
|
}
|
||||||
_reactions->add(reaction);
|
_reactions->add(reaction);
|
||||||
|
history()->owner().notifyItemDataChange(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryItem::updateReactions(const MTPMessageReactions &reactions) {
|
void HistoryItem::updateReactions(const MTPMessageReactions &reactions) {
|
||||||
|
@ -764,6 +765,7 @@ void HistoryItem::updateReactions(const MTPMessageReactions &reactions) {
|
||||||
_reactions = std::make_unique<Data::MessageReactions>(this);
|
_reactions = std::make_unique<Data::MessageReactions>(this);
|
||||||
}
|
}
|
||||||
_reactions->set(data.vresults().v, data.is_min());
|
_reactions->set(data.vresults().v, data.is_min());
|
||||||
|
history()->owner().notifyItemDataChange(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history_item_components.h"
|
#include "history/history_item_components.h"
|
||||||
#include "history/history_message.h"
|
#include "history/history_message.h"
|
||||||
#include "history/view/history_view_message.h"
|
#include "history/view/history_view_message.h"
|
||||||
|
#include "data/data_message_reactions.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
|
||||||
BottomInfo::BottomInfo(Data &&data) : _data(std::move(data)) {
|
BottomInfo::BottomInfo(Data &&data)
|
||||||
|
: _data(std::move(data))
|
||||||
|
, _reactions(st::msgMinWidth / 2) {
|
||||||
layout();
|
layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +42,17 @@ QSize BottomInfo::size() const {
|
||||||
return _size;
|
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 {
|
bool BottomInfo::pointInTime(QPoint position) const {
|
||||||
return QRect(
|
return QRect(
|
||||||
_size.width() - _dateWidth,
|
_size.width() - _dateWidth,
|
||||||
|
@ -144,7 +158,7 @@ void BottomInfo::paint(
|
||||||
} else {
|
} else {
|
||||||
const auto available = _size.width();
|
const auto available = _size.width();
|
||||||
const auto use = std::min(available, _reactions.maxWidth());
|
const auto use = std::min(available, _reactions.maxWidth());
|
||||||
_reactions.drawLeftElided(
|
_reactions.drawLeft(
|
||||||
p,
|
p,
|
||||||
position.x() + _size.width() - use,
|
position.x() + _size.width() - use,
|
||||||
position.y() + st::msgDateFont->height,
|
position.y() + st::msgDateFont->height,
|
||||||
|
@ -157,12 +171,25 @@ void BottomInfo::paint(
|
||||||
int BottomInfo::resizeToWidth(int newWidth) {
|
int BottomInfo::resizeToWidth(int newWidth) {
|
||||||
if (newWidth >= _optimalSize.width()) {
|
if (newWidth >= _optimalSize.width()) {
|
||||||
_size = _optimalSize;
|
_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() {
|
void BottomInfo::layout() {
|
||||||
|
//const auto good = ::Data::MessageReactions::SuggestList();
|
||||||
|
//for (const auto &item : good) {
|
||||||
|
// _data.reactions.emplace(item, rand_value<uint8>() + 1);
|
||||||
|
//}
|
||||||
|
|
||||||
layoutDateText();
|
layoutDateText();
|
||||||
layoutViewsText();
|
layoutViewsText();
|
||||||
layoutRepliesText();
|
layoutRepliesText();
|
||||||
|
@ -234,6 +261,9 @@ void BottomInfo::layoutReactionsText() {
|
||||||
auto fullCount = 0;
|
auto fullCount = 0;
|
||||||
auto text = QString();
|
auto text = QString();
|
||||||
for (const auto &[string, count] : sorted) {
|
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);
|
text.append(string);
|
||||||
fullCount += count;
|
fullCount += count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] QSize optimalSize() const;
|
[[nodiscard]] QSize optimalSize() const;
|
||||||
[[nodiscard]] QSize size() const;
|
[[nodiscard]] QSize size() const;
|
||||||
|
[[nodiscard]] int firstLineWidth() const;
|
||||||
[[nodiscard]] bool pointInTime(QPoint position) const;
|
[[nodiscard]] bool pointInTime(QPoint position) const;
|
||||||
[[nodiscard]] bool isSignedAuthorElided() const;
|
[[nodiscard]] bool isSignedAuthorElided() const;
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,10 @@ int Element::infoWidth() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Element::bottomInfoFirstLineWidth() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Element::isHiddenByGroup() const {
|
bool Element::isHiddenByGroup() const {
|
||||||
return _flags & Flag::HiddenByGroup;
|
return _flags & Flag::HiddenByGroup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,6 +261,7 @@ public:
|
||||||
int skipBlockHeight() const;
|
int skipBlockHeight() const;
|
||||||
QString skipBlock() const;
|
QString skipBlock() const;
|
||||||
virtual int infoWidth() const;
|
virtual int infoWidth() const;
|
||||||
|
virtual int bottomInfoFirstLineWidth() const;
|
||||||
|
|
||||||
bool isHiddenByGroup() const;
|
bool isHiddenByGroup() const;
|
||||||
virtual bool isHidden() const;
|
virtual bool isHidden() const;
|
||||||
|
|
|
@ -634,6 +634,10 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
||||||
if (entry) {
|
if (entry) {
|
||||||
trect.setHeight(trect.height() - entry->height());
|
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);
|
paintText(p, trect, context);
|
||||||
if (mediaDisplayed) {
|
if (mediaDisplayed) {
|
||||||
auto mediaHeight = media->height();
|
auto mediaHeight = media->height();
|
||||||
|
@ -660,11 +664,6 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
||||||
entry->draw(p, entryContext);
|
entry->draw(p, entryContext);
|
||||||
p.translate(-entryLeft, -entryTop);
|
p.translate(-entryLeft, -entryTop);
|
||||||
}
|
}
|
||||||
const auto needDrawInfo = entry
|
|
||||||
? !entry->customInfoLayout()
|
|
||||||
: (mediaDisplayed
|
|
||||||
? !media->customInfoLayout()
|
|
||||||
: true);
|
|
||||||
if (needDrawInfo) {
|
if (needDrawInfo) {
|
||||||
const auto bottomSelected = context.selected()
|
const auto bottomSelected = context.selected()
|
||||||
|| (!mediaSelectionIntervals.empty()
|
|| (!mediaSelectionIntervals.empty()
|
||||||
|
@ -1802,6 +1801,10 @@ int Message::infoWidth() const {
|
||||||
return _bottomInfo.optimalSize().width();
|
return _bottomInfo.optimalSize().width();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Message::bottomInfoFirstLineWidth() const {
|
||||||
|
return _bottomInfo.firstLineWidth();
|
||||||
|
}
|
||||||
|
|
||||||
bool Message::isSignedAuthorElided() const {
|
bool Message::isSignedAuthorElided() const {
|
||||||
return _bottomInfo.isSignedAuthorElided();
|
return _bottomInfo.isSignedAuthorElided();
|
||||||
}
|
}
|
||||||
|
@ -2464,8 +2467,10 @@ int Message::resizeContentGetHeight(int newWidth) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_bottomInfo.resizeToWidth(
|
const auto bottomInfoHeight = _bottomInfo.resizeToWidth(
|
||||||
std::min(_bottomInfo.optimalSize().width(), contentWidth));
|
std::min(
|
||||||
|
_bottomInfo.optimalSize().width(),
|
||||||
|
contentWidth - st::msgPadding.left() - st::msgPadding.right() - 2 * st::msgDateDelta.x()));
|
||||||
|
|
||||||
if (bubble) {
|
if (bubble) {
|
||||||
auto reply = displayedReply();
|
auto reply = displayedReply();
|
||||||
|
@ -2536,6 +2541,9 @@ int Message::resizeContentGetHeight(int newWidth) {
|
||||||
reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
|
reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
|
||||||
newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
||||||
}
|
}
|
||||||
|
if (needInfoDisplay()) {
|
||||||
|
newHeight += (bottomInfoHeight - st::msgDateFont->height);
|
||||||
|
}
|
||||||
|
|
||||||
if (item->repliesAreComments() || item->externalReply()) {
|
if (item->repliesAreComments() || item->externalReply()) {
|
||||||
newHeight += st::historyCommentsButtonHeight;
|
newHeight += st::historyCommentsButtonHeight;
|
||||||
|
@ -2556,6 +2564,20 @@ int Message::resizeContentGetHeight(int newWidth) {
|
||||||
return newHeight;
|
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 {
|
bool Message::hasVisibleText() const {
|
||||||
if (message()->emptyText()) {
|
if (message()->emptyText()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -106,14 +106,15 @@ public:
|
||||||
int left,
|
int left,
|
||||||
int top,
|
int top,
|
||||||
int outerWidth) const override;
|
int outerWidth) const override;
|
||||||
ClickHandlerPtr rightActionLink() const override;
|
[[nodiscard]] ClickHandlerPtr rightActionLink() const override;
|
||||||
bool displayEditedBadge() const override;
|
[[nodiscard]] bool displayEditedBadge() const override;
|
||||||
TimeId displayedEditDate() const override;
|
[[nodiscard]] TimeId displayedEditDate() const override;
|
||||||
HistoryMessageReply *displayedReply() const override;
|
[[nodiscard]] HistoryMessageReply *displayedReply() const override;
|
||||||
bool toggleSelectionByHandlerClick(
|
[[nodiscard]] bool toggleSelectionByHandlerClick(
|
||||||
const ClickHandlerPtr &handler) const override;
|
const ClickHandlerPtr &handler) const override;
|
||||||
int infoWidth() const override;
|
[[nodiscard]] int infoWidth() const override;
|
||||||
bool isSignedAuthorElided() const override;
|
[[nodiscard]] int bottomInfoFirstLineWidth() const override;
|
||||||
|
[[nodiscard]] bool isSignedAuthorElided() const override;
|
||||||
|
|
||||||
void itemDataChanged() override;
|
void itemDataChanged() override;
|
||||||
|
|
||||||
|
@ -202,6 +203,7 @@ private:
|
||||||
QSize performCountOptimalSize() override;
|
QSize performCountOptimalSize() override;
|
||||||
QSize performCountCurrentSize(int newWidth) override;
|
QSize performCountCurrentSize(int newWidth) override;
|
||||||
bool hasVisibleText() const override;
|
bool hasVisibleText() const override;
|
||||||
|
[[nodiscard]] bool needInfoDisplay() const;
|
||||||
|
|
||||||
[[nodiscard]] bool isPinnedContext() const;
|
[[nodiscard]] bool isPinnedContext() const;
|
||||||
|
|
||||||
|
@ -219,7 +221,7 @@ private:
|
||||||
void updateViewButtonExistence();
|
void updateViewButtonExistence();
|
||||||
[[nodiscard]] int viewButtonHeight() const;
|
[[nodiscard]] int viewButtonHeight() const;
|
||||||
|
|
||||||
WebPage *logEntryOriginal() const;
|
[[nodiscard]] WebPage *logEntryOriginal() const;
|
||||||
|
|
||||||
[[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const;
|
[[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const;
|
||||||
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
|
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
|
||||||
|
|
|
@ -217,7 +217,7 @@ QSize Gif::countCurrentSize(int newWidth) {
|
||||||
newWidth = std::clamp(
|
newWidth = std::clamp(
|
||||||
std::max(tw, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())),
|
std::max(tw, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())),
|
||||||
st::minPhotoSize,
|
st::minPhotoSize,
|
||||||
maxSize);
|
std::min(newWidth, maxSize));
|
||||||
auto newHeight = qMax(th, st::minPhotoSize);
|
auto newHeight = qMax(th, st::minPhotoSize);
|
||||||
if (!activeCurrentStreamed()) {
|
if (!activeCurrentStreamed()) {
|
||||||
accumulate_max(newWidth, gifMaxStatusWidth(_data) + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
|
accumulate_max(newWidth, gifMaxStatusWidth(_data) + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
|
||||||
|
|
|
@ -124,7 +124,7 @@ QSize Location::countCurrentSize(int newWidth) {
|
||||||
auto minWidth = std::clamp(
|
auto minWidth = std::clamp(
|
||||||
_parent->minWidthForMedia(),
|
_parent->minWidthForMedia(),
|
||||||
st::minPhotoSize,
|
st::minPhotoSize,
|
||||||
st::maxMediaSize);
|
std::min(newWidth, st::maxMediaSize));
|
||||||
accumulate_max(newWidth, minWidth);
|
accumulate_max(newWidth, minWidth);
|
||||||
accumulate_max(newHeight, st::minPhotoSize);
|
accumulate_max(newHeight, st::minPhotoSize);
|
||||||
if (_parent->hasBubble()) {
|
if (_parent->hasBubble()) {
|
||||||
|
|
|
@ -210,7 +210,7 @@ QSize Photo::countCurrentSize(int newWidth) {
|
||||||
const auto minWidth = std::clamp(
|
const auto minWidth = std::clamp(
|
||||||
_parent->minWidthForMedia(),
|
_parent->minWidthForMedia(),
|
||||||
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
|
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
|
||||||
st::maxMediaSize);
|
std::min(newWidth, st::maxMediaSize));
|
||||||
newWidth = qMax(_pixw, minWidth);
|
newWidth = qMax(_pixw, minWidth);
|
||||||
auto newHeight = qMax(_pixh, st::minPhotoSize);
|
auto newHeight = qMax(_pixh, st::minPhotoSize);
|
||||||
if (_parent->hasBubble() && !_caption.isEmpty()) {
|
if (_parent->hasBubble() && !_caption.isEmpty()) {
|
||||||
|
|
|
@ -799,7 +799,7 @@ void Poll::paintInlineFooter(
|
||||||
top,
|
top,
|
||||||
std::min(
|
std::min(
|
||||||
_totalVotesLabel.maxWidth(),
|
_totalVotesLabel.maxWidth(),
|
||||||
paintw - _parent->infoWidth()),
|
paintw - _parent->bottomInfoFirstLineWidth()),
|
||||||
width());
|
width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue