aboutsummaryrefslogtreecommitdiff
path: root/include/completion/Completer.hpp
blob: c1b77a6332e8a19bc327927505cdc1b4a0aa1c4c (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 <QCompleter>
#include <QHBoxLayout>
#include <QSortFilterProxyModel>
#include <QWidget>
#include <QtCore>
#include <QtWidgets/qtreeview.h>
#include <cstdint>

#include "completion/CompleterDelegate.hpp"
#include "completion/FuzzySearchProxyModel.hpp"
#include "utils.hpp"

class Completer : public QWidget {
  Q_OBJECT

public:
  Completer(QWidget *parentNode = nullptr);

  DELEGATE((&proxyModel), setSourceModel, setSourceModel)
  DELEGATE((&proxyModel), sourceModel, sourceModel)

signals:
  void accepted(QString text);

public slots:
  void onTextChange(QString text);
  bool onKeyPressEvent(QKeyEvent *event);

protected:
  void setHighlightedRow(uint32_t);
  void acceptHighlighted();

  DELEGATE(this, onKeyPressEvent, keyPressEvent)

private:
  QTreeView *view;
  FuzzySearchProxyModel proxyModel;
  CompleterDelegate *viewDelegate;
  QHBoxLayout *layout;
};