| 149 | } |
| 150 | |
| 151 | base::weak_qptr<Ui::RpWidget> Search::createPinnedToTop( |
| 152 | not_null<QWidget*> parent) { |
| 153 | _searchController = std::make_unique<Ui::SearchFieldController>(""); |
| 154 | auto rowView = _searchController->createRowView( |
| 155 | parent, |
| 156 | st::infoLayerMediaSearch); |
| 157 | _searchField = rowView.field; |
| 158 | _searchField->customUpDown(true); |
| 159 | |
| 160 | const auto searchContainer = Ui::CreateChild<Ui::FixedHeightWidget>( |
| 161 | parent.get(), |
| 162 | st::infoLayerMediaSearch.height); |
| 163 | const auto wrap = rowView.wrap.release(); |
| 164 | wrap->setParent(searchContainer); |
| 165 | wrap->show(); |
| 166 | |
| 167 | searchContainer->widthValue( |
| 168 | ) | rpl::on_next([=](int width) { |
| 169 | wrap->resizeToWidth(width); |
| 170 | wrap->moveToLeft(0, 0); |
| 171 | }, searchContainer->lifetime()); |
| 172 | |
| 173 | _searchController->queryChanges() | rpl::on_next([=](QString &&query) { |
| 174 | rebuildResults(std::move(query)); |
| 175 | }, searchContainer->lifetime()); |
| 176 | |
| 177 | _searchField->submits( |
| 178 | ) | rpl::on_next([=](Qt::KeyboardModifiers) { |
| 179 | const auto index = (_selected >= 0) ? _selected : 0; |
| 180 | if (index < int(_visibleButtons.size())) { |
| 181 | _visibleButtons[index]->clicked( |
| 182 | Qt::NoModifier, |
| 183 | Qt::LeftButton); |
| 184 | } |
| 185 | }, searchContainer->lifetime()); |
| 186 | |
| 187 | base::install_event_filter(_searchField, [=](not_null<QEvent*> e) { |
| 188 | if (e->type() != QEvent::KeyPress) { |
| 189 | return base::EventFilterResult::Continue; |
| 190 | } |
| 191 | const auto key = static_cast<QKeyEvent*>(e.get())->key(); |
| 192 | if (key == Qt::Key_Up |
| 193 | || key == Qt::Key_Down |
| 194 | || key == Qt::Key_PageUp |
| 195 | || key == Qt::Key_PageDown) { |
| 196 | handleKeyNavigation(key); |
| 197 | return base::EventFilterResult::Cancel; |
| 198 | } |
| 199 | return base::EventFilterResult::Continue; |
| 200 | }, lifetime()); |
| 201 | |
| 202 | if (!_pendingQuery.isEmpty()) { |
| 203 | _searchField->setText(base::take(_pendingQuery)); |
| 204 | } |
| 205 | |
| 206 | return base::make_weak(not_null<Ui::RpWidget*>{ searchContainer }); |
| 207 | } |
| 208 |
nothing calls this directly
no test coverage detected