tdesktop/Telegram/SourceFiles/info/media/info_media_widget.cpp

134 lines
3.2 KiB
C++
Raw Normal View History

/*
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"
2017-11-03 12:03:00 +00:00
#include "ui/search_field_controller.h"
2019-09-13 12:22:54 +00:00
#include "ui/ui_utility.h"
2020-06-08 09:06:50 +00:00
#include "data/data_peer.h"
2017-11-03 12:03:00 +00:00
#include "styles/style_info.h"
namespace Info {
namespace Media {
2018-09-21 16:28:46 +00:00
std::optional<int> TypeToTabIndex(Type type) {
2017-11-03 12:03:00 +00:00
switch (type) {
case Type::Photo: return 0;
case Type::Video: return 1;
case Type::File: return 2;
}
2018-09-21 16:28:46 +00:00
return std::nullopt;
2017-11-03 12:03:00 +00:00
}
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*> controller)
: Memento(
2020-06-08 09:06:50 +00:00
controller->peer(),
controller->migratedPeerId(),
controller->section().mediaType()) {
}
2020-06-08 09:06:50 +00:00
Memento::Memento(not_null<PeerData*> peer, PeerId migratedPeerId, Type type)
: ContentMemento(peer, migratedPeerId)
2017-11-03 15:47:08 +00:00
, _type(type) {
_searchState.query.type = type;
2020-06-08 09:06:50 +00:00
_searchState.query.peerId = peer->id;
2017-11-03 15:47:08 +00:00
_searchState.query.migratedPeerId = migratedPeerId;
if (migratedPeerId) {
_searchState.migratedList = Storage::SparseIdsList();
}
}
Section Memento::section() const {
return Section(_type);
}
object_ptr<ContentWidget> Memento::createWidget(
QWidget *parent,
not_null<Controller*> controller,
const QRect &geometry) {
auto result = object_ptr<Widget>(
parent,
controller);
result->setInternalState(geometry, this);
return result;
}
Widget::Widget(
QWidget *parent,
not_null<Controller*> controller)
: ContentWidget(parent, controller) {
_inner = setInnerWidget(object_ptr<InnerWidget>(
this,
controller));
2017-11-14 17:22:44 +00:00
_inner->setScrollHeightValue(scrollHeightValue());
_inner->scrollToRequests(
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
scrollTo(request);
}, _inner->lifetime());
}
rpl::producer<SelectedItems> Widget::selectedListValue() const {
return _inner->selectedListValue();
}
void Widget::cancelSelection() {
_inner->cancelSelection();
}
void Widget::setIsStackBottom(bool isStackBottom) {
_inner->setIsStackBottom(isStackBottom);
}
bool Widget::showInternal(not_null<ContentMemento*> memento) {
if (!controller()->validateMementoPeer(memento)) {
return false;
}
2018-09-05 19:05:49 +00:00
if (const auto mediaMemento = dynamic_cast<Memento*>(memento.get())) {
if (_inner->showInternal(mediaMemento)) {
return true;
}
}
return false;
}
void Widget::setInternalState(
const QRect &geometry,
not_null<Memento*> memento) {
setGeometry(geometry);
Ui::SendPendingMoveResizeEvents(this);
restoreState(memento);
}
2020-12-14 14:48:10 +00:00
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
auto result = std::make_shared<Memento>(controller());
saveState(result.get());
return result;
}
void Widget::saveState(not_null<Memento*> memento) {
_inner->saveState(memento);
}
void Widget::restoreState(not_null<Memento*> memento) {
_inner->restoreState(memento);
}
} // namespace Media
} // namespace Info