From efa72578cd2557fdcc918be88582ef689faace02 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 15 Dec 2017 22:05:10 +0300 Subject: [PATCH] Fix grouped media display in MediaView. --- Telegram/SourceFiles/boxes/send_files_box.cpp | 2 +- .../SourceFiles/data/data_shared_media.cpp | 2 +- Telegram/SourceFiles/history/history_media.h | 5 +++- .../history/history_media_grouped.h | 7 +++++ .../history/history_media_types.cpp | 4 +-- .../SourceFiles/history/history_media_types.h | 20 ++++++++----- .../SourceFiles/history/history_widget.cpp | 2 +- .../info/media/info_media_list_widget.cpp | 2 +- Telegram/SourceFiles/mediaview.cpp | 28 ++++++++----------- 9 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 4d1fe4a4c8..98279510ed 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -480,7 +480,7 @@ EditCaptionBox::EditCaptionBox(QWidget*, HistoryMedia *media, FullMsgId msgId) : case MediaTypePhoto: { _photo = true; - auto photo = static_cast(media)->photo(); + auto photo = static_cast(media)->getPhoto(); dimensions = QSize(photo->full->width(), photo->full->height()); image = photo->full; } break; diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index 767c54f425..3b776b85e2 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -291,7 +291,7 @@ base::optional SharedMediaWithLastSlice::IsLastIsolated( | [](HistoryItem *item) { return item ? item->getMedia() : nullptr; } | [](HistoryMedia *media) { return (media && media->type() == MediaTypePhoto) - ? static_cast(media)->photo().get() + ? static_cast(media)->getPhoto() : nullptr; } | [](PhotoData *photo) { return photo ? photo->id : 0; } diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index f0664871da..3ed31ca8e0 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -138,7 +138,10 @@ public: not_null newParent, not_null realParent) const = 0; - virtual DocumentData *getDocument() { + virtual PhotoData *getPhoto() const { + return nullptr; + } + virtual DocumentData *getDocument() const { return nullptr; } virtual Media::Clip::Reader *getClipReader() { diff --git a/Telegram/SourceFiles/history/history_media_grouped.h b/Telegram/SourceFiles/history/history_media_grouped.h index 06071bd63f..ed5cf1a090 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.h +++ b/Telegram/SourceFiles/history/history_media_grouped.h @@ -65,6 +65,13 @@ public: return !_caption.isEmpty(); } + PhotoData *getPhoto() const override { + return main()->getPhoto(); + } + DocumentData *getDocument() const override { + return main()->getDocument(); + } + QString notificationText() const override; QString inDialogsText() const override; TextWithEntities selectedText(TextSelection selection) const override; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 6faa7b8732..a3f19ff6f4 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -123,7 +123,7 @@ QSize CountPixSizeForSize(QSize original, QSize geometry) { auto tw = original.width(); auto th = original.height(); if (tw * height > th * width) { - if (tw * height < 2 * th * width) { + if (th > height || tw * height < 2 * th * width) { tw = (height * tw) / th; th = height; } else if (tw < width) { @@ -131,7 +131,7 @@ QSize CountPixSizeForSize(QSize original, QSize geometry) { tw = width; } } else { - if (th * width < 2 * tw * height) { + if (tw > width || th * width < 2 * tw * height) { th = (width * th) / tw; tw = width; } else if (tw > 0 && th < height) { diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index 54386cfed2..86d788a382 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -199,7 +199,7 @@ public: Storage::SharedMediaTypesMask sharedMediaTypes() const override; - not_null photo() const { + PhotoData *getPhoto() const override { return _data; } @@ -318,7 +318,7 @@ public: Storage::SharedMediaTypesMask sharedMediaTypes() const override; - DocumentData *getDocument() override { + DocumentData *getDocument() const override { return _data; } @@ -517,7 +517,7 @@ public: return _data->uploading(); } - DocumentData *getDocument() override { + DocumentData *getDocument() const override { return _data; } @@ -632,7 +632,7 @@ public: return _data->uploading(); } - DocumentData *getDocument() override { + DocumentData *getDocument() const override { return _data; } Media::Clip::Reader *getClipReader() override { @@ -743,7 +743,7 @@ public: QString notificationText() const override; TextWithEntities selectedText(TextSelection selection) const override; - DocumentData *getDocument() override { + DocumentData *getDocument() const override { return _data; } @@ -973,7 +973,10 @@ public: bool isDisplayed() const override { return !_data->pendingTill && !_parent->Has(); } - DocumentData *getDocument() override { + PhotoData *getPhoto() const override { + return _attach ? _attach->getPhoto() : nullptr; + } + DocumentData *getDocument() const override { return _attach ? _attach->getDocument() : nullptr; } Media::Clip::Reader *getClipReader() override { @@ -1089,7 +1092,10 @@ public: void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; - DocumentData *getDocument() override { + PhotoData *getPhoto() const override { + return _attach ? _attach->getPhoto() : nullptr; + } + DocumentData *getDocument() const override { return _attach ? _attach->getDocument() : nullptr; } Media::Clip::Reader *getClipReader() override { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ecf8698ffa..d3d3bf4b2a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4508,7 +4508,7 @@ void HistoryWidget::onThumbDocumentUploaded( void HistoryWidget::onPhotoProgress(const FullMsgId &newId) { if (const auto item = App::histItemById(newId)) { const auto photo = (item->getMedia() && item->getMedia()->type() == MediaTypePhoto) - ? static_cast(item->getMedia())->photo().get() + ? static_cast(item->getMedia())->getPhoto() : nullptr; updateSendAction(item->history(), SendAction::Type::UploadPhoto, 0); Auth().data().requestItemRepaint(item); diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 4a38d29ae9..52695c9b71 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -849,7 +849,7 @@ std::unique_ptr ListWidget::createLayout( auto getPhoto = [&]() -> PhotoData* { if (auto media = item->getMedia()) { if (media->type() == MediaTypePhoto) { - return static_cast(media)->photo(); + return static_cast(media)->getPhoto(); } } return nullptr; diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 99503b62a1..31d3321091 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1266,8 +1266,9 @@ void MediaView::displayPhoto(not_null photo, HistoryItem *item) { _zoom = 0; _caption = Text(); - if (auto itemMsg = item ? item->toHistoryMessage() : nullptr) { - if (auto photoMsg = dynamic_cast(itemMsg->getMedia())) { + if (const auto media = item ? item->getMedia() : nullptr) { + const auto caption = media->getCaption(); + if (!caption.text.isEmpty()) { auto asBot = (item->author()->isUser() && item->author()->asUser()->botInfo); auto skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width()); @@ -1275,7 +1276,7 @@ void MediaView::displayPhoto(not_null photo, HistoryItem *item) { _caption = Text(maxw); _caption.setMarkedText( st::mediaviewCaptionStyle, - photoMsg->getCaption(), + caption, itemTextOptions(item)); } } @@ -2254,21 +2255,16 @@ MediaView::Entity MediaView::entityForSharedMedia(int index) const { return { base::none, nullptr }; } auto value = (*_sharedMediaData)[index]; - if (auto photo = base::get_if>(&value)) { + if (const auto photo = base::get_if>(&value)) { // Last peer photo. return { *photo, nullptr }; - } else if (auto itemId = base::get_if(&value)) { - if (auto item = App::histItemById(*itemId)) { - if (auto media = item->getMedia()) { - switch (media->type()) { - case MediaTypePhoto: return { - static_cast(item->getMedia())->photo(), - item - }; - case MediaTypeFile: - case MediaTypeVideo: - case MediaTypeGif: - case MediaTypeSticker: return { media->getDocument(), item }; + } else if (const auto itemId = base::get_if(&value)) { + if (const auto item = App::histItemById(*itemId)) { + if (const auto media = item->getMedia()) { + if (const auto photo = media->getPhoto()) { + return { photo, item }; + } else if (const auto document = media->getDocument()) { + return { document, item }; } } return { base::none, item };