Fix caption edit in column albums.

This commit is contained in:
John Preston 2020-10-29 18:21:16 +03:00
parent 78492386c4
commit 6d9c529a65
9 changed files with 70 additions and 73 deletions

View file

@ -1544,7 +1544,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
return item; return item;
}; };
const auto addItemActions = [&](HistoryItem *item) { const auto addItemActions = [&](
HistoryItem *item,
HistoryItem *albumPartItem) {
if (!item if (!item
|| !IsServerMsgId(item->id) || !IsServerMsgId(item->id)
|| isUponSelected == 2 || isUponSelected == 2
@ -1572,9 +1574,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
controller->showRepliesForMessage(_history, rootId); controller->showRepliesForMessage(_history, rootId);
}); });
} }
if (item->allowsEdit(base::unixtime::now())) { const auto t = base::unixtime::now();
const auto editItem = (albumPartItem && albumPartItem->allowsEdit(t))
? albumPartItem
: item->allowsEdit(t)
? item
: nullptr;
if (editItem) {
const auto editItemId = editItem->fullId();
_menu->addAction(tr::lng_context_edit_msg(tr::now), [=] { _menu->addAction(tr::lng_context_edit_msg(tr::now), [=] {
_widget->editMessage(itemId); _widget->editMessage(editItemId);
}); });
} }
const auto pinItem = (item->canPin() && item->isPinned()) const auto pinItem = (item->canPin() && item->isPinned())
@ -1663,7 +1672,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
: tr::lng_context_copy_selected(tr::now)), : tr::lng_context_copy_selected(tr::now)),
[=] { copySelectedText(); }); [=] { copySelectedText(); });
} }
addItemActions(item); addItemActions(item, item);
if (lnkPhoto) { if (lnkPhoto) {
addPhotoActions(lnkPhoto->photo()); addPhotoActions(lnkPhoto->photo());
} else { } else {
@ -1726,7 +1735,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
} }
} else { // maybe cursor on some text history item? } else { // maybe cursor on some text history item?
const auto item = [&]() -> HistoryItem* { const auto albumPartItem = _dragStateItem;
const auto item = [&] {
const auto result = App::hoveredItem() const auto result = App::hoveredItem()
? App::hoveredItem()->data().get() ? App::hoveredItem()->data().get()
: App::hoveredLinkItem() : App::hoveredLinkItem()
@ -1750,9 +1760,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
? tr::lng_context_copy_selected_items(tr::now) ? tr::lng_context_copy_selected_items(tr::now)
: tr::lng_context_copy_selected(tr::now)), : tr::lng_context_copy_selected(tr::now)),
[=] { copySelectedText(); }); [=] { copySelectedText(); });
addItemActions(item); addItemActions(item, item);
} else { } else {
addItemActions(item); addItemActions(item, albumPartItem);
if (item && !isUponSelected) { if (item && !isUponSelected) {
const auto media = (view ? view->media() : nullptr); const auto media = (view ? view->media() : nullptr);
const auto mediaHasTextForCopy = media && media->hasTextForCopy(); const auto mediaHasTextForCopy = media && media->hasTextForCopy();

View file

@ -518,11 +518,9 @@ void Document::draw(
} }
} }
if (mode != LayoutMode::GroupedLast) { if (auto captioned = Get<HistoryDocumentCaptioned>()) {
if (auto captioned = Get<HistoryDocumentCaptioned>()) { p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg)); captioned->_caption.draw(p, st::msgPadding.left(), bottom, captionw, style::al_left, 0, -1, selection);
captioned->_caption.draw(p, st::msgPadding.left(), bottom, captionw, style::al_left, 0, -1, selection);
}
} }
} }
@ -699,20 +697,18 @@ TextState Document::textState(
} }
auto painth = layout.height(); auto painth = layout.height();
if (mode != LayoutMode::GroupedLast) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { if (point.y() >= bottom) {
if (point.y() >= bottom) { result = TextState(_parent, captioned->_caption.getState(
result = TextState(_parent, captioned->_caption.getState( point - QPoint(st::msgPadding.left(), bottom),
point - QPoint(st::msgPadding.left(), bottom), width - st::msgPadding.left() - st::msgPadding.right(),
width - st::msgPadding.left() - st::msgPadding.right(), request.forText()));
request.forText())); return result;
return result; }
} auto captionw = width - st::msgPadding.left() - st::msgPadding.right();
auto captionw = width - st::msgPadding.left() - st::msgPadding.right(); painth -= captioned->_caption.countHeight(captionw);
painth -= captioned->_caption.countHeight(captionw); if (isBubbleBottom()) {
if (isBubbleBottom()) { painth -= st::msgPadding.bottom();
painth -= st::msgPadding.bottom();
}
} }
} }
if (QRect(0, 0, width, painth).contains(point) if (QRect(0, 0, width, painth).contains(point)
@ -877,35 +873,29 @@ bool Document::hideForwardedFrom() const {
return _data->isSong(); return _data->isSong();
} }
QSize Document::sizeForGroupingOptimal(int maxWidth, bool last) const { QSize Document::sizeForGroupingOptimal(int maxWidth) const {
const auto thumbed = Get<HistoryDocumentThumbed>(); const auto thumbed = Get<HistoryDocumentThumbed>();
const auto &st = (thumbed ? st::msgFileThumbLayoutGrouped : st::msgFileLayoutGrouped); const auto &st = (thumbed ? st::msgFileThumbLayoutGrouped : st::msgFileLayoutGrouped);
auto height = st.padding.top() + st.thumbSize + st.padding.bottom(); auto height = st.padding.top() + st.thumbSize + st.padding.bottom();
if (!last) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { auto captionw = maxWidth
auto captionw = maxWidth - st::msgPadding.left()
- st::msgPadding.left() - st::msgPadding.right();
- st::msgPadding.right(); height += captioned->_caption.countHeight(captionw);
height += captioned->_caption.countHeight(captionw);
}
} }
return { maxWidth, height }; return { maxWidth, height };
} }
QSize Document::sizeForGrouping(int width, bool last) const { QSize Document::sizeForGrouping(int width) const {
const auto thumbed = Get<HistoryDocumentThumbed>(); const auto thumbed = Get<HistoryDocumentThumbed>();
const auto &st = (thumbed ? st::msgFileThumbLayoutGrouped : st::msgFileLayoutGrouped); const auto &st = (thumbed ? st::msgFileThumbLayoutGrouped : st::msgFileLayoutGrouped);
auto height = st.padding.top() + st.thumbSize + st.padding.bottom(); auto height = st.padding.top() + st.thumbSize + st.padding.bottom();
if (!last) { if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
if (const auto captioned = Get<HistoryDocumentCaptioned>()) { auto captionw = width
auto captionw = width - st::msgPadding.left()
- st::msgPadding.left() - st::msgPadding.right();
- st::msgPadding.right(); height += captioned->_caption.countHeight(captionw);
height += captioned->_caption.countHeight(captionw);
}
} }
return { maxWidth(), height }; return { maxWidth(), height };
} }
@ -926,7 +916,7 @@ void Document::drawGrouped(
geometry.width(), geometry.width(),
selection, selection,
ms, ms,
last ? LayoutMode::GroupedLast : LayoutMode::Grouped); LayoutMode::Grouped);
p.translate(-geometry.topLeft()); p.translate(-geometry.topLeft());
} }
@ -941,7 +931,7 @@ TextState Document::getStateGrouped(
point, point,
geometry.size(), geometry.size(),
request, request,
last ? LayoutMode::GroupedLast : LayoutMode::Grouped); LayoutMode::Grouped);
} }
bool Document::voiceProgressAnimationCallback(crl::time now) { bool Document::voiceProgressAnimationCallback(crl::time now) {

View file

@ -62,8 +62,8 @@ public:
QMargins bubbleMargins() const override; QMargins bubbleMargins() const override;
bool hideForwardedFrom() const override; bool hideForwardedFrom() const override;
QSize sizeForGroupingOptimal(int maxWidth, bool last) const override; QSize sizeForGroupingOptimal(int maxWidth) const override;
QSize sizeForGrouping(int width, bool last) const override; QSize sizeForGrouping(int width) const override;
void drawGrouped( void drawGrouped(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,
@ -106,7 +106,6 @@ private:
enum class LayoutMode { enum class LayoutMode {
Full, Full,
Grouped, Grouped,
GroupedLast,
}; };
void draw( void draw(

View file

@ -885,11 +885,11 @@ bool Gif::fullFeaturedGrouped(RectParts sides) const {
return (sides & RectPart::Left) && (sides & RectPart::Right); return (sides & RectPart::Left) && (sides & RectPart::Right);
} }
QSize Gif::sizeForGroupingOptimal(int maxWidth, bool last) const { QSize Gif::sizeForGroupingOptimal(int maxWidth) const {
return sizeForAspectRatio(); return sizeForAspectRatio();
} }
QSize Gif::sizeForGrouping(int width, bool last) const { QSize Gif::sizeForGrouping(int width) const {
return sizeForAspectRatio(); return sizeForAspectRatio();
} }

View file

@ -69,8 +69,8 @@ public:
} }
bool fullFeaturedGrouped(RectParts sides) const; bool fullFeaturedGrouped(RectParts sides) const;
QSize sizeForGroupingOptimal(int maxWidth, bool last) const override; QSize sizeForGroupingOptimal(int maxWidth) const override;
QSize sizeForGrouping(int width, bool last) const override; QSize sizeForGrouping(int width) const override;
void drawGrouped( void drawGrouped(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,

View file

@ -163,12 +163,10 @@ public:
virtual void checkAnimation() { virtual void checkAnimation() {
} }
[[nodiscard]] virtual QSize sizeForGroupingOptimal( [[nodiscard]] virtual QSize sizeForGroupingOptimal(int maxWidth) const {
int maxWidth,
bool last) const {
Unexpected("Grouping method call."); Unexpected("Grouping method call.");
} }
[[nodiscard]] virtual QSize sizeForGrouping(int width, bool last) const { [[nodiscard]] virtual QSize sizeForGrouping(int width) const {
Unexpected("Grouping method call."); Unexpected("Grouping method call.");
} }
virtual void drawGrouped( virtual void drawGrouped(

View file

@ -117,10 +117,8 @@ QSize GroupedMedia::countOptimalSize() {
accumulate_max(maxWidth, media->maxWidth()); accumulate_max(maxWidth, media->maxWidth());
} }
} }
auto index = 0;
for (const auto &part : _parts) { for (const auto &part : _parts) {
const auto last = (++index == partsCount); sizes.push_back(part.content->sizeForGroupingOptimal(maxWidth));
sizes.push_back(part.content->sizeForGroupingOptimal(maxWidth, last));
} }
const auto layout = (_mode == Mode::Grid) const auto layout = (_mode == Mode::Grid)
@ -161,11 +159,9 @@ QSize GroupedMedia::countCurrentSize(int newWidth) {
if (_mode == Mode::Grid && newWidth < st::historyGroupWidthMin) { if (_mode == Mode::Grid && newWidth < st::historyGroupWidthMin) {
return { newWidth, newHeight }; return { newWidth, newHeight };
} else if (_mode == Mode::Column) { } else if (_mode == Mode::Column) {
auto index = 0;
auto top = 0; auto top = 0;
for (auto &part : _parts) { for (auto &part : _parts) {
const auto last = (++index == _parts.size()); const auto size = part.content->sizeForGrouping(newWidth);
const auto size = part.content->sizeForGrouping(newWidth, last);
part.geometry = QRect(0, top, newWidth, size.height()); part.geometry = QRect(0, top, newWidth, size.height());
top += size.height(); top += size.height();
} }
@ -242,11 +238,14 @@ QMargins GroupedMedia::groupedPadding() const {
const auto normal = st::msgFileLayout.padding; const auto normal = st::msgFileLayout.padding;
const auto grouped = st::msgFileLayoutGrouped.padding; const auto grouped = st::msgFileLayoutGrouped.padding;
const auto topMinus = isBubbleTop() ? 0 : st::msgFileTopMinus; const auto topMinus = isBubbleTop() ? 0 : st::msgFileTopMinus;
const auto lastHasCaption = isBubbleBottom()
&& !_parts.back().item->emptyText();
const auto addToBottom = lastHasCaption ? st::msgPadding.bottom() : 0;
return QMargins( return QMargins(
0, 0,
(normal.top() - grouped.top()) - topMinus, (normal.top() - grouped.top()) - topMinus,
0, 0,
(normal.bottom() - grouped.bottom())); (normal.bottom() - grouped.bottom()) + addToBottom);
} }
void GroupedMedia::draw( void GroupedMedia::draw(
@ -518,8 +517,10 @@ DocumentData *GroupedMedia::getDocument() const {
} }
HistoryMessageEdited *GroupedMedia::displayedEditBadge() const { HistoryMessageEdited *GroupedMedia::displayedEditBadge() const {
if (!_caption.isEmpty()) { for (const auto &part : _parts) {
return _parts.front().item->Get<HistoryMessageEdited>(); if (const auto edited = part.item->Get<HistoryMessageEdited>()) {
return edited;
}
} }
return nullptr; return nullptr;
} }
@ -527,8 +528,7 @@ HistoryMessageEdited *GroupedMedia::displayedEditBadge() const {
void GroupedMedia::updateNeedBubbleState() { void GroupedMedia::updateNeedBubbleState() {
const auto captionItem = [&]() -> HistoryItem* { const auto captionItem = [&]() -> HistoryItem* {
if (_mode == Mode::Column) { if (_mode == Mode::Column) {
const auto last = _parts.back().item.get(); return nullptr;
return last->emptyText() ? nullptr : last;
} }
auto result = (HistoryItem*)nullptr; auto result = (HistoryItem*)nullptr;
for (const auto &part : _parts) { for (const auto &part : _parts) {

View file

@ -467,14 +467,14 @@ TextState Photo::textState(QPoint point, StateRequest request) const {
return result; return result;
} }
QSize Photo::sizeForGroupingOptimal(int maxWidth, bool last) const { QSize Photo::sizeForGroupingOptimal(int maxWidth) const {
const auto width = _data->width(); const auto width = _data->width();
const auto height = _data->height(); const auto height = _data->height();
return { std::max(width, 1), std::max(height, 1) }; return { std::max(width, 1), std::max(height, 1) };
} }
QSize Photo::sizeForGrouping(int width, bool last) const { QSize Photo::sizeForGrouping(int width) const {
return sizeForGroupingOptimal(width, last); return sizeForGroupingOptimal(width);
} }
void Photo::drawGrouped( void Photo::drawGrouped(

View file

@ -58,8 +58,8 @@ public:
return _data; return _data;
} }
QSize sizeForGroupingOptimal(int maxWidth, bool last) const override; QSize sizeForGroupingOptimal(int maxWidth) const override;
QSize sizeForGrouping(int width, bool last) const override; QSize sizeForGrouping(int width) const override;
void drawGrouped( void drawGrouped(
Painter &p, Painter &p,
const QRect &clip, const QRect &clip,