aboutsummaryrefslogtreecommitdiff
path: root/include/completion
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-10 22:04:24 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-10 22:13:15 +0530
commit971854bfefad4c644ac3d5f5d6003f24d551bf1d (patch)
tree0f5ee90fd5968d345b157d38964094837315edf0 /include/completion
parentd400369084107104f51fe217d5781c8d7bd07ff9 (diff)
downloadnull-browser-971854bfefad4c644ac3d5f5d6003f24d551bf1d.tar.gz
null-browser-971854bfefad4c644ac3d5f5d6003f24d551bf1d.zip
Add completer + simplify command parsing + class generator
Diffstat (limited to 'include/completion')
-rw-r--r--include/completion/CommandsModel.hpp32
-rw-r--r--include/completion/Completer.hpp14
-rw-r--r--include/completion/CompleterDelegate.hpp15
3 files changed, 61 insertions, 0 deletions
diff --git a/include/completion/CommandsModel.hpp b/include/completion/CommandsModel.hpp
new file mode 100644
index 0000000..6cb25f9
--- /dev/null
+++ b/include/completion/CommandsModel.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include <QWidget>
+#include <QtCore>
+
+struct Command {
+ QString name;
+ QString description;
+};
+
+const QList<Command> commands = {
+ {.name = "open", .description = "Open a url in the current tab"},
+ {.name = "tabopen", .description = "Open a url in a new tab"},
+ {.name = "bnext", .description = "Go to next tab"},
+ {.name = "bprev", .description = "Go to previous tab"},
+};
+
+class CommandsModel : public QAbstractListModel {
+ Q_OBJECT
+
+public:
+ CommandsModel(QObject *parent = nullptr);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ QHash<int, QByteArray> roleNames() const override;
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override;
+
+private:
+ QList<Command> items;
+};
diff --git a/include/completion/Completer.hpp b/include/completion/Completer.hpp
new file mode 100644
index 0000000..b67de61
--- /dev/null
+++ b/include/completion/Completer.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <QCompleter>
+#include <QWidget>
+#include <QtCore>
+
+class Completer : public QCompleter {
+ Q_OBJECT
+
+public:
+ Completer(QObject *parent = nullptr);
+
+ // bool eventFilter(QObject *watched, QEvent *event) override;
+};
diff --git a/include/completion/CompleterDelegate.hpp b/include/completion/CompleterDelegate.hpp
new file mode 100644
index 0000000..fc7a321
--- /dev/null
+++ b/include/completion/CompleterDelegate.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <QStyledItemDelegate>
+#include <QWidget>
+#include <QtCore>
+
+class CompleterDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+
+public:
+ explicit CompleterDelegate(QObject *parent = nullptr);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};