aboutsummaryrefslogtreecommitdiff
path: root/src/completion
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-18 21:19:28 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-18 21:19:47 +0530
commit4c762b2516bc664293c2aec072074f1e34dda8c3 (patch)
treeebe441f7af8c1f4c49f04630538312d55f18f63b /src/completion
parent056b0b16947ac19a0c425aa9d2ff8f589378d3bc (diff)
downloadnull-browser-4c762b2516bc664293c2aec072074f1e34dda8c3.tar.gz
null-browser-4c762b2516bc664293c2aec072074f1e34dda8c3.zip
Remove all the ui bits because screw it, lets unix a bit more
Diffstat (limited to '')
-rw-r--r--src/completion/CommandsAdapter.cpp22
-rw-r--r--src/completion/CommandsModel.cpp43
-rw-r--r--src/completion/Completer.cpp95
-rw-r--r--src/completion/CompleterDelegate.cpp46
-rw-r--r--src/completion/FuzzySearchProxyModel.cpp21
-rw-r--r--src/completion/TabsAdapter.cpp20
-rw-r--r--src/completion/TabsModel.cpp42
-rw-r--r--src/completion/UrlAdapter.cpp20
-rw-r--r--src/completion/UrlModel.cpp50
9 files changed, 0 insertions, 359 deletions
diff --git a/src/completion/CommandsAdapter.cpp b/src/completion/CommandsAdapter.cpp
deleted file mode 100644
index 020c115..0000000
--- a/src/completion/CommandsAdapter.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/CommandsAdapter.hpp"
-#include "completion/CommandsModel.hpp"
-#include "completion/Completer.hpp"
-
-const QString cmdPrompt = "[exec]";
-
-CommandsAdapter::CommandsAdapter() : Adapter() {
- completerInstance = new Completer();
- completerInstance->setSourceModel(new CommandsModel(this));
-}
-
-Completer *CommandsAdapter::completer() { return completerInstance; }
-
-QString CommandsAdapter::prompt() { return cmdPrompt; }
-
-CommandsAdapter::~CommandsAdapter() {
- delete completerInstance->sourceModel();
- delete completerInstance;
-}
diff --git a/src/completion/CommandsModel.cpp b/src/completion/CommandsModel.cpp
deleted file mode 100644
index 670c0e8..0000000
--- a/src/completion/CommandsModel.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <QAbstractListModel>
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/CommandsModel.hpp"
-
-CommandsModel::CommandsModel(QObject *parent) : QAbstractListModel(parent) {
- items = commands;
-}
-
-QVariant CommandsModel::data(const QModelIndex &index, int role) const {
- if (!index.isValid() || index.row() >= items.size())
- return QVariant();
-
- const Command &item = items.at(index.row());
-
- if (role == Qt::DisplayRole)
- return item.name;
- else if (role == Qt::UserRole)
- return item.description;
- else if (role == Qt::AccessibleDescriptionRole)
- return item.name + item.description;
-
- return QVariant();
-}
-
-QHash<int, QByteArray> CommandsModel::roleNames() const {
- QHash<int, QByteArray> roles;
- roles[Qt::DisplayRole] = "name";
- roles[Qt::UserRole] = "description";
- roles[Qt::AccessibleDescriptionRole] = "full";
- return roles;
-}
-
-int CommandsModel::rowCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return items.size();
-}
-
-int CommandsModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return 2; // name + description
-}
diff --git a/src/completion/Completer.cpp b/src/completion/Completer.cpp
deleted file mode 100644
index 95d1dde..0000000
--- a/src/completion/Completer.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#include <QAbstractItemView>
-#include <QHeaderView>
-#include <QKeyEvent>
-#include <QLineEdit>
-#include <QTreeView>
-#include <QWidget>
-#include <QtCore/qabstractitemmodel.h>
-#include <QtCore/qitemselectionmodel.h>
-#include <QtCore/qnamespace.h>
-#include <QtCore/qsortfilterproxymodel.h>
-#include <QtCore>
-#include <QtWidgets/qboxlayout.h>
-
-#include "completion/Completer.hpp"
-#include "completion/CompleterDelegate.hpp"
-
-const char *completerStyles = R"(
- background-color: #111;
- color: #fff;
- border-radius: 0;
-)";
-
-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->setItemDelegate(viewDelegate);
- view->setRootIsDecorated(false);
- view->setUniformRowHeights(true);
- view->header()->hide();
- view->setColumnWidth(0, 500);
- view->setModel(&proxyModel);
- view->setFocusPolicy(Qt::NoFocus);
- view->setSelectionMode(QAbstractItemView::SingleSelection);
- 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();
-
- // If there are no matches, nothing to handle here
- if (proxyModel.rowCount() == 0)
- return false;
-
- if (combo.key() == Qt::Key_Up) {
- setHighlightedRow(row <= 0 ? proxyModel.rowCount() - 1 : row - 1);
- return true;
- }
-
- if (combo.key() == Qt::Key_Down) {
- setHighlightedRow((row + 1) % proxyModel.rowCount());
- return true;
- }
-
- if (combo.key() == Qt::Key_Tab) {
- acceptHighlighted();
- return true;
- }
-
- if (combo.key() == Qt::Key_Return) {
- acceptHighlighted();
- return false;
- }
-
- return false;
-}
-
-void Completer::setHighlightedRow(uint32_t row) {
- viewDelegate->setCurrentRow(row);
- view->update();
-}
diff --git a/src/completion/CompleterDelegate.cpp b/src/completion/CompleterDelegate.cpp
deleted file mode 100644
index ce446b2..0000000
--- a/src/completion/CompleterDelegate.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <QPainter>
-#include <QWidget>
-#include <QtCore/qlogging.h>
-#include <QtCore/qnamespace.h>
-#include <QtCore>
-
-#include "completion/CompleterDelegate.hpp"
-
-CompleterDelegate::CompleterDelegate(QObject *parent)
- : QStyledItemDelegate(parent) {}
-
-void CompleterDelegate::setCurrentRow(uint32_t r) { row = r; }
-
-uint32_t CompleterDelegate::currentRow() { return row; }
-
-void CompleterDelegate::paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const {
- painter->save();
-
- bool selected = index.row() == row;
-
- // Style
- if (selected) {
- painter->fillRect(option.rect, QColor("#aaa"));
- painter->setPen(Qt::black);
- } else {
- painter->fillRect(option.rect, QColor("#111"));
- painter->setPen(Qt::white);
- }
-
- // Draw text
- QString text;
- QRect rect;
- if (index.column() == 0) {
- text = index.data(Qt::DisplayRole).toString();
- rect = option.rect.adjusted(5, 0, 0, 0);
- painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, text);
- } else if (index.column() == 1) {
- text = index.data(Qt::UserRole).toString();
- rect = option.rect.adjusted(0, 0, -5, 0);
- painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, text);
- }
-
- painter->restore();
-}
diff --git a/src/completion/FuzzySearchProxyModel.cpp b/src/completion/FuzzySearchProxyModel.cpp
deleted file mode 100644
index 0c467c6..0000000
--- a/src/completion/FuzzySearchProxyModel.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/FuzzySearchProxyModel.hpp"
-
-bool FuzzySearchProxyModel::filterAcceptsRow(
- int sourceRow, const QModelIndex &sourceParent) const {
- QAbstractItemModel *model = sourceModel();
- QString filterText = filterRegularExpression().pattern();
-
- for (int col = 0; col < model->columnCount(); ++col) {
- QModelIndex index = model->index(sourceRow, col, sourceParent);
- QString data = model->data(index, Qt::AccessibleDescriptionRole).toString();
-
- // TODO: Fuzzy eet up
- if (data.contains(filterText, Qt::CaseInsensitive)) {
- return true;
- }
- }
- return false;
-}
diff --git a/src/completion/TabsAdapter.cpp b/src/completion/TabsAdapter.cpp
deleted file mode 100644
index d669151..0000000
--- a/src/completion/TabsAdapter.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/Completer.hpp"
-#include "completion/TabsAdapter.hpp"
-#include "completion/TabsModel.hpp"
-
-TabsAdapter::TabsAdapter(QList<Tab> tabs) : Adapter() {
- completerInstance = new Completer();
- completerInstance->setSourceModel(new TabsModel(tabs, this));
-}
-
-Completer *TabsAdapter::completer() { return completerInstance; }
-
-QString TabsAdapter::prompt() { return "[tabs]"; }
-
-TabsAdapter::~TabsAdapter() {
- delete completerInstance->sourceModel();
- delete completerInstance;
-}
diff --git a/src/completion/TabsModel.cpp b/src/completion/TabsModel.cpp
deleted file mode 100644
index 6d14b30..0000000
--- a/src/completion/TabsModel.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <QAbstractListModel>
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/TabsModel.hpp"
-
-TabsModel::TabsModel(QList<Tab> tabs, QObject *parent)
- : QAbstractListModel(parent), items(tabs) {}
-
-QVariant TabsModel::data(const QModelIndex &index, int role) const {
- if (!index.isValid() || index.row() >= items.size())
- return QVariant();
-
- const Tab &item = items.at(index.row());
-
- if (role == Qt::DisplayRole)
- return index.row();
- else if (role == Qt::UserRole)
- return item.title;
- else if (role == Qt::AccessibleDescriptionRole)
- return item.url + item.title;
-
- return QVariant();
-}
-
-QHash<int, QByteArray> TabsModel::roleNames() const {
- QHash<int, QByteArray> roles;
- roles[Qt::DisplayRole] = "url";
- roles[Qt::UserRole] = "title";
- roles[Qt::AccessibleDescriptionRole] = "full";
- return roles;
-}
-
-int TabsModel::rowCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return items.size();
-}
-
-int TabsModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return 2; // url + title
-}
diff --git a/src/completion/UrlAdapter.cpp b/src/completion/UrlAdapter.cpp
deleted file mode 100644
index 54caa0d..0000000
--- a/src/completion/UrlAdapter.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <QWidget>
-#include <QtCore>
-
-#include "completion/Completer.hpp"
-#include "completion/UrlAdapter.hpp"
-#include "completion/UrlModel.hpp"
-
-UrlAdapter::UrlAdapter() : Adapter() {
- completerInstance = new Completer();
- completerInstance->setSourceModel(new UrlModel(this));
-}
-
-Completer *UrlAdapter::completer() { return completerInstance; }
-
-QString UrlAdapter::prompt() { return "[url]"; }
-
-UrlAdapter::~UrlAdapter() {
- delete completerInstance->sourceModel();
- delete completerInstance;
-}
diff --git a/src/completion/UrlModel.cpp b/src/completion/UrlModel.cpp
deleted file mode 100644
index 8c5d75c..0000000
--- a/src/completion/UrlModel.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <QAbstractListModel>
-#include <QWidget>
-#include <QtCore/qnamespace.h>
-#include <QtCore>
-
-#include "completion/UrlModel.hpp"
-
-UrlModel::UrlModel(QObject *parent) : QAbstractListModel(parent) {
- items = {
- {.url = "https://google.com", .description = "Google"},
- {.url = "https://duckduckgo.com", .description = "DuckDuckGo"},
- {.url = "https://ediblemonad.dev", .description = "EdibleMonad website"},
- {.url = "https://lite.duckduckgo.com", .description = "DDG lite"},
- {.url = "https://github.com/trending", .description = "Github trending"},
- };
-}
-
-QVariant UrlModel::data(const QModelIndex &index, int role) const {
- if (!index.isValid() || index.row() >= items.size())
- return QVariant();
-
- const Url &item = items.at(index.row());
-
- if (role == Qt::DisplayRole)
- return item.url;
- else if (role == Qt::UserRole)
- return item.description;
- else if (role == Qt::AccessibleDescriptionRole)
- return item.url + " " + item.description;
-
- return QVariant();
-}
-
-QHash<int, QByteArray> UrlModel::roleNames() const {
- QHash<int, QByteArray> roles;
- roles[Qt::DisplayRole] = "url";
- roles[Qt::UserRole] = "description";
- roles[Qt::AccessibleDescriptionRole] = "full";
- return roles;
-}
-
-int UrlModel::rowCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return items.size();
-}
-
-int UrlModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
- return 2; // url + description
-}