From 5a2a6aef3703d6aaaee24d9436da9e60ffcae769 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 16 Mar 2025 00:33:33 +0530 Subject: Fix UI issues with inputline and completer --- src/completion/Completer.cpp | 47 +++++++++++++++++++------------- src/completion/FuzzySearchProxyModel.cpp | 3 -- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src/completion') diff --git a/src/completion/Completer.cpp b/src/completion/Completer.cpp index 27a7b77..95d1dde 100644 --- a/src/completion/Completer.cpp +++ b/src/completion/Completer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "completion/Completer.hpp" #include "completion/CompleterDelegate.hpp" @@ -17,43 +18,46 @@ const char *completerStyles = R"( background-color: #111; color: #fff; border-radius: 0; - width: 100%; )"; -Completer::Completer() : QWidget() { - view = new QTreeView(this); +Completer::Completer(QWidget *parentNode) : QWidget(parentNode) { + layout = new QHBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + setLayout(layout); + setStyleSheet(completerStyles); + setContentsMargins(0, 0, 0, 0); + + view = new QTreeView(); + layout->addWidget(view, 0); viewDelegate = new CompleterDelegate(view); - view->setStyleSheet(completerStyles); view->setItemDelegate(viewDelegate); view->setRootIsDecorated(false); view->setUniformRowHeights(true); view->header()->hide(); - view->setColumnWidth(1, 500); + view->setColumnWidth(0, 500); view->setModel(&proxyModel); view->setFocusPolicy(Qt::NoFocus); - view->setEditTriggers(QAbstractItemView::NoEditTriggers); view->setSelectionMode(QAbstractItemView::SingleSelection); -} - -void Completer::setSourceModel(QAbstractItemModel *model) { - proxyModel.setSourceModel(model); -} - -void Completer::onTextChange(QString text) { - proxyModel.setFilterWildcard(text); -} - -void Completer::setHighlightedRow(uint32_t row) { - viewDelegate->setCurrentRow(row); - view->update(); + view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); + view->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } void Completer::acceptHighlighted() { auto index = proxyModel.index(viewDelegate->currentRow(), 0); auto text = proxyModel.data(index, Qt::DisplayRole).toString(); + setHighlightedRow(0); emit accepted(text); } +void Completer::onTextChange(QString text) { + setHighlightedRow(0); + proxyModel.setFilterWildcard(text); +} + bool Completer::onKeyPressEvent(QKeyEvent *event) { auto combo = event->keyCombination(); auto row = viewDelegate->currentRow(); @@ -84,3 +88,8 @@ bool Completer::onKeyPressEvent(QKeyEvent *event) { return false; } + +void Completer::setHighlightedRow(uint32_t row) { + viewDelegate->setCurrentRow(row); + view->update(); +} diff --git a/src/completion/FuzzySearchProxyModel.cpp b/src/completion/FuzzySearchProxyModel.cpp index 151f60e..0c467c6 100644 --- a/src/completion/FuzzySearchProxyModel.cpp +++ b/src/completion/FuzzySearchProxyModel.cpp @@ -7,14 +7,11 @@ bool FuzzySearchProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const { QAbstractItemModel *model = sourceModel(); QString filterText = filterRegularExpression().pattern(); - qDebug() << "Searching: " << filterText; for (int col = 0; col < model->columnCount(); ++col) { QModelIndex index = model->index(sourceRow, col, sourceParent); QString data = model->data(index, Qt::AccessibleDescriptionRole).toString(); - qDebug() << " against: " << data; - // TODO: Fuzzy eet up if (data.contains(filterText, Qt::CaseInsensitive)) { return true; -- cgit v1.3.1