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;
};
const auto addItemActions = [&](HistoryItem *item) {
const auto addItemActions = [&](
HistoryItem *item,
HistoryItem *albumPartItem) {
if (!item
|| !IsServerMsgId(item->id)
|| isUponSelected == 2
@ -1572,9 +1574,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
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), [=] {
_widget->editMessage(itemId);
_widget->editMessage(editItemId);
});
}
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)),
[=] { copySelectedText(); });
}
addItemActions(item);
addItemActions(item, item);
if (lnkPhoto) {
addPhotoActions(lnkPhoto->photo());
} else {
@ -1726,7 +1735,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}
}
} else { // maybe cursor on some text history item?
const auto item = [&]() -> HistoryItem* {
const auto albumPartItem = _dragStateItem;
const auto item = [&] {
const auto result = App::hoveredItem()
? App::hoveredItem()->data().get()
: 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(tr::now)),
[=] { copySelectedText(); });
addItemActions(item);
addItemActions(item, item);
} else {
addItemActions(item);
addItemActions(item, albumPartItem);
if (item && !isUponSelected) {
const auto media = (view ? view->media() : nullptr);
const auto mediaHasTextForCopy = media && media->hasTextForCopy();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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