From 053eace154cafde7f5eaba06585adae6cf45f333 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 21 May 2020 16:27:04 +0400 Subject: [PATCH] Prepare overview layouts for media clearing. --- Telegram/CMakeLists.txt | 1 + .../info/media/info_media_list_widget.cpp | 85 ++++++++++++++----- .../info/media/info_media_list_widget.h | 45 +++++----- .../SourceFiles/overview/overview_layout.cpp | 27 ++++-- .../SourceFiles/overview/overview_layout.h | 29 +++++-- .../overview/overview_layout_delegate.h | 22 +++++ 6 files changed, 152 insertions(+), 57 deletions(-) create mode 100644 Telegram/SourceFiles/overview/overview_layout_delegate.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index d5e0d70c43..1066d68f0d 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -756,6 +756,7 @@ PRIVATE mtproto/type_utils.h overview/overview_layout.cpp overview/overview_layout.h + overview/overview_layout_delegate.h passport/passport_encryption.cpp passport/passport_encryption.h passport/passport_form_controller.cpp diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 2af34bd183..58714ae4a3 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -112,6 +112,7 @@ public: bool removeItem(UniversalMsgId universalId); FoundItem findItemNearId(UniversalMsgId universalId) const; + FoundItem findItemDetails(not_null item) const; FoundItem findItemByPoint(QPoint point) const; void paint( @@ -190,6 +191,11 @@ ListWidget::CachedItem::CachedItem(std::unique_ptr item) : item(std::move(item)) { } +ListWidget::CachedItem::CachedItem(CachedItem &&other) = default; + +ListWidget::CachedItem &ListWidget::CachedItem::operator=( + CachedItem && other) = default; + ListWidget::CachedItem::~CachedItem() = default; bool ListWidget::Section::addItem(not_null item) { @@ -306,9 +312,10 @@ auto ListWidget::Section::findItemByPoint( return { item, rect, rect.contains(point) }; } -auto ListWidget::Section::findItemNearId( - UniversalMsgId universalId) const -> FoundItem { +auto ListWidget::Section::findItemNearId(UniversalMsgId universalId) const +-> FoundItem { Expects(!_items.empty()); + auto itemIt = ranges::lower_bound( _items, universalId, @@ -322,6 +329,11 @@ auto ListWidget::Section::findItemNearId( return { item, findItemRect(item), exact }; } +auto ListWidget::Section::findItemDetails(not_null item) const +-> FoundItem { + return { item, findItemRect(item), true }; +} + auto ListWidget::Section::findItemAfterTop( int top) -> Items::iterator { return ranges::lower_bound( @@ -621,6 +633,7 @@ void ListWidget::restart() { _overLayout = nullptr; _sections.clear(); _layouts.clear(); + _heavyLayouts.clear(); _universalAroundId = kDefaultAroundId; _idsLimit = kMinimalIdsLimit; @@ -631,11 +644,11 @@ void ListWidget::restart() { void ListWidget::itemRemoved(not_null item) { if (isMyItem(item)) { - auto universalId = GetUniversalId(item); + auto id = GetUniversalId(item); - auto sectionIt = findSectionByItem(universalId); + auto sectionIt = findSectionByItem(id); if (sectionIt != _sections.end()) { - if (sectionIt->removeItem(universalId)) { + if (sectionIt->removeItem(id)) { auto top = sectionIt->top(); if (sectionIt->empty()) { _sections.erase(sectionIt); @@ -648,11 +661,13 @@ void ListWidget::itemRemoved(not_null item) { _overLayout = nullptr; } - _layouts.erase(universalId); - _dragSelected.remove(universalId); + if (const auto i = _layouts.find(id); i != _layouts.end()) { + _heavyLayouts.remove(i->second.item.get()); + _layouts.erase(i); + } + _dragSelected.remove(id); - auto i = _selected.find(universalId); - if (i != _selected.cend()) { + if (const auto i = _selected.find(id); i != _selected.cend()) { removeItemSelection(i); } @@ -789,6 +804,10 @@ void ListWidget::invalidatePaletteCache() { } } +void ListWidget::registerHeavyItem(not_null item) { + _heavyLayouts.emplace(item); +} + SparseIdsMergedSlice::Key ListWidget::sliceKey( UniversalMsgId universalId) const { using Key = SparseIdsMergedSlice::Key; @@ -871,31 +890,31 @@ std::unique_ptr ListWidget::createLayout( switch (type) { case Type::Photo: if (const auto photo = getPhoto()) { - return std::make_unique(item, photo); + return std::make_unique(this, item, photo); } return nullptr; case Type::Video: if (const auto file = getFile()) { - return std::make_unique