mirror of https://github.com/procxx/kepka.git
Focus search field in Info layer.
This commit is contained in:
parent
b501af0b8f
commit
827784e3b2
|
@ -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/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<SelectedItems> 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;
|
||||
|
|
|
@ -30,6 +30,7 @@ enum class SharedMediaType : char;
|
|||
|
||||
namespace Ui {
|
||||
class ScrollArea;
|
||||
class InputField;
|
||||
struct ScrollToRequest;
|
||||
template <typename Widget>
|
||||
class PaddingWrap;
|
||||
|
@ -113,6 +114,7 @@ private:
|
|||
object_ptr<Ui::ScrollArea> _scroll;
|
||||
Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr;
|
||||
base::unique_qptr<Ui::RpWidget> _searchWrap = nullptr;
|
||||
QPointer<Ui::InputField> _searchField;
|
||||
int _innerDesiredHeight = 0;
|
||||
|
||||
// Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent().
|
||||
|
|
|
@ -33,9 +33,9 @@ SearchFieldController::SearchFieldController(const QString &query)
|
|||
: _query(query) {
|
||||
}
|
||||
|
||||
base::unique_qptr<Ui::RpWidget> SearchFieldController::createRowView(
|
||||
auto SearchFieldController::createRowView(
|
||||
QWidget *parent,
|
||||
const style::SearchFieldRow &st) {
|
||||
const style::SearchFieldRow &st) -> RowView {
|
||||
auto result = base::make_unique_q<Ui::FixedHeightWidget>(
|
||||
parent,
|
||||
st.height);
|
||||
|
@ -94,7 +94,7 @@ base::unique_qptr<Ui::RpWidget> SearchFieldController::createRowView(
|
|||
|
||||
_view.release();
|
||||
_view.reset(wrap);
|
||||
return std::move(result);
|
||||
return { std::move(result), field };
|
||||
}
|
||||
|
||||
QString SearchFieldController::query() const {
|
||||
|
|
|
@ -41,7 +41,11 @@ public:
|
|||
base::unique_qptr<Ui::InputField> createField(
|
||||
QWidget *parent,
|
||||
const style::InputField &st);
|
||||
base::unique_qptr<Ui::RpWidget> createRowView(
|
||||
struct RowView {
|
||||
base::unique_qptr<Ui::RpWidget> wrap;
|
||||
QPointer<Ui::InputField> field;
|
||||
};
|
||||
RowView createRowView(
|
||||
QWidget *parent,
|
||||
const style::SearchFieldRow &st);
|
||||
|
||||
|
|
Loading…
Reference in New Issue