diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d9a67aab45..3d34906f9e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6388,27 +6388,43 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { } } if (drawWebPagePreview) { + const auto textTop = backy + st::msgReplyPadding.top(); auto previewLeft = st::historyReplySkip + st::webPageLeft; - p.fillRect(st::historyReplySkip, backy + st::msgReplyPadding.top(), st::webPageBar, st::msgReplyBarSize.height(), st::msgInReplyBarColor); - if ((_previewData->photo && !_previewData->photo->isNull()) || (_previewData->document && _previewData->document->hasThumbnail() && !_previewData->document->isPatternWallPaper())) { - const auto preview = _previewData->photo - ? _previewData->photo->getReplyPreview(Data::FileOrigin()) - : _previewData->document->getReplyPreview(Data::FileOrigin()); - if (preview) { - auto to = QRect(previewLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); - if (preview->width() == preview->height()) { - p.drawPixmap(to.x(), to.y(), preview->pix()); - } else { - auto from = (preview->width() > preview->height()) ? QRect((preview->width() - preview->height()) / 2, 0, preview->height(), preview->height()) : QRect(0, (preview->height() - preview->width()) / 2, preview->width(), preview->width()); - p.drawPixmap(to, preview->pix(), from); - } - } - previewLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); + p.fillRect( + st::historyReplySkip, + textTop, + st::webPageBar, + st::msgReplyBarSize.height(), + st::msgInReplyBarColor); + + const auto to = QRect( + previewLeft, + textTop, + st::msgReplyBarSize.height(), + st::msgReplyBarSize.height()); + if (HistoryView::DrawWebPageDataPreview(p, _previewData, to)) { + previewLeft += st::msgReplyBarSize.height() + + st::msgReplyBarSkip + - st::msgReplyBarSize.width() + - st::msgReplyBarPos.x(); } p.setPen(st::historyReplyNameFg); - _previewTitle.drawElided(p, previewLeft, backy + st::msgReplyPadding.top(), width() - previewLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); + const auto elidedWidth = width() + - previewLeft + - _fieldBarCancel->width() + - st::msgReplyPadding.right(); + + _previewTitle.drawElided( + p, + previewLeft, + textTop, + elidedWidth); p.setPen(st::historyComposeAreaFg); - _previewDescription.drawElided(p, previewLeft, backy + st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - previewLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); + _previewDescription.drawElided( + p, + previewLeft, + textTop + st::msgServiceNameFont->height, + elidedWidth); } } diff --git a/Telegram/SourceFiles/history/view/history_view_webpage_preview.cpp b/Telegram/SourceFiles/history/view/history_view_webpage_preview.cpp index 9111ac7b14..ba0cbacdf6 100644 --- a/Telegram/SourceFiles/history/view/history_view_webpage_preview.cpp +++ b/Telegram/SourceFiles/history/view/history_view_webpage_preview.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_webpage_preview.h" +#include "data/data_file_origin.h" #include "data/data_web_page.h" namespace HistoryView { @@ -56,4 +57,32 @@ WebPageText TitleAndDescriptionFromWebPage(not_null d) { return { resultTitle, resultDescription }; } +bool DrawWebPageDataPreview(Painter &p, not_null d, QRect to) { + const auto document = d->document; + const auto photo = d->photo; + if ((!photo || photo->isNull()) + && (!document + || !document->hasThumbnail() + || document->isPatternWallPaper())) { + return false; + } + + const auto preview = photo + ? photo->getReplyPreview(Data::FileOrigin()) + : document->getReplyPreview(Data::FileOrigin()); + const auto w = preview->width(); + const auto h = preview->height(); + if (preview) { + if (w == h) { + p.drawPixmap(to.x(), to.y(), preview->pix()); + } else { + const auto from = (w > h) + ? QRect((w - h) / 2, 0, h, h) + : QRect(0, (h - w) / 2, w, w); + p.drawPixmap(to, preview->pix(), from); + } + } + return true; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_webpage_preview.h b/Telegram/SourceFiles/history/view/history_view_webpage_preview.h index f8ec53bda6..54594c28a6 100644 --- a/Telegram/SourceFiles/history/view/history_view_webpage_preview.h +++ b/Telegram/SourceFiles/history/view/history_view_webpage_preview.h @@ -15,5 +15,6 @@ struct WebPageText { }; WebPageText TitleAndDescriptionFromWebPage(not_null d); +bool DrawWebPageDataPreview(Painter &p, not_null d, QRect to); } // namespace HistoryView