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 <rpl/range.h>
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
|
#include "ui/widgets/input_fields.h"
|
||||||
#include "ui/wrap/padding_wrap.h"
|
#include "ui/wrap/padding_wrap.h"
|
||||||
#include "ui/search_field_controller.h"
|
#include "ui/search_field_controller.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -206,7 +207,11 @@ bool ContentWidget::hasTopBarShadow() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWidget::setInnerFocus() {
|
void ContentWidget::setInnerFocus() {
|
||||||
_innerWrap->entity()->setFocus();
|
if (_searchField) {
|
||||||
|
_searchField->setFocus();
|
||||||
|
} else {
|
||||||
|
_innerWrap->entity()->setFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ContentWidget::scrollTopSave() const {
|
int ContentWidget::scrollTopSave() const {
|
||||||
|
@ -236,18 +241,21 @@ rpl::producer<SelectedItems> ContentWidget::selectedListValue() const {
|
||||||
void ContentWidget::refreshSearchField(bool shown) {
|
void ContentWidget::refreshSearchField(bool shown) {
|
||||||
auto search = _controller->searchFieldController();
|
auto search = _controller->searchFieldController();
|
||||||
if (search && shown) {
|
if (search && shown) {
|
||||||
_searchWrap = search->createRowView(
|
auto rowView = search->createRowView(
|
||||||
this,
|
this,
|
||||||
st::infoLayerMediaSearch);
|
st::infoLayerMediaSearch);
|
||||||
auto field = _searchWrap.get();
|
_searchWrap = std::move(rowView.wrap);
|
||||||
|
_searchField = rowView.field;
|
||||||
|
|
||||||
|
const auto view = _searchWrap.get();
|
||||||
widthValue()
|
widthValue()
|
||||||
| rpl::start_with_next([field](int newWidth) {
|
| rpl::start_with_next([=](int newWidth) {
|
||||||
field->resizeToWidth(newWidth);
|
view->resizeToWidth(newWidth);
|
||||||
field->moveToLeft(0, 0);
|
view->moveToLeft(0, 0);
|
||||||
}, field->lifetime());
|
}, view->lifetime());
|
||||||
field->show();
|
view->show();
|
||||||
field->setFocus();
|
_searchField->setFocus();
|
||||||
setScrollTopSkip(field->heightNoMargins() - st::lineWidth);
|
setScrollTopSkip(view->heightNoMargins() - st::lineWidth);
|
||||||
} else {
|
} else {
|
||||||
setFocus();
|
setFocus();
|
||||||
_searchWrap = nullptr;
|
_searchWrap = nullptr;
|
||||||
|
|
|
@ -30,6 +30,7 @@ enum class SharedMediaType : char;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ScrollArea;
|
class ScrollArea;
|
||||||
|
class InputField;
|
||||||
struct ScrollToRequest;
|
struct ScrollToRequest;
|
||||||
template <typename Widget>
|
template <typename Widget>
|
||||||
class PaddingWrap;
|
class PaddingWrap;
|
||||||
|
@ -113,6 +114,7 @@ private:
|
||||||
object_ptr<Ui::ScrollArea> _scroll;
|
object_ptr<Ui::ScrollArea> _scroll;
|
||||||
Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr;
|
Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr;
|
||||||
base::unique_qptr<Ui::RpWidget> _searchWrap = nullptr;
|
base::unique_qptr<Ui::RpWidget> _searchWrap = nullptr;
|
||||||
|
QPointer<Ui::InputField> _searchField;
|
||||||
int _innerDesiredHeight = 0;
|
int _innerDesiredHeight = 0;
|
||||||
|
|
||||||
// Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent().
|
// Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent().
|
||||||
|
|
|
@ -33,9 +33,9 @@ SearchFieldController::SearchFieldController(const QString &query)
|
||||||
: _query(query) {
|
: _query(query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::unique_qptr<Ui::RpWidget> SearchFieldController::createRowView(
|
auto SearchFieldController::createRowView(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
const style::SearchFieldRow &st) {
|
const style::SearchFieldRow &st) -> RowView {
|
||||||
auto result = base::make_unique_q<Ui::FixedHeightWidget>(
|
auto result = base::make_unique_q<Ui::FixedHeightWidget>(
|
||||||
parent,
|
parent,
|
||||||
st.height);
|
st.height);
|
||||||
|
@ -94,7 +94,7 @@ base::unique_qptr<Ui::RpWidget> SearchFieldController::createRowView(
|
||||||
|
|
||||||
_view.release();
|
_view.release();
|
||||||
_view.reset(wrap);
|
_view.reset(wrap);
|
||||||
return std::move(result);
|
return { std::move(result), field };
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SearchFieldController::query() const {
|
QString SearchFieldController::query() const {
|
||||||
|
|
|
@ -41,7 +41,11 @@ public:
|
||||||
base::unique_qptr<Ui::InputField> createField(
|
base::unique_qptr<Ui::InputField> createField(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
const style::InputField &st);
|
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,
|
QWidget *parent,
|
||||||
const style::SearchFieldRow &st);
|
const style::SearchFieldRow &st);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue