Show enlarge photo button in webpage preview.

This commit is contained in:
John Preston 2023-11-09 22:25:08 +04:00
parent e4d920b148
commit 9b2f2b104f
12 changed files with 74 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -391,3 +391,7 @@ bool WebPageData::computeDefaultSmallMedia() const {
} }
return false; return false;
} }
bool WebPageData::suggestEnlargePhoto() const {
return !siteName.isEmpty() || !title.isEmpty() || !description.empty();
}

View file

@ -90,6 +90,7 @@ struct WebPageData {
[[nodiscard]] QString displayedSiteName() const; [[nodiscard]] QString displayedSiteName() const;
[[nodiscard]] bool computeDefaultSmallMedia() const; [[nodiscard]] bool computeDefaultSmallMedia() const;
[[nodiscard]] bool suggestEnlargePhoto() const;
const WebPageId id = 0; const WebPageId id = 0;
WebPageType type = WebPageType::None; WebPageType type = WebPageType::None;

View file

@ -22,6 +22,7 @@ enum class CursorState : char {
None, None,
Text, Text,
Date, Date,
Enlarge,
Forwarded, Forwarded,
}; };

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_click_handler.h" #include "data/data_file_click_handler.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_auto_download.h" #include "data/data_auto_download.h"
#include "data/data_web_page.h"
#include "core/application.h" #include "core/application.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
@ -242,6 +243,7 @@ QSize Photo::countCurrentSize(int newWidth) {
maxWidth()); maxWidth());
newWidth = qMax(pix.width(), minWidth); newWidth = qMax(pix.width(), minWidth);
auto newHeight = qMax(pix.height(), st::minPhotoSize); auto newHeight = qMax(pix.height(), st::minPhotoSize);
auto imageHeight = newHeight;
if (_parent->hasBubble() && !_caption.isEmpty()) { if (_parent->hasBubble() && !_caption.isEmpty()) {
auto captionMaxWidth = st::msgPadding.left() auto captionMaxWidth = st::msgPadding.left()
+ _caption.maxWidth() + _caption.maxWidth()
@ -252,7 +254,7 @@ QSize Photo::countCurrentSize(int newWidth) {
} }
const auto maxWithCaption = qMin(st::msgMaxWidth, captionMaxWidth); const auto maxWithCaption = qMin(st::msgMaxWidth, captionMaxWidth);
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth); newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
newHeight = adjustHeightForLessCrop( imageHeight = newHeight = adjustHeightForLessCrop(
dimensions, dimensions,
{ newWidth, newHeight }); { newWidth, newHeight });
const auto captionw = newWidth const auto captionw = newWidth
@ -266,6 +268,15 @@ QSize Photo::countCurrentSize(int newWidth) {
newHeight += st::msgPadding.bottom(); newHeight += st::msgPadding.bottom();
} }
} }
const auto enlargeInner = st::historyPageEnlargeSize;
const auto enlargeOuter = 2 * st::historyPageEnlargeSkip + enlargeInner;
const auto showEnlarge = (_parent->media() != this)
&& _parent->data()->media()
&& _parent->data()->media()->webpage()
&& _parent->data()->media()->webpage()->suggestEnlargePhoto()
&& (newWidth >= enlargeOuter)
&& (imageHeight >= enlargeOuter);
_showEnlarge = showEnlarge ? 1 : 0;
return { newWidth, newHeight }; return { newWidth, newHeight };
} }
@ -351,15 +362,16 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
fillImageOverlay(p, rthumb, rounding, context); fillImageOverlay(p, rthumb, rounding, context);
} }
} }
if (radial || (!loaded && !_data->loading())) {
const auto radialOpacity = (radial && loaded && !_data->uploading()) const auto showEnlarge = loaded && _showEnlarge;
? _animation->radial.opacity() : const auto paintInCenter = (radial || (!loaded && !_data->loading()));
1.; if (paintInCenter || showEnlarge) {
const auto innerSize = st::msgFileLayout.thumbSize;
QRect inner(rthumb.x() + (rthumb.width() - innerSize) / 2, rthumb.y() + (rthumb.height() - innerSize) / 2, innerSize, innerSize);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
if (context.selected()) { if (context.selected()) {
p.setBrush(st->msgDateImgBgSelected()); p.setBrush(st->msgDateImgBgSelected());
} else if (showEnlarge) {
const auto over = ClickHandler::showAsActive(_openl);
p.setBrush(over ? st->msgDateImgBgOver() : st->msgDateImgBg());
} else if (isThumbAnimation()) { } else if (isThumbAnimation()) {
const auto over = _animation->a_thumbOver.value(1.); const auto over = _animation->a_thumbOver.value(1.);
p.setBrush(anim::brush(st->msgDateImgBg(), st->msgDateImgBgOver(), over)); p.setBrush(anim::brush(st->msgDateImgBg(), st->msgDateImgBgOver(), over));
@ -367,6 +379,13 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
const auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); const auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel);
p.setBrush(over ? st->msgDateImgBgOver() : st->msgDateImgBg()); p.setBrush(over ? st->msgDateImgBgOver() : st->msgDateImgBg());
} }
}
if (paintInCenter) {
const auto radialOpacity = (radial && loaded && !_data->uploading())
? _animation->radial.opacity() :
1.;
const auto innerSize = st::msgFileLayout.thumbSize;
QRect inner(rthumb.x() + (rthumb.width() - innerSize) / 2, rthumb.y() + (rthumb.height() - innerSize) / 2, innerSize, innerSize);
p.setOpacity(radialOpacity * p.opacity()); p.setOpacity(radialOpacity * p.opacity());
@ -386,6 +405,13 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
_animation->radial.draw(p, rinner, st::msgFileRadialLine, sti->historyFileThumbRadialFg); _animation->radial.draw(p, rinner, st::msgFileRadialLine, sti->historyFileThumbRadialFg);
} }
} }
if (showEnlarge) {
auto hq = PainterHighQualityEnabler(p);
const auto rect = enlargeRect();
const auto radius = st::historyPageEnlargeRadius;
p.drawRoundedRect(rect, radius, radius);
sti->historyPageEnlarge.paintInCenter(p, rect);
}
// date // date
if (!_caption.isEmpty()) { if (!_caption.isEmpty()) {
@ -631,6 +657,18 @@ QSize Photo::photoSize() const {
return QSize(_data->width(), _data->height()); return QSize(_data->width(), _data->height());
} }
QRect Photo::enlargeRect() const {
const auto skip = st::historyPageEnlargeSkip;
const auto enlargeInner = st::historyPageEnlargeSize;
const auto enlargeOuter = 2 * skip + enlargeInner;
return {
width() - enlargeOuter + skip,
skip,
enlargeInner,
enlargeInner,
};
}
TextState Photo::textState(QPoint point, StateRequest request) const { TextState Photo::textState(QPoint point, StateRequest request) const {
auto result = TextState(_parent); auto result = TextState(_parent);
@ -673,6 +711,11 @@ TextState Photo::textState(QPoint point, StateRequest request) const {
: _data->loading() : _data->loading()
? _cancell ? _cancell
: _savel; : _savel;
if (_showEnlarge
&& result.link == _openl
&& enlargeRect().contains(point)) {
result.cursor = CursorState::Enlarge;
}
} }
if (_caption.isEmpty() && _parent->media() == this) { if (_caption.isEmpty() && _parent->media() == this) {
auto fullRight = paintx + paintw; auto fullRight = paintx + paintw;

View file

@ -163,6 +163,7 @@ private:
QPoint photoPosition) const; QPoint photoPosition) const;
[[nodiscard]] QSize photoSize() const; [[nodiscard]] QSize photoSize() const;
[[nodiscard]] QRect enlargeRect() const;
void togglePollingStory(bool enabled) const; void togglePollingStory(bool enabled) const;
@ -178,6 +179,7 @@ private:
mutable uint32 _imageCacheForum : 1 = 0; mutable uint32 _imageCacheForum : 1 = 0;
mutable uint32 _imageCacheBlurred : 1 = 0; mutable uint32 _imageCacheBlurred : 1 = 0;
mutable uint32 _pollingStory : 1 = 0; mutable uint32 _pollingStory : 1 = 0;
mutable uint32 _showEnlarge : 1 = 0;
}; };

View file

@ -783,7 +783,11 @@ TextState WebPage::textState(QPoint point, StateRequest request) const {
auto attachTop = tshift - bubble.top(); auto attachTop = tshift - bubble.top();
if (rtl()) attachLeft = width() - attachLeft - _attach->width(); if (rtl()) attachLeft = width() - attachLeft - _attach->width();
result = _attach->textState(point - QPoint(attachLeft, attachTop), request); result = _attach->textState(point - QPoint(attachLeft, attachTop), request);
result.link = replaceAttachLink(result.link); if (result.cursor == CursorState::Enlarge) {
result.cursor = CursorState::None;
} else {
result.link = replaceAttachLink(result.link);
}
} }
} }
if (!result.link && outer.contains(point)) { if (!result.link && outer.contains(point)) {

View file

@ -640,6 +640,12 @@ historyPageButtonLine: 1px;
historyPageButtonHeight: 36px; historyPageButtonHeight: 36px;
historyPageButtonPadding: margins(13px, 8px, 13px, 8px); historyPageButtonPadding: margins(13px, 8px, 13px, 8px);
historyPageEnlarge: icon{{ "chat/link_photo_enlarge", historyFileThumbRadialFg }};
historyPageEnlargeSelected: icon{{ "chat/link_photo_enlarge", historyFileThumbRadialFgSelected }};
historyPageEnlargeSize: 36px;
historyPageEnlargeSkip: 4px;
historyPageEnlargeRadius: 8px;
historyCommentsButtonHeight: 40px; historyCommentsButtonHeight: 40px;
historyCommentsSkipLeft: 9px; historyCommentsSkipLeft: 9px;
historyCommentsSkipText: 10px; historyCommentsSkipText: 10px;

View file

@ -505,6 +505,10 @@ ChatStyle::ChatStyle(rpl::producer<ColorIndicesCompressed> colorIndices) {
&MessageImageStyle::historyVideoMessageMute, &MessageImageStyle::historyVideoMessageMute,
st::historyVideoMessageMute, st::historyVideoMessageMute,
st::historyVideoMessageMuteSelected); st::historyVideoMessageMuteSelected);
make(
&MessageImageStyle::historyPageEnlarge,
st::historyPageEnlarge,
st::historyPageEnlargeSelected);
updateDarkValue(); updateDarkValue();
} }

View file

@ -117,6 +117,7 @@ struct MessageImageStyle {
style::icon historyVideoDownload = { Qt::Uninitialized }; style::icon historyVideoDownload = { Qt::Uninitialized };
style::icon historyVideoCancel = { Qt::Uninitialized }; style::icon historyVideoCancel = { Qt::Uninitialized };
style::icon historyVideoMessageMute = { Qt::Uninitialized }; style::icon historyVideoMessageMute = { Qt::Uninitialized };
style::icon historyPageEnlarge = { Qt::Uninitialized };
}; };
struct ReactionPaintInfo { struct ReactionPaintInfo {