diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/InputMediator.hpp | 60 | ||||
| -rw-r--r-- | include/completion/CommandsModel.hpp | 4 | ||||
| -rw-r--r-- | include/utils.hpp | 5 | ||||
| -rw-r--r-- | include/widgets/InputLine.hpp | 11 | ||||
| -rw-r--r-- | include/widgets/MainWindow.hpp | 39 |
5 files changed, 76 insertions, 43 deletions
diff --git a/include/InputMediator.hpp b/include/InputMediator.hpp new file mode 100644 index 0000000..660d39f --- /dev/null +++ b/include/InputMediator.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include <QWidget> +#include <QtCore> + +#include "LuaRuntime.hpp" +#include "utils.hpp" +#include "widgets/InputLine.hpp" +#include "widgets/WebViewStack.hpp" + +class EvaluationType { +public: + EvaluationType() {} + virtual ~EvaluationType() = default; +}; +class NoopEval : public EvaluationType {}; + +class InputMediator : public QObject { + Q_OBJECT + +public: + InputMediator(InputLine *inputLine, WebViewStack *webViewStack, + LuaRuntime *luaRuntime); + + void showURLInput(QString url = "", OpenType openType = OpenType::OpenUrl); + void showCommandInput(QString command = ""); + void hideInputLine(); + + DELEGATE(webViewStack, openUrl, openUrl) + DELEGATE(webViewStack, currentUrl, currentUrl) + DELEGATE(webViewStack, next, nextWebView) + DELEGATE(webViewStack, previous, previousWebView) + DELEGATE(webViewStack, closeCurrent, closeCurrentWebView) + DELEGATE(inputLine, getInputText, getInputText) + +private: + void showInputLine(); + void evaluateCommand(QString command); + void setEvaluationType(EvaluationType *); + +private slots: + void onInputSubmit(QString input); + +private: + InputLine *inputLine; + WebViewStack *webViewStack; + LuaRuntime *luaRuntime; + EvaluationType *currentEvaluationType = new NoopEval(); +}; + +class UrlEval : public EvaluationType { +public: + UrlEval(OpenType type) : EvaluationType(), openType(type) {} + OpenType type() { return openType; } + +private: + OpenType openType; +}; + +class CommandEval : public EvaluationType {}; diff --git a/include/completion/CommandsModel.hpp b/include/completion/CommandsModel.hpp index 6cb25f9..28836fe 100644 --- a/include/completion/CommandsModel.hpp +++ b/include/completion/CommandsModel.hpp @@ -12,8 +12,8 @@ struct Command { 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"}, + {.name = "tabnext", .description = "Go to next tab"}, + {.name = "tabbprev", .description = "Go to previous tab"}, }; class CommandsModel : public QAbstractListModel { diff --git a/include/utils.hpp b/include/utils.hpp new file mode 100644 index 0000000..65667f7 --- /dev/null +++ b/include/utils.hpp @@ -0,0 +1,5 @@ + +#define DELEGATE(OBJ, METHOD, METHOD_AS) \ + template <typename... Args> decltype(auto) METHOD_AS(Args &&...args) { \ + return OBJ->METHOD(std::forward<Args>(args)...); \ + } diff --git a/include/widgets/InputLine.hpp b/include/widgets/InputLine.hpp index 1d98c9a..07b6e92 100644 --- a/include/widgets/InputLine.hpp +++ b/include/widgets/InputLine.hpp @@ -7,6 +7,7 @@ #include <QtCore> #include "completion/Adapter.hpp" +#include "utils.hpp" class InputLine : public QWidget { Q_OBJECT @@ -15,13 +16,15 @@ public: InputLine(QString defaultInput = "", QWidget *parentNode = nullptr); void setInputFocus(bool focussed); bool isInputFocussed(); - QString getInputCommand(); - void setInputText(QString text); void setAdapter(Adapter *adapter); - Adapter *adapter(); + + DELEGATE(input, hasFocus, isInputFocussed) + DELEGATE(input, setText, setInputText) + DELEGATE(input, text, getInputText) + DELEGATE(adapterInstance, prompt, prompt) signals: - void submitted(QString command); + void submitted(QString text); void cancelled(); protected: diff --git a/include/widgets/MainWindow.hpp b/include/widgets/MainWindow.hpp index 99a3895..f77ed60 100644 --- a/include/widgets/MainWindow.hpp +++ b/include/widgets/MainWindow.hpp @@ -5,16 +5,7 @@ #include <QStackedLayout> #include <QWebEngineView> -#include "LuaRuntime.hpp" -#include "widgets/InputLine.hpp" -#include "widgets/WebViewStack.hpp" - -class EvaluationType { -public: - EvaluationType() {} - virtual ~EvaluationType() = default; -}; -class NoopEval : public EvaluationType {}; +#include "InputMediator.hpp" class MainWindow : public QMainWindow { public: @@ -22,33 +13,7 @@ public: private: void keyPressEvent(QKeyEvent *event) override; - void onInputSubmit(QString input); - - void evaluateCommand(QString command); - - void hideInputLine(); - void showInputLine(); - void showURLInput(QString url, OpenType openType); - void showCommandInput(QString command = ""); - - void setEvaluationType(EvaluationType *); private: - WebViewStack *webViewStack; - InputLine *inputLine; - LuaRuntime *luaRuntime; - QStackedLayout *layout; - - EvaluationType *currentEvaluationType = new NoopEval(); + InputMediator *inputMediator; }; - -class UrlEval : public EvaluationType { -public: - UrlEval(OpenType type) : EvaluationType(), openType(type) {} - OpenType type() { return openType; } - -private: - OpenType openType; -}; - -class CommandEval : public EvaluationType {}; |
