aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-16 00:33:33 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-16 13:57:55 +0530
commit5a2a6aef3703d6aaaee24d9436da9e60ffcae769 (patch)
tree565bfebbd41003c0e198739056d9178d279dfa6a
parent387cf24e389854ecc97f6236fdd6acbc2486dd52 (diff)
downloadnull-browser-5a2a6aef3703d6aaaee24d9436da9e60ffcae769.tar.gz
null-browser-5a2a6aef3703d6aaaee24d9436da9e60ffcae769.zip
Fix UI issues with inputline and completer
Diffstat (limited to '')
-rw-r--r--include/completion/Completer.hpp9
-rw-r--r--include/widgets/InputLine.hpp2
-rw-r--r--src/completion/Completer.cpp47
-rw-r--r--src/completion/FuzzySearchProxyModel.cpp3
-rw-r--r--src/widgets/InputLine.cpp32
-rw-r--r--src/widgets/MainWindow.cpp4
-rw-r--r--src/widgets/WebViewStack.cpp4
7 files changed, 59 insertions, 42 deletions
diff --git a/include/completion/Completer.hpp b/include/completion/Completer.hpp
index 9ad03d4..c1b77a6 100644
--- a/include/completion/Completer.hpp
+++ b/include/completion/Completer.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <QCompleter>
+#include <QHBoxLayout>
#include <QSortFilterProxyModel>
#include <QWidget>
#include <QtCore>
@@ -15,9 +16,9 @@ class Completer : public QWidget {
Q_OBJECT
public:
- Completer();
- void setSourceModel(QAbstractItemModel *model);
+ Completer(QWidget *parentNode = nullptr);
+ DELEGATE((&proxyModel), setSourceModel, setSourceModel)
DELEGATE((&proxyModel), sourceModel, sourceModel)
signals:
@@ -28,12 +29,14 @@ public slots:
bool onKeyPressEvent(QKeyEvent *event);
protected:
- void keyPressEvent(QKeyEvent *event) override { onKeyPressEvent(event); }
void setHighlightedRow(uint32_t);
void acceptHighlighted();
+ DELEGATE(this, onKeyPressEvent, keyPressEvent)
+
private:
QTreeView *view;
FuzzySearchProxyModel proxyModel;
CompleterDelegate *viewDelegate;
+ QHBoxLayout *layout;
};
diff --git a/include/widgets/InputLine.hpp b/include/widgets/InputLine.hpp
index 45aa559..d5f65be 100644
--- a/include/widgets/InputLine.hpp
+++ b/include/widgets/InputLine.hpp
@@ -14,6 +14,7 @@ class InputLine : public QWidget {
public:
InputLine(QString defaultInput = "", QWidget *parentNode = nullptr);
+
void setInputFocus(bool focussed);
bool isInputFocussed();
void setAdapter(Adapter *adapter);
@@ -37,4 +38,5 @@ private:
QLineEdit *input;
QLabel *promptPrefix;
Adapter *adapterInstance = nullptr;
+ QVBoxLayout *layout;
};
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);
}