/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/media/info_media_widget.h" #include "info/media/info_media_inner_widget.h" #include "info/info_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" #include "styles/style_info.h" namespace Info { namespace Media { base::optional TypeToTabIndex(Type type) { switch (type) { case Type::Photo: return 0; case Type::Video: return 1; case Type::File: return 2; } return base::none; } Type TabIndexToType(int index) { switch (index) { case 0: return Type::Photo; case 1: return Type::Video; case 2: return Type::File; } Unexpected("Index in Info::Media::TabIndexToType()"); } Memento::Memento(not_null controller) : Memento( controller->peerId(), controller->migratedPeerId(), controller->section().mediaType()) { } Memento::Memento(PeerId peerId, PeerId migratedPeerId, Type type) : ContentMemento(peerId, migratedPeerId) , _type(type) { _searchState.query.type = type; _searchState.query.peerId = peerId; _searchState.query.migratedPeerId = migratedPeerId; if (migratedPeerId) { _searchState.migratedList = Storage::SparseIdsList(); } } Section Memento::section() const { return Section(_type); } object_ptr Memento::createWidget( QWidget *parent, not_null controller, const QRect &geometry) { auto result = object_ptr( parent, controller); result->setInternalState(geometry, this); return std::move(result); } Widget::Widget( QWidget *parent, not_null controller) : ContentWidget(parent, controller) { _inner = setInnerWidget(object_ptr( this, controller)); _inner->setScrollHeightValue(scrollHeightValue()); _inner->scrollToRequests( ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { scrollTo(request); }, _inner->lifetime()); } rpl::producer Widget::selectedListValue() const { return _inner->selectedListValue(); } void Widget::cancelSelection() { _inner->cancelSelection(); } void Widget::setIsStackBottom(bool isStackBottom) { _inner->setIsStackBottom(isStackBottom); } bool Widget::showInternal(not_null memento) { if (!controller()->validateMementoPeer(memento)) { return false; } if (auto mediaMemento = dynamic_cast(memento.get())) { if (_inner->showInternal(mediaMemento)) { return true; } } return false; } void Widget::setInternalState( const QRect &geometry, not_null memento) { setGeometry(geometry); Ui::SendPendingMoveResizeEvents(this); restoreState(memento); } std::unique_ptr Widget::doCreateMemento() { auto result = std::make_unique(controller()); saveState(result.get()); return std::move(result); } void Widget::saveState(not_null memento) { _inner->saveState(memento); } void Widget::restoreState(not_null memento) { _inner->restoreState(memento); } } // namespace Media } // namespace Info