API Documentation
Loading...
Searching...
No Matches
CommandLineEdit.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/QCustomLineEdit.h>
3#include <QCompleter>
4#include <QKeyEvent>
5namespace NDEVR
6{
8 {
9 CommandLineEdit(QWidget* parent = nullptr)
10 : QCustomLineEdit(parent)
11 , m_scroll_back_index(Constant<uint04>::NaN)
12 {
13
14 }
15 void setCompleter(QCompleter* completer)
16 {
17 if (c)
18 c->disconnect(this);
19
20 c = completer;
21
22 if (!c)
23 return;
24
25 c->setWidget(this);
26 c->setCompletionMode(QCompleter::PopupCompletion);
27 c->setCaseSensitivity(Qt::CaseInsensitive);
28 QObject::connect(c, QOverload<const QString&>::of(&QCompleter::activated),
29 this, &CommandLineEdit::insertCompletion);
30 }
31 protected:
32 void keyPressEvent(QKeyEvent* e) override
33 {
34 switch (e->key()) {
35 case Qt::Key_Enter:
36 case Qt::Key_Return:
37 case Qt::Key_Escape:
38 case Qt::Key_Tab:
39 case Qt::Key_Backtab:
40 e->ignore();
41 return; // let the completer do default behavior
42 default:
43 break;
44 }
45 }
46
47 void focusInEvent(QFocusEvent* e) override
48 {
49 if (c)
50 c->setWidget(this);
52 }
53
54 private slots:
55 void insertCompletion(const QString& completion)
56 {
57 if (c->widget() != this)
58 return;
59
60 }
61 private:
62 QString textUnderCursor() const;
63
64 private:
65 QCompleter* c = nullptr;
66 Buffer<String> m_last_commands;
67 uint04 m_scroll_back_index;
68 };
69}
Definition CommandLineEdit.h:8
void focusInEvent(QFocusEvent *e) override
Definition CommandLineEdit.h:47
void keyPressEvent(QKeyEvent *e) override
Definition CommandLineEdit.h:32
Definition QCustomLineEdit.h:118
virtual void focusInEvent(QFocusEvent *e) override
Definition QCustomLineEdit.cpp:525
QCustomLineEdit(QWidget *parent=Q_NULLPTR)
Definition QCustomLineEdit.cpp:17
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
Definition BaseValues.hpp:272