2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-13 17:01:23 +00:00
|
|
|
*/
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/media/info_media_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/media/info_media_inner_widget.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#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"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Media {
|
2017-09-15 17:34:41 +00:00
|
|
|
|
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()");
|
|
|
|
}
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
|
|
|
: Memento(
|
2020-06-08 09:06:50 +00:00
|
|
|
controller->peer(),
|
2017-10-31 18:25:22 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(_type);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller,
|
2017-09-13 17:01:23 +00:00
|
|
|
const QRect &geometry) {
|
|
|
|
auto result = object_ptr<Widget>(
|
|
|
|
parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
controller);
|
2017-09-13 17:01:23 +00:00
|
|
|
result->setInternalState(geometry, this);
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller)
|
|
|
|
: ContentWidget(parent, controller) {
|
2017-10-04 12:39:59 +00:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
2017-10-31 18:25:22 +00:00
|
|
|
controller));
|
2017-11-14 17:22:44 +00:00
|
|
|
_inner->setScrollHeightValue(scrollHeightValue());
|
2017-12-22 07:05:20 +00:00
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
scrollTo(request);
|
|
|
|
}, _inner->lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:19:42 +00:00
|
|
|
rpl::producer<SelectedItems> Widget::selectedListValue() const {
|
|
|
|
return _inner->selectedListValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::cancelSelection() {
|
|
|
|
_inner->cancelSelection();
|
|
|
|
}
|
|
|
|
|
2017-12-05 12:23:08 +00:00
|
|
|
void Widget::setIsStackBottom(bool isStackBottom) {
|
|
|
|
_inner->setIsStackBottom(isStackBottom);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
2017-10-31 18:25:22 +00:00
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-05 19:05:49 +00:00
|
|
|
if (const auto mediaMemento = dynamic_cast<Memento*>(memento.get())) {
|
2017-10-04 12:39:59 +00:00
|
|
|
if (_inner->showInternal(mediaMemento)) {
|
2017-09-13 17:01:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
2017-09-13 17:01:23 +00:00
|
|
|
setGeometry(geometry);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
2017-09-13 17:01:23 +00:00
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
std::unique_ptr<ContentMemento> Widget::doCreateMemento() {
|
2017-10-31 18:25:22 +00:00
|
|
|
auto result = std::make_unique<Memento>(controller());
|
2017-09-13 17:01:23 +00:00
|
|
|
saveState(result.get());
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::saveState(not_null<Memento*> memento) {
|
|
|
|
_inner->saveState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::restoreState(not_null<Memento*> memento) {
|
|
|
|
_inner->restoreState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Media
|
|
|
|
} // namespace Info
|