mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-23 12:15:17 +02:00
Moved drawing preview image from HistoryWidget to WebPageData.
This commit is contained in:
parent
0b655450bb
commit
58281023bc
3 changed files with 63 additions and 17 deletions
|
@ -6388,27 +6388,43 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (drawWebPagePreview) {
|
if (drawWebPagePreview) {
|
||||||
|
const auto textTop = backy + st::msgReplyPadding.top();
|
||||||
auto previewLeft = st::historyReplySkip + st::webPageLeft;
|
auto previewLeft = st::historyReplySkip + st::webPageLeft;
|
||||||
p.fillRect(st::historyReplySkip, backy + st::msgReplyPadding.top(), st::webPageBar, st::msgReplyBarSize.height(), st::msgInReplyBarColor);
|
p.fillRect(
|
||||||
if ((_previewData->photo && !_previewData->photo->isNull()) || (_previewData->document && _previewData->document->hasThumbnail() && !_previewData->document->isPatternWallPaper())) {
|
st::historyReplySkip,
|
||||||
const auto preview = _previewData->photo
|
textTop,
|
||||||
? _previewData->photo->getReplyPreview(Data::FileOrigin())
|
st::webPageBar,
|
||||||
: _previewData->document->getReplyPreview(Data::FileOrigin());
|
st::msgReplyBarSize.height(),
|
||||||
if (preview) {
|
st::msgInReplyBarColor);
|
||||||
auto to = QRect(previewLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height());
|
|
||||||
if (preview->width() == preview->height()) {
|
const auto to = QRect(
|
||||||
p.drawPixmap(to.x(), to.y(), preview->pix());
|
previewLeft,
|
||||||
} else {
|
textTop,
|
||||||
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());
|
st::msgReplyBarSize.height(),
|
||||||
p.drawPixmap(to, preview->pix(), from);
|
st::msgReplyBarSize.height());
|
||||||
}
|
if (HistoryView::DrawWebPageDataPreview(p, _previewData, to)) {
|
||||||
}
|
previewLeft += st::msgReplyBarSize.height()
|
||||||
previewLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x();
|
+ st::msgReplyBarSkip
|
||||||
|
- st::msgReplyBarSize.width()
|
||||||
|
- st::msgReplyBarPos.x();
|
||||||
}
|
}
|
||||||
p.setPen(st::historyReplyNameFg);
|
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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/history_view_webpage_preview.h"
|
#include "history/view/history_view_webpage_preview.h"
|
||||||
|
|
||||||
|
#include "data/data_file_origin.h"
|
||||||
#include "data/data_web_page.h"
|
#include "data/data_web_page.h"
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
@ -56,4 +57,32 @@ WebPageText TitleAndDescriptionFromWebPage(not_null<WebPageData*> d) {
|
||||||
return { resultTitle, resultDescription };
|
return { resultTitle, resultDescription };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DrawWebPageDataPreview(Painter &p, not_null<WebPageData*> 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
|
} // namespace HistoryView
|
||||||
|
|
|
@ -15,5 +15,6 @@ struct WebPageText {
|
||||||
};
|
};
|
||||||
|
|
||||||
WebPageText TitleAndDescriptionFromWebPage(not_null<WebPageData*> d);
|
WebPageText TitleAndDescriptionFromWebPage(not_null<WebPageData*> d);
|
||||||
|
bool DrawWebPageDataPreview(Painter &p, not_null<WebPageData*> d, QRect to);
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
Loading…
Add table
Reference in a new issue