mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 21:27:07 +02:00
Use HistoryView::Object in BottomInfo.
This commit is contained in:
parent
57cb921bb9
commit
3aacd15ef2
4 changed files with 55 additions and 59 deletions
|
@ -33,25 +33,17 @@ void BottomInfo::update(Data &&data, Context &&context, int availableWidth) {
|
|||
_data = std::move(data);
|
||||
_context = std::move(context);
|
||||
layout();
|
||||
if (!_size.isEmpty()) {
|
||||
resizeToWidth(std::min(optimalSize().width(), availableWidth));
|
||||
if (width() > 0) {
|
||||
resizeGetHeight(std::min(maxWidth(), availableWidth));
|
||||
}
|
||||
}
|
||||
|
||||
QSize BottomInfo::optimalSize() const {
|
||||
return _optimalSize;
|
||||
}
|
||||
|
||||
QSize BottomInfo::size() const {
|
||||
return _size;
|
||||
}
|
||||
|
||||
int BottomInfo::firstLineWidth() const {
|
||||
if (_size.height() == _optimalSize.height()) {
|
||||
return _size.width();
|
||||
if (height() == minHeight()) {
|
||||
return width();
|
||||
}
|
||||
const auto reactionsWidth = _reactions.maxWidth();
|
||||
const auto noReactionsWidth = _optimalSize.width()
|
||||
const auto noReactionsWidth = maxWidth()
|
||||
- st::historyReactionsSkip
|
||||
- reactionsWidth;
|
||||
return noReactionsWidth;
|
||||
|
@ -63,24 +55,24 @@ TextState BottomInfo::textState(
|
|||
auto result = TextState(item);
|
||||
if (!_reactions.isEmpty()) {
|
||||
const auto reactionsPosition = [&] {
|
||||
if (_size.height() == _optimalSize.height()) {
|
||||
if (height() == minHeight()) {
|
||||
return QPoint(0, 0);
|
||||
}
|
||||
const auto available = _size.width();
|
||||
const auto available = width();
|
||||
const auto use = std::min(available, _reactions.maxWidth());
|
||||
return QPoint(_size.width() - use, st::msgDateFont->height);
|
||||
return QPoint(width() - use, st::msgDateFont->height);
|
||||
}();
|
||||
const auto state = _reactions.getStateLeft(
|
||||
position - reactionsPosition,
|
||||
std::min(_size.width(), _reactions.maxWidth()),
|
||||
_size.width());
|
||||
std::min(width(), _reactions.maxWidth()),
|
||||
width());
|
||||
if (state.uponSymbol) {
|
||||
result.link = _context.reactions;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
const auto inTime = QRect(
|
||||
_size.width() - _dateWidth,
|
||||
width() - _dateWidth,
|
||||
0,
|
||||
_dateWidth,
|
||||
st::msgDateFont->height
|
||||
|
@ -106,7 +98,7 @@ void BottomInfo::paint(
|
|||
const auto sti = context.imageStyle();
|
||||
const auto stm = context.messageStyle();
|
||||
|
||||
auto right = position.x() + _size.width();
|
||||
auto right = position.x() + width();
|
||||
const auto firstLineBottom = position.y() + st::msgDateFont->height;
|
||||
if (_data.flags & Data::Flag::OutLayout) {
|
||||
const auto &icon = (_data.flags & Data::Flag::Sending)
|
||||
|
@ -177,7 +169,7 @@ void BottomInfo::paint(
|
|||
outerWidth);
|
||||
}
|
||||
if (!_reactions.isEmpty()) {
|
||||
if (_size.height() == _optimalSize.height()) {
|
||||
if (height() == minHeight()) {
|
||||
_reactions.drawLeft(
|
||||
p,
|
||||
position.x(),
|
||||
|
@ -185,11 +177,11 @@ void BottomInfo::paint(
|
|||
_reactions.maxWidth(),
|
||||
outerWidth);
|
||||
} else {
|
||||
const auto available = _size.width();
|
||||
const auto available = width();
|
||||
const auto use = std::min(available, _reactions.maxWidth());
|
||||
_reactions.drawLeft(
|
||||
p,
|
||||
position.x() + _size.width() - use,
|
||||
position.x() + width() - use,
|
||||
position.y() + st::msgDateFont->height,
|
||||
use,
|
||||
outerWidth);
|
||||
|
@ -197,20 +189,18 @@ void BottomInfo::paint(
|
|||
}
|
||||
}
|
||||
|
||||
int BottomInfo::resizeToWidth(int newWidth) {
|
||||
if (newWidth >= _optimalSize.width()) {
|
||||
_size = _optimalSize;
|
||||
} 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));
|
||||
QSize BottomInfo::countCurrentSize(int newWidth) {
|
||||
if (newWidth >= maxWidth()) {
|
||||
return optimalSize();
|
||||
}
|
||||
return _size.height();
|
||||
const auto reactionsWidth = _reactions.maxWidth();
|
||||
const auto noReactionsWidth = maxWidth()
|
||||
- st::historyReactionsSkip
|
||||
- reactionsWidth;
|
||||
accumulate_min(newWidth, std::max(noReactionsWidth, reactionsWidth));
|
||||
return QSize(
|
||||
newWidth,
|
||||
st::msgDateFont->height + _reactions.countHeight(newWidth));
|
||||
}
|
||||
|
||||
void BottomInfo::layout() {
|
||||
|
@ -218,7 +208,7 @@ void BottomInfo::layout() {
|
|||
layoutViewsText();
|
||||
layoutRepliesText();
|
||||
layoutReactionsText();
|
||||
countOptimalSize();
|
||||
initDimensions();
|
||||
}
|
||||
|
||||
void BottomInfo::layoutDateText() {
|
||||
|
@ -304,7 +294,7 @@ void BottomInfo::layoutReactionsText() {
|
|||
Ui::NameTextOptions());
|
||||
}
|
||||
|
||||
void BottomInfo::countOptimalSize() {
|
||||
QSize BottomInfo::countOptimalSize() {
|
||||
auto width = 0;
|
||||
if (_data.flags & (Data::Flag::OutLayout | Data::Flag::Sending)) {
|
||||
width += st::historySendStateSpace;
|
||||
|
@ -323,7 +313,7 @@ void BottomInfo::countOptimalSize() {
|
|||
if (!_reactions.isEmpty()) {
|
||||
width += st::historyReactionsSkip + _reactions.maxWidth();
|
||||
}
|
||||
_optimalSize = QSize(width, st::msgDateFont->height);
|
||||
return QSize(width, st::msgDateFont->height);
|
||||
}
|
||||
|
||||
BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "history/view/history_view_object.h"
|
||||
#include "ui/text/text.h"
|
||||
#include "base/flags.h"
|
||||
|
||||
|
@ -21,7 +22,7 @@ using PaintContext = Ui::ChatPaintContext;
|
|||
class Message;
|
||||
struct TextState;
|
||||
|
||||
class BottomInfo {
|
||||
class BottomInfo final : public Object {
|
||||
public:
|
||||
struct Data {
|
||||
enum class Flag {
|
||||
|
@ -50,8 +51,6 @@ public:
|
|||
|
||||
void update(Data &&data, Context &&context, int availableWidth);
|
||||
|
||||
[[nodiscard]] QSize optimalSize() const;
|
||||
[[nodiscard]] QSize size() const;
|
||||
[[nodiscard]] int firstLineWidth() const;
|
||||
[[nodiscard]] TextState textState(
|
||||
not_null<const HistoryItem*> item,
|
||||
|
@ -66,20 +65,18 @@ public:
|
|||
bool inverted,
|
||||
const PaintContext &context) const;
|
||||
|
||||
int resizeToWidth(int newWidth);
|
||||
|
||||
private:
|
||||
void layout();
|
||||
void layoutDateText();
|
||||
void layoutViewsText();
|
||||
void layoutRepliesText();
|
||||
void layoutReactionsText();
|
||||
void countOptimalSize();
|
||||
|
||||
QSize countOptimalSize() override;
|
||||
QSize countCurrentSize(int newWidth) override;
|
||||
|
||||
Data _data;
|
||||
Context _context;
|
||||
QSize _optimalSize;
|
||||
QSize _size;
|
||||
Ui::Text::String _authorEditedDate;
|
||||
Ui::Text::String _views;
|
||||
Ui::Text::String _replies;
|
||||
|
|
|
@ -610,7 +610,7 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
|||
auto trect = inner.marginsRemoved(st::msgPadding);
|
||||
if (_viewButton) {
|
||||
const auto belowInfo = _viewButton->belowMessageInfo();
|
||||
const auto infoHeight = _bottomInfo.size().height();
|
||||
const auto infoHeight = _bottomInfo.height();
|
||||
const auto heightMargins = QMargins(0, 0, 0, infoHeight);
|
||||
_viewButton->draw(
|
||||
p,
|
||||
|
@ -642,7 +642,8 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
|||
trect.setHeight(trect.height() - entry->height());
|
||||
}
|
||||
if (needDrawInfo) {
|
||||
trect.setHeight(trect.height() - (_bottomInfo.size().height() - st::msgDateFont->height));
|
||||
trect.setHeight(trect.height()
|
||||
- (_bottomInfo.height() - st::msgDateFont->height));
|
||||
}
|
||||
paintText(p, trect, context);
|
||||
if (mediaDisplayed) {
|
||||
|
@ -1219,7 +1220,7 @@ TextState Message::textState(
|
|||
}
|
||||
if (_viewButton) {
|
||||
const auto belowInfo = _viewButton->belowMessageInfo();
|
||||
const auto infoHeight = _bottomInfo.size().height();
|
||||
const auto infoHeight = _bottomInfo.height();
|
||||
const auto heightMargins = QMargins(0, 0, 0, infoHeight);
|
||||
if (_viewButton->getState(
|
||||
point,
|
||||
|
@ -1765,7 +1766,7 @@ void Message::drawInfo(
|
|||
break;
|
||||
}
|
||||
|
||||
const auto size = _bottomInfo.size();
|
||||
const auto size = _bottomInfo.currentSize();
|
||||
const auto dateX = infoRight - size.width();
|
||||
const auto dateY = infoBottom - size.height();
|
||||
if (type == InfoDisplayType::Image) {
|
||||
|
@ -1807,7 +1808,7 @@ TextState Message::bottomInfoTextState(
|
|||
infoBottom -= st::msgDateImgPadding.y();
|
||||
break;
|
||||
}
|
||||
const auto size = _bottomInfo.size();
|
||||
const auto size = _bottomInfo.currentSize();
|
||||
const auto infoLeft = infoRight - size.width();
|
||||
const auto infoTop = infoBottom - size.height();
|
||||
return _bottomInfo.textState(
|
||||
|
@ -1828,12 +1829,13 @@ bool Message::isSignedAuthorElided() const {
|
|||
}
|
||||
|
||||
void Message::itemDataChanged() {
|
||||
const auto was = _bottomInfo.size();
|
||||
const auto wasInfo = _bottomInfo.currentSize();
|
||||
_bottomInfo.update(
|
||||
BottomInfoDataFromMessage(this),
|
||||
BottomInfoContextFromMessage(this),
|
||||
width());
|
||||
if (was != _bottomInfo.size()) {
|
||||
const auto nowInfo = _bottomInfo.currentSize();
|
||||
if (wasInfo != nowInfo) {
|
||||
history()->owner().requestViewResize(this);
|
||||
} else {
|
||||
history()->owner().requestViewRepaint(this);
|
||||
|
@ -2488,7 +2490,7 @@ int Message::resizeContentGetHeight(int newWidth) {
|
|||
}
|
||||
}
|
||||
}
|
||||
const auto bottomInfoHeight = _bottomInfo.resizeToWidth(
|
||||
const auto bottomInfoHeight = _bottomInfo.resizeGetHeight(
|
||||
std::min(
|
||||
_bottomInfo.optimalSize().width(),
|
||||
contentWidth - st::msgPadding.left() - st::msgPadding.right() - 2 * st::msgDateDelta.x()));
|
||||
|
|
|
@ -23,16 +23,23 @@ public:
|
|||
return _height;
|
||||
}
|
||||
|
||||
int maxWidth() const {
|
||||
[[nodiscard]] QSize optimalSize() const {
|
||||
return { _maxWidth, _minHeight };
|
||||
}
|
||||
[[nodiscard]] QSize currentSize() const {
|
||||
return { _width, _height };
|
||||
}
|
||||
|
||||
[[nodiscard]] int maxWidth() const {
|
||||
return _maxWidth;
|
||||
}
|
||||
int minHeight() const {
|
||||
[[nodiscard]] int minHeight() const {
|
||||
return _minHeight;
|
||||
}
|
||||
int width() const {
|
||||
[[nodiscard]] int width() const {
|
||||
return _width;
|
||||
}
|
||||
int height() const {
|
||||
[[nodiscard]] int height() const {
|
||||
return _height;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue