From 9b2f2b104fe9b0ca92008b0adda803cfd0233475 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 9 Nov 2023 22:25:08 +0400 Subject: [PATCH] Show enlarge photo button in webpage preview. --- .../icons/chat/link_photo_enlarge.png | Bin 0 -> 661 bytes .../icons/chat/link_photo_enlarge@2x.png | Bin 0 -> 1171 bytes .../icons/chat/link_photo_enlarge@3x.png | Bin 0 -> 1813 bytes Telegram/SourceFiles/data/data_web_page.cpp | 4 ++ Telegram/SourceFiles/data/data_web_page.h | 1 + .../history/view/history_view_cursor_state.h | 1 + .../history/view/media/history_view_photo.cpp | 57 +++++++++++++++--- .../history/view/media/history_view_photo.h | 2 + .../view/media/history_view_web_page.cpp | 6 +- Telegram/SourceFiles/ui/chat/chat.style | 6 ++ Telegram/SourceFiles/ui/chat/chat_style.cpp | 4 ++ Telegram/SourceFiles/ui/chat/chat_style.h | 1 + 12 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 Telegram/Resources/icons/chat/link_photo_enlarge.png create mode 100644 Telegram/Resources/icons/chat/link_photo_enlarge@2x.png create mode 100644 Telegram/Resources/icons/chat/link_photo_enlarge@3x.png diff --git a/Telegram/Resources/icons/chat/link_photo_enlarge.png b/Telegram/Resources/icons/chat/link_photo_enlarge.png new file mode 100644 index 0000000000000000000000000000000000000000..c4ba35289e0e7b521d0448a6abe84d9dda19f0df GIT binary patch literal 661 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uv49!D1}S`GTDlgf?7ydrV~B;| z-QfMJ8v`Zw)lHf7hmpr?O47v6B?cQjy*6sh?iD(vHkrpulBX=qaDj-KW<7&b-4dN0 zDuwSa+m^oDDStmhcE@YULSlxX+Cta-dN|tE~9~<-b+q%z=O>_t_ZH;%zijgsW9Xvh46ffw-!@^OOs>yDb(JUm2nm5}+Y+FkwPo zsMgho1sPkTrd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;rLR{S4-3cZDu6_FSDGm7n5aRNX#Amx8 ztOAnAhLc=p3>`sSWdbpK-dJ{-nVG0)L}x4@ARszAn$WPL(EOkw&R9=R&x;o?Xodik z*ht4{2n7gM6KHL1rR_dAILOc1w9Eti;YX4P;O5Pn{6YmxuC4g~{d?kzblcX}mWCPu zqT-cRfKwuuVb7mGCw7S75fKqI)CgdgXmxdUYHCWUATGmtdwbCvB-W-SZ$xesKtaTw z%&x93_GB6*7ZA7%+uYnlDM1_)5)#;xP4j92DJd!F@DMjPy`o9g0JLe@(~N4Ghjmm` z6j5=8Y#d;mD5AnnVU6SwstgC)164E0L)FMr|KZ}s{RS$md17KBkI15;B9a0Cy+BMOO9-jGBk>=pwfagM5D*&%wzvgTusG`6Tc##zkxTdDY%vSsP z^XF$~W>~g(-v|v2RYzlfF7@^GtP+6HB$G^zd3fTwNA)FQh#^eH=H%g^8V(}l(9n=b z6|}q2LRA!+{rvnoJ3B>u*x@g*4Yv*Y&#V#xjLYiYy?Y@cA#5Ej@+cx?e0)5fLXAFi zf~U#0{aeP1#PbYGN=okDy(?)03Jp{-xM~5Qn}9HYdIvxJtsp!+Trw)aDTwuk4-x2p zAZVeA=TS*Doa@)Gi=N92myu_ty}jMT!vlv(6h#DDlh@5GJJE8<$;tWj=@X9uhBzZ5 zBj_BG28YWwsD-u!Zi3O#Q8bASwKtqWuxV*&5w&6k^A4SDf?7C8ckbN5ll1ubI8GN` z=tyU=X%S9qYina;W91)f4ykRluK);tgfJoH`w!U0+NlWspW24>Qjwbu9rAwbR#{nj z=yX-8kfd$sNy_ly>Uqe}AIvAD9Y{VzPcV37Js9blOToIKY!|LX0P<(dtXxrZQw#(k zFGWp&X{;VBH2AJh=pN8LpnE{~fbId^1G)!(g$MowfHDwG_3`nJ00000NkvXXu0mjf D5=Tbk literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index e8eef89784..95b042775c 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -391,3 +391,7 @@ bool WebPageData::computeDefaultSmallMedia() const { } return false; } + +bool WebPageData::suggestEnlargePhoto() const { + return !siteName.isEmpty() || !title.isEmpty() || !description.empty(); +} diff --git a/Telegram/SourceFiles/data/data_web_page.h b/Telegram/SourceFiles/data/data_web_page.h index 9aea4a0f58..04f16a7b66 100644 --- a/Telegram/SourceFiles/data/data_web_page.h +++ b/Telegram/SourceFiles/data/data_web_page.h @@ -90,6 +90,7 @@ struct WebPageData { [[nodiscard]] QString displayedSiteName() const; [[nodiscard]] bool computeDefaultSmallMedia() const; + [[nodiscard]] bool suggestEnlargePhoto() const; const WebPageId id = 0; WebPageType type = WebPageType::None; diff --git a/Telegram/SourceFiles/history/view/history_view_cursor_state.h b/Telegram/SourceFiles/history/view/history_view_cursor_state.h index 82fcda9547..d5bcaa6f94 100644 --- a/Telegram/SourceFiles/history/view/history_view_cursor_state.h +++ b/Telegram/SourceFiles/history/view/history_view_cursor_state.h @@ -22,6 +22,7 @@ enum class CursorState : char { None, Text, Date, + Enlarge, Forwarded, }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index b3d79c6fe2..85a2997a8b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_file_click_handler.h" #include "data/data_file_origin.h" #include "data/data_auto_download.h" +#include "data/data_web_page.h" #include "core/application.h" #include "styles/style_chat.h" @@ -242,6 +243,7 @@ QSize Photo::countCurrentSize(int newWidth) { maxWidth()); newWidth = qMax(pix.width(), minWidth); auto newHeight = qMax(pix.height(), st::minPhotoSize); + auto imageHeight = newHeight; if (_parent->hasBubble() && !_caption.isEmpty()) { auto captionMaxWidth = st::msgPadding.left() + _caption.maxWidth() @@ -252,7 +254,7 @@ QSize Photo::countCurrentSize(int newWidth) { } const auto maxWithCaption = qMin(st::msgMaxWidth, captionMaxWidth); newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth); - newHeight = adjustHeightForLessCrop( + imageHeight = newHeight = adjustHeightForLessCrop( dimensions, { newWidth, newHeight }); const auto captionw = newWidth @@ -266,6 +268,15 @@ QSize Photo::countCurrentSize(int newWidth) { 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 }; } @@ -351,15 +362,16 @@ void Photo::draw(Painter &p, const PaintContext &context) const { fillImageOverlay(p, rthumb, rounding, context); } } - if (radial || (!loaded && !_data->loading())) { - 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); + + const auto showEnlarge = loaded && _showEnlarge; + const auto paintInCenter = (radial || (!loaded && !_data->loading())); + if (paintInCenter || showEnlarge) { p.setPen(Qt::NoPen); if (context.selected()) { p.setBrush(st->msgDateImgBgSelected()); + } else if (showEnlarge) { + const auto over = ClickHandler::showAsActive(_openl); + p.setBrush(over ? st->msgDateImgBgOver() : st->msgDateImgBg()); } else if (isThumbAnimation()) { const auto over = _animation->a_thumbOver.value(1.); 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); 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()); @@ -386,6 +405,13 @@ void Photo::draw(Painter &p, const PaintContext &context) const { _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 if (!_caption.isEmpty()) { @@ -631,6 +657,18 @@ QSize Photo::photoSize() const { 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 { auto result = TextState(_parent); @@ -673,6 +711,11 @@ TextState Photo::textState(QPoint point, StateRequest request) const { : _data->loading() ? _cancell : _savel; + if (_showEnlarge + && result.link == _openl + && enlargeRect().contains(point)) { + result.cursor = CursorState::Enlarge; + } } if (_caption.isEmpty() && _parent->media() == this) { auto fullRight = paintx + paintw; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.h b/Telegram/SourceFiles/history/view/media/history_view_photo.h index 7213dca210..4b123cc7c1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.h +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.h @@ -163,6 +163,7 @@ private: QPoint photoPosition) const; [[nodiscard]] QSize photoSize() const; + [[nodiscard]] QRect enlargeRect() const; void togglePollingStory(bool enabled) const; @@ -178,6 +179,7 @@ private: mutable uint32 _imageCacheForum : 1 = 0; mutable uint32 _imageCacheBlurred : 1 = 0; mutable uint32 _pollingStory : 1 = 0; + mutable uint32 _showEnlarge : 1 = 0; }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 56299bf451..c622585b9a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -783,7 +783,11 @@ TextState WebPage::textState(QPoint point, StateRequest request) const { auto attachTop = tshift - bubble.top(); if (rtl()) attachLeft = width() - attachLeft - _attach->width(); 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)) { diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index d4f189ac00..7567c501a8 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -640,6 +640,12 @@ historyPageButtonLine: 1px; historyPageButtonHeight: 36px; 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; historyCommentsSkipLeft: 9px; historyCommentsSkipText: 10px; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index 7bdebaee17..d85da4ec4f 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -505,6 +505,10 @@ ChatStyle::ChatStyle(rpl::producer colorIndices) { &MessageImageStyle::historyVideoMessageMute, st::historyVideoMessageMute, st::historyVideoMessageMuteSelected); + make( + &MessageImageStyle::historyPageEnlarge, + st::historyPageEnlarge, + st::historyPageEnlargeSelected); updateDarkValue(); } diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 39f5a76e44..afa63a7ae2 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -117,6 +117,7 @@ struct MessageImageStyle { style::icon historyVideoDownload = { Qt::Uninitialized }; style::icon historyVideoCancel = { Qt::Uninitialized }; style::icon historyVideoMessageMute = { Qt::Uninitialized }; + style::icon historyPageEnlarge = { Qt::Uninitialized }; }; struct ReactionPaintInfo {