From b814c6307aee395cf2b25948b4639d648928af27 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 Aug 2019 17:03:34 +0300 Subject: [PATCH] Check that sticker drag point is inside. --- .../media/history_view_media_unwrapped.cpp | 32 +++++++++++++++++++ .../view/media/history_view_media_unwrapped.h | 1 + 2 files changed, 33 insertions(+) diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index 44ac864b29..f4e52bc344 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -195,6 +195,38 @@ void UnwrappedMedia::drawSurrounding( } } +PointState UnwrappedMedia::pointState(QPoint point) const { + if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { + return PointState::Outside; + } + + const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); + const auto inWebPage = (_parent->media() != this); + const auto item = _parent->data(); + const auto via = inWebPage ? nullptr : item->Get(); + const auto reply = inWebPage ? nullptr : item->Get(); + auto usex = 0; + auto usew = maxWidth(); + if (!inWebPage) { + usew -= additionalWidth(via, reply); + if (rightAligned) { + usex = width() - usew; + } + } + if (rtl()) { + usex = width() - usex - usew; + } + + const auto usey = rightAligned ? 0 : (height() - _contentSize.height()); + const auto useh = rightAligned + ? std::max( + _contentSize.height(), + height() - st::msgDateImgPadding.y() * 2 - st::msgDateFont->height) + : _contentSize.height(); + const auto inner = QRect(usex, usey, usew, useh); + return inner.contains(point) ? PointState::Inside : PointState::Outside; +} + TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { auto result = TextState(_parent); if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h index fffea017ff..de27f2d0f5 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h @@ -49,6 +49,7 @@ public: std::unique_ptr content); void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override; + PointState pointState(QPoint point) const override; TextState textState(QPoint point, StateRequest request) const override; bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {