diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-16 00:33:33 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-16 13:57:55 +0530 |
| commit | 5a2a6aef3703d6aaaee24d9436da9e60ffcae769 (patch) | |
| tree | 565bfebbd41003c0e198739056d9178d279dfa6a /src | |
| parent | 387cf24e389854ecc97f6236fdd6acbc2486dd52 (diff) | |
| download | null-browser-5a2a6aef3703d6aaaee24d9436da9e60ffcae769.tar.gz null-browser-5a2a6aef3703d6aaaee24d9436da9e60ffcae769.zip | |
Fix UI issues with inputline and completer
Diffstat (limited to 'src')
| -rw-r--r-- | src/completion/Completer.cpp | 47 | ||||
| -rw-r--r-- | src/completion/FuzzySearchProxyModel.cpp | 3 | ||||
| -rw-r--r-- | src/widgets/InputLine.cpp | 32 | ||||
| -rw-r--r-- | src/widgets/MainWindow.cpp | 4 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 4 |
5 files changed, 51 insertions, 39 deletions
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 <QtCore/qnamespace.h> #include <QtCore/qsortfilterproxymodel.h> #include <QtCore> +#include <QtWidgets/qboxlayout.h> #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; diff --git a/src/widgets/InputLine.cpp b/src/widgets/InputLine.cpp index 7e0a2dd..81e2bab 100644 --- a/src/widgets/InputLine.cpp +++ b/src/widgets/InputLine.cpp @@ -8,9 +8,11 @@ #include <QWidget> #include <QWidgetAction> #include <QWindow> +#include <QtCore/qnamespace.h> #include <QtCore> #include <QtWidgets/qboxlayout.h> #include <QtWidgets/qlineedit.h> +#include <QtWidgets/qwidget.h> #include "completion/CommandsAdapter.hpp" #include "widgets/InputLine.hpp" @@ -24,53 +26,59 @@ const char *rootStyles = R"( const char *promptStyles = R"( background-color: #222; color: #fff; - padding: 0 2px; + padding: 0 4px; +)"; + +const char *inputStyles = R"( + color: #fff; + padding: 0 4px; )"; InputLine::InputLine(QString defaultInput, QWidget *parentNode) : QWidget(parentNode) { setContentsMargins(0, 0, 0, 0); - move(0, 0); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setStyleSheet(rootStyles); - auto layout = new QVBoxLayout(this); + layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); setLayout(layout); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); auto cmdLineBox = new QWidget(); - layout->addWidget(cmdLineBox); auto cmdLineLayout = new QHBoxLayout(); - cmdLineBox->setLayout(cmdLineLayout); - cmdLineBox->layout()->setContentsMargins(0, 0, 0, 0); - cmdLineBox->setContentsMargins(0, 0, 0, 0); + cmdLineLayout->setContentsMargins(0, 0, 0, 0); cmdLineLayout->setSpacing(0); + cmdLineBox->setLayout(cmdLineLayout); promptPrefix = new QLabel(); promptPrefix->setStyleSheet(promptStyles); promptPrefix->setContentsMargins(0, 0, 0, 0); input = new QLineEdit(defaultInput); + input->setStyleSheet(inputStyles); input->setFocusPolicy(Qt::StrongFocus); input->setContentsMargins(0, 0, 0, 0); cmdLineLayout->addWidget(promptPrefix); - cmdLineLayout->addWidget(input); + cmdLineLayout->addWidget(input, 1); cmdLineBox->setFixedHeight(input->sizeHint().height()); + layout->addWidget(cmdLineBox, 0); + setAdapter(new CommandsAdapter()); } void InputLine::setAdapter(Adapter *adapter) { if (this->adapterInstance) { - layout()->removeWidget(this->adapterInstance->completer()); + layout->removeWidget(this->adapterInstance->completer()); delete this->adapterInstance; } this->adapterInstance = adapter; promptPrefix->setText(adapter->prompt()); auto completer = adapter->completer(); - layout()->addWidget(completer); - completer->move(0, 0); + layout->insertWidget(1, completer, 0, Qt::AlignmentFlag::AlignTop); + connect(input, &QLineEdit::textChanged, completer, &Completer::onTextChange); connect(completer, &Completer::accepted, input, &QLineEdit::setText); } diff --git a/src/widgets/MainWindow.cpp b/src/widgets/MainWindow.cpp index 632869f..e2e54da 100644 --- a/src/widgets/MainWindow.cpp +++ b/src/widgets/MainWindow.cpp @@ -11,7 +11,7 @@ MainWindow::MainWindow() { setStyleSheet("background-color: #000; color: #fff;"); - setCentralWidget(new QWidget()); + setCentralWidget(new QWidget()); // TODO: manage widget memory // Root stacked layout auto layout = new QStackedLayout(); @@ -25,7 +25,7 @@ MainWindow::MainWindow() { layout->addWidget(webViewStack); // Command input - auto inputLine = new InputLine; + auto inputLine = new InputLine(); layout->addWidget(inputLine); inputMediator = diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 8102351..0d1f7fc 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -6,11 +6,9 @@ WebViewStack::WebViewStack(QWebEngineProfile *profile, QWidget *parent) : QWidget(parent), profile(profile) { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - layout = new QStackedLayout(this); - layout->setStackingMode(QStackedLayout::StackAll); layout->setContentsMargins(0, 0, 0, 0); + layout->setStackingMode(QStackedLayout::StackOne); createNewWebView(WebViewStack::NewtabURL, true); } |
