aboutsummaryrefslogtreecommitdiff
path: root/include/widgets/InputLine.hpp
blob: d5f65bed841cbd25525cce61051cb852009e5730 (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
#pragma once

#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QWidget>
#include <QtCore>

#include "completion/Adapter.hpp"
#include "utils.hpp"

class InputLine : public QWidget {
  Q_OBJECT

public:
  InputLine(QString defaultInput = "", QWidget *parentNode = nullptr);

  void setInputFocus(bool focussed);
  bool isInputFocussed();
  void setAdapter(Adapter *adapter);

  DELEGATE(input, hasFocus, isInputFocussed)
  DELEGATE(input, setText, setInputText)
  DELEGATE(input, text, getInputText)
  DELEGATE(promptPrefix, text, prompt)

  // bool eventFilter(QObject *obj, QEvent *event) override;

signals:
  void submitted(QString text);
  void cancelled();

protected:
  void keyPressEvent(QKeyEvent *event) override;
  void emitSubmit();

private:
  QLineEdit *input;
  QLabel *promptPrefix;
  Adapter *adapterInstance = nullptr;
  QVBoxLayout *layout;
};