mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-08 12:43:52 +00:00
Adjust width of file albums by captions.
This commit is contained in:
@@ -4222,8 +4222,14 @@ void Message::refreshDataIdHook() {
|
||||
}
|
||||
|
||||
int Message::monospaceMaxWidth() const {
|
||||
const auto fromText = hasVisibleText()
|
||||
? text().countMaxMonospaceWidth()
|
||||
: 0;
|
||||
const auto fromMedia = this->media()
|
||||
? this->media()->contributedMaxMonospaceWidth()
|
||||
: 0;
|
||||
return st::msgPadding.left()
|
||||
+ (hasVisibleText() ? text().countMaxMonospaceWidth() : 0)
|
||||
+ std::max(fromText, fromMedia)
|
||||
+ st::msgPadding.right();
|
||||
}
|
||||
|
||||
|
||||
@@ -1599,35 +1599,51 @@ QMargins Document::bubbleMargins() const {
|
||||
}
|
||||
|
||||
void Document::refreshCaption(bool last) {
|
||||
const auto now = Get<HistoryDocumentCaptioned>();
|
||||
auto caption = createCaption();
|
||||
if (!caption.isEmpty()) {
|
||||
if (now) {
|
||||
return;
|
||||
}
|
||||
AddComponents(HistoryDocumentCaptioned::Bit());
|
||||
auto captioned = Get<HistoryDocumentCaptioned>();
|
||||
captioned->caption = std::move(caption);
|
||||
const auto applySkipBlock = [&](Ui::Text::String &caption) {
|
||||
const auto skip = last ? _parent->skipBlockWidth() : 0;
|
||||
if (skip) {
|
||||
captioned->caption.updateSkipBlock(
|
||||
caption.updateSkipBlock(
|
||||
_parent->skipBlockWidth(),
|
||||
_parent->skipBlockHeight());
|
||||
} else {
|
||||
captioned->caption.removeSkipBlock();
|
||||
caption.removeSkipBlock();
|
||||
}
|
||||
} else if (now) {
|
||||
RemoveComponents(HistoryDocumentCaptioned::Bit());
|
||||
};
|
||||
if (const auto now = Get<HistoryDocumentCaptioned>()) {
|
||||
applySkipBlock(now->caption);
|
||||
return;
|
||||
}
|
||||
auto caption = createCaption();
|
||||
if (caption.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
AddComponents(HistoryDocumentCaptioned::Bit());
|
||||
const auto captioned = Get<HistoryDocumentCaptioned>();
|
||||
captioned->caption = std::move(caption);
|
||||
applySkipBlock(captioned->caption);
|
||||
}
|
||||
|
||||
int Document::widenGroupingMaxWidth(int current, bool last) {
|
||||
refreshCaption(last);
|
||||
const auto captioned = Get<HistoryDocumentCaptioned>();
|
||||
if (!captioned) {
|
||||
return current;
|
||||
}
|
||||
const auto &caption = captioned->caption;
|
||||
const auto padding = st::msgPadding.left() + st::msgPadding.right();
|
||||
const auto proseFull = padding + caption.maxWidth();
|
||||
const auto proseCapped = std::min(proseFull, int(st::msgMaxWidth));
|
||||
const auto monospaceRaw = caption.countMaxMonospaceWidth();
|
||||
const auto monospaceFull = monospaceRaw
|
||||
? (padding + monospaceRaw)
|
||||
: 0;
|
||||
return std::max({ current, proseCapped, monospaceFull });
|
||||
}
|
||||
|
||||
QSize Document::sizeForGroupingOptimal(int maxWidth, bool last) const {
|
||||
const auto thumbed = Get<HistoryDocumentThumbed>();
|
||||
const auto &st = (thumbed ? st::msgFileThumbLayoutGrouped : st::msgFileLayoutGrouped);
|
||||
auto height = st.padding.top() + st.thumbSize + st.padding.bottom();
|
||||
|
||||
const_cast<Document*>(this)->refreshCaption(last);
|
||||
|
||||
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
auto captionw = maxWidth
|
||||
- st::msgPadding.left()
|
||||
@@ -1763,6 +1779,13 @@ Ui::Text::String Document::createCaption() const {
|
||||
return File::createCaption(_realParent);
|
||||
}
|
||||
|
||||
int Document::contributedMaxMonospaceWidth() const {
|
||||
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
return captioned->caption.countMaxMonospaceWidth();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::setElided(bool value) {
|
||||
if (_elided != value) {
|
||||
_elided = value;
|
||||
|
||||
@@ -71,6 +71,8 @@ public:
|
||||
|
||||
QSize sizeForGroupingOptimal(int maxWidth, bool last) const override;
|
||||
QSize sizeForGrouping(int width) const override;
|
||||
int widenGroupingMaxWidth(int current, bool last) override;
|
||||
int contributedMaxMonospaceWidth() const override;
|
||||
void drawGrouped(
|
||||
Painter &p,
|
||||
const PaintContext &context,
|
||||
|
||||
@@ -346,6 +346,14 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual int contributedMaxMonospaceWidth() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int widenGroupingMaxWidth(int current, bool last) {
|
||||
return current;
|
||||
}
|
||||
|
||||
// Sometimes click on media in message is overloaded by the message:
|
||||
// (for example it can open a link or a game instead of opening media)
|
||||
// But the overloading click handler should be used only when media
|
||||
|
||||
@@ -146,6 +146,13 @@ QSize GroupedMedia::countOptimalSize() {
|
||||
media->initDimensions();
|
||||
accumulate_max(maxWidth, media->maxWidth());
|
||||
}
|
||||
auto index = 0;
|
||||
for (const auto &part : _parts) {
|
||||
const auto last = (++index == _parts.size());
|
||||
accumulate_max(
|
||||
maxWidth,
|
||||
part.content->widenGroupingMaxWidth(maxWidth, last));
|
||||
}
|
||||
}
|
||||
auto index = 0;
|
||||
for (const auto &part : _parts) {
|
||||
@@ -893,6 +900,19 @@ bool GroupedMedia::enforceBubbleWidth() const {
|
||||
return _mode == Mode::Grid;
|
||||
}
|
||||
|
||||
int GroupedMedia::contributedMaxMonospaceWidth() const {
|
||||
if (_mode != Mode::Column) {
|
||||
return 0;
|
||||
}
|
||||
auto result = 0;
|
||||
for (const auto &part : _parts) {
|
||||
accumulate_max(
|
||||
result,
|
||||
part.content->contributedMaxMonospaceWidth());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GroupedMedia::computeNeedBubble() const {
|
||||
Expects(_mode == Mode::Column || _captionItem.has_value());
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
}
|
||||
QRect groupItemRect(int index) const override;
|
||||
bool enforceBubbleWidth() const override;
|
||||
int contributedMaxMonospaceWidth() const override;
|
||||
|
||||
void stopAnimation() override;
|
||||
void checkAnimation() override;
|
||||
|
||||
Reference in New Issue
Block a user