aboutsummaryrefslogtreecommitdiff
path: root/src/completion/Completer.cpp
blob: 96a363e066a169da3753397ab639563fe97757f6 (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
#include <QAbstractItemView>
#include <QHeaderView>
#include <QLineEdit>
#include <QTreeView>
#include <QWidget>
#include <QtCore>

#include "completion/Completer.hpp"
#include "completion/CompleterDelegate.hpp"

const char *completerStyles = R"(
  background-color: #111;
  color: #fff;
  border-radius: 0;
)";

Completer::Completer(QObject *parent) : QCompleter(parent) {
  setFilterMode(Qt::MatchContains);
  setCaseSensitivity(Qt::CaseInsensitive);
  setCompletionRole(Qt::DisplayRole);
  setCompletionMode(QCompleter::PopupCompletion);

  auto treeView = new QTreeView();
  setPopup(treeView);
  treeView->setStyleSheet(completerStyles);
  treeView->setItemDelegate(new CompleterDelegate(treeView));
  treeView->setRootIsDecorated(false);
  treeView->setUniformRowHeights(true);
  treeView->header()->hide();
  treeView->setColumnWidth(1, 160);

  complete();
}

// bool Completer::eventFilter(QObject *watched, QEvent *event) {
//   auto isFocusIn = event->type() == QEvent::FocusIn;
//   auto isKeyRelease = event->type() == QEvent::KeyRelease;
//
//   QLineEdit *lineEdit = qobject_cast<QLineEdit *>(watched);
//   bool isInputEmpty = lineEdit && lineEdit->text().isEmpty();
//
//   if ((isFocusIn || isKeyRelease) && isInputEmpty)
//     complete();
//
//   return QCompleter::eventFilter(watched, event);
// }