aboutsummaryrefslogtreecommitdiff
path: root/include/InputMediator.hpp
blob: 660d39f3005a5ee238fefe89b0620051d71e3ffe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 {};