2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Search and save state in common groups.

This commit is contained in:
John Preston
2017-11-03 22:26:14 +04:00
parent a6361d6221
commit 628c8e10f7
22 changed files with 290 additions and 85 deletions

View File

@@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <rpl/range.h>
#include "window/window_controller.h"
#include "ui/widgets/scroll_area.h"
#include "ui/search_field_controller.h"
#include "lang/lang_keys.h"
#include "info/profile/info_profile_widget.h"
#include "info/media/info_media_widget.h"
@@ -43,6 +44,8 @@ ContentWidget::ContentWidget(
: RpWidget(parent)
, _controller(controller)
, _scroll(this, st::infoScroll) {
using namespace rpl::mappers;
setAttribute(Qt::WA_OpaquePaintEvent);
_controller->wrapValue()
| rpl::start_with_next([this](Wrap value) {
@@ -51,6 +54,13 @@ ContentWidget::ContentWidget(
: st::profileBg;
update();
}, lifetime());
rpl::combine(
_controller->wrapValue(),
_controller->searchEnabledByContent(),
($1 == Wrap::Layer) && $2)
| rpl::start_with_next([this](bool shown) {
refreshSearchField(shown);
}, lifetime());
_scrollTopSkip.changes()
| rpl::start_with_next([this] {
updateControlsGeometry();
@@ -62,6 +72,9 @@ void ContentWidget::resizeEvent(QResizeEvent *e) {
}
void ContentWidget::updateControlsGeometry() {
if (!_inner) {
return;
}
auto newScrollTop = _scroll->scrollTop() + _topDelta;
auto scrollGeometry = rect().marginsRemoved(
QMargins(0, _scrollTopSkip.current(), 0, 0));
@@ -75,10 +88,18 @@ void ContentWidget::updateControlsGeometry() {
_scroll->scrollToY(newScrollTop);
}
auto scrollTop = _scroll->scrollTop();
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
_inner->setVisibleTopBottom(
scrollTop,
scrollTop + _scroll->height());
}
}
std::unique_ptr<ContentMemento> ContentWidget::createMemento() {
auto result = doCreateMemento();
_controller->saveSearchState(result.get());
return result;
}
void ContentWidget::paintEvent(QPaintEvent *e) {
Painter p(this);
p.fillRect(e->rect(), _bg);
@@ -100,8 +121,7 @@ void ContentWidget::setGeometryWithTopMoved(
}
Ui::RpWidget *ContentWidget::doSetInnerWidget(
object_ptr<RpWidget> inner,
int scrollTopSkip) {
object_ptr<RpWidget> inner) {
using namespace rpl::mappers;
_inner = _scroll->setOwnedWidget(std::move(inner));
@@ -119,8 +139,6 @@ Ui::RpWidget *ContentWidget::doSetInnerWidget(
inner->setVisibleTopBottom(top, bottom);
}, _inner->lifetime());
setScrollTopSkip(scrollTopSkip);
return _inner;
}
@@ -176,4 +194,24 @@ rpl::producer<SelectedItems> ContentWidget::selectedListValue() const {
return rpl::single(SelectedItems(Storage::SharedMediaType::Photo));
}
void ContentWidget::refreshSearchField(bool shown) {
auto search = _controller->searchFieldController();
if (search && shown) {
_searchField = search->createRowView(
this,
st::infoLayerMediaSearch);
auto field = _searchField.get();
widthValue()
| rpl::start_with_next([field](int newWidth) {
field->resizeToWidth(newWidth);
field->moveToLeft(0, 0);
}, field->lifetime());
field->show();
setScrollTopSkip(field->heightNoMargins() - st::lineWidth);
} else {
_searchField = nullptr;
setScrollTopSkip(0);
}
}
} // namespace Info