From 827784e3b205a987c24055b7f98fe4bdf9d3dd82 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 8 Dec 2017 12:22:02 +0400 Subject: [PATCH] Focus search field in Info layer. --- .../SourceFiles/info/info_content_widget.cpp | 28 ++++++++++++------- .../SourceFiles/info/info_content_widget.h | 2 ++ .../ui/search_field_controller.cpp | 6 ++-- .../SourceFiles/ui/search_field_controller.h | 6 +++- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 6ceb39de6..b11be19f9 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include "window/window_controller.h" #include "ui/widgets/scroll_area.h" +#include "ui/widgets/input_fields.h" #include "ui/wrap/padding_wrap.h" #include "ui/search_field_controller.h" #include "lang/lang_keys.h" @@ -206,7 +207,11 @@ bool ContentWidget::hasTopBarShadow() const { } void ContentWidget::setInnerFocus() { - _innerWrap->entity()->setFocus(); + if (_searchField) { + _searchField->setFocus(); + } else { + _innerWrap->entity()->setFocus(); + } } int ContentWidget::scrollTopSave() const { @@ -236,18 +241,21 @@ rpl::producer ContentWidget::selectedListValue() const { void ContentWidget::refreshSearchField(bool shown) { auto search = _controller->searchFieldController(); if (search && shown) { - _searchWrap = search->createRowView( + auto rowView = search->createRowView( this, st::infoLayerMediaSearch); - auto field = _searchWrap.get(); + _searchWrap = std::move(rowView.wrap); + _searchField = rowView.field; + + const auto view = _searchWrap.get(); widthValue() - | rpl::start_with_next([field](int newWidth) { - field->resizeToWidth(newWidth); - field->moveToLeft(0, 0); - }, field->lifetime()); - field->show(); - field->setFocus(); - setScrollTopSkip(field->heightNoMargins() - st::lineWidth); + | rpl::start_with_next([=](int newWidth) { + view->resizeToWidth(newWidth); + view->moveToLeft(0, 0); + }, view->lifetime()); + view->show(); + _searchField->setFocus(); + setScrollTopSkip(view->heightNoMargins() - st::lineWidth); } else { setFocus(); _searchWrap = nullptr; diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 15578bc95..1a7b02271 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -30,6 +30,7 @@ enum class SharedMediaType : char; namespace Ui { class ScrollArea; +class InputField; struct ScrollToRequest; template class PaddingWrap; @@ -113,6 +114,7 @@ private: object_ptr _scroll; Ui::PaddingWrap *_innerWrap = nullptr; base::unique_qptr _searchWrap = nullptr; + QPointer _searchField; int _innerDesiredHeight = 0; // Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent(). diff --git a/Telegram/SourceFiles/ui/search_field_controller.cpp b/Telegram/SourceFiles/ui/search_field_controller.cpp index 5c9cc37f4..67cde4d96 100644 --- a/Telegram/SourceFiles/ui/search_field_controller.cpp +++ b/Telegram/SourceFiles/ui/search_field_controller.cpp @@ -33,9 +33,9 @@ SearchFieldController::SearchFieldController(const QString &query) : _query(query) { } -base::unique_qptr SearchFieldController::createRowView( +auto SearchFieldController::createRowView( QWidget *parent, - const style::SearchFieldRow &st) { + const style::SearchFieldRow &st) -> RowView { auto result = base::make_unique_q( parent, st.height); @@ -94,7 +94,7 @@ base::unique_qptr SearchFieldController::createRowView( _view.release(); _view.reset(wrap); - return std::move(result); + return { std::move(result), field }; } QString SearchFieldController::query() const { diff --git a/Telegram/SourceFiles/ui/search_field_controller.h b/Telegram/SourceFiles/ui/search_field_controller.h index 794dc4eb2..feff4d356 100644 --- a/Telegram/SourceFiles/ui/search_field_controller.h +++ b/Telegram/SourceFiles/ui/search_field_controller.h @@ -41,7 +41,11 @@ public: base::unique_qptr createField( QWidget *parent, const style::InputField &st); - base::unique_qptr createRowView( + struct RowView { + base::unique_qptr wrap; + QPointer field; + }; + RowView createRowView( QWidget *parent, const style::SearchFieldRow &st);