mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
UI/Qt: Migrate to LibWebView's autocomplete engine
As a result, we now no longer depend on Qt::Network.
This commit is contained in:
parent
a87c264088
commit
60dd5cc4ef
Notes:
github-actions[bot]
2025-04-02 12:53:43 +00:00
Author: https://github.com/trflynn89
Commit: 60dd5cc4ef
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4156
13 changed files with 100 additions and 371 deletions
43
UI/Qt/Autocomplete.cpp
Normal file
43
UI/Qt/Autocomplete.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWebView/Autocomplete.h>
|
||||
#include <UI/Qt/Autocomplete.h>
|
||||
#include <UI/Qt/StringUtils.h>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
Autocomplete::Autocomplete(QWidget* parent)
|
||||
: QCompleter(parent)
|
||||
, m_autocomplete(make<WebView::Autocomplete>())
|
||||
, m_model(new QStringListModel(this))
|
||||
, m_popup(new QListView(parent))
|
||||
{
|
||||
m_autocomplete->on_autocomplete_query_complete = [this](auto const& suggestions) {
|
||||
if (suggestions.is_empty()) {
|
||||
m_model->setStringList({});
|
||||
} else {
|
||||
QStringList list;
|
||||
for (auto const& suggestion : suggestions)
|
||||
list.append(qstring_from_ak_string(suggestion));
|
||||
|
||||
m_model->setStringList(list);
|
||||
complete();
|
||||
}
|
||||
};
|
||||
|
||||
setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
||||
setModel(m_model);
|
||||
setPopup(m_popup);
|
||||
}
|
||||
|
||||
void Autocomplete::query_autocomplete_engine(String search_string)
|
||||
{
|
||||
m_autocomplete->query_autocomplete_engine(move(search_string));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue