-
Notifications
You must be signed in to change notification settings - Fork 38
/
filteringedit.cpp
75 lines (67 loc) · 1.8 KB
/
filteringedit.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "filteringedit.h"
#include <QDebug>
#include <QTimer>
FilteringEdit::FilteringEdit(QWidget *parent) :
QTextEdit(parent), m_allowSelectAll(false)
{
}
void FilteringEdit::keyPressEvent(QKeyEvent *e)
{
int key = e->key();
Qt::KeyboardModifiers m = e->modifiers();
const Qt::KeyboardModifiers generalMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier;
if (m == 0) {
if (key == Qt::Key_Up) {
emit prevEntry();
return;
}
if (key == Qt::Key_Down) {
emit nextEntry();
return;
}
if (key == Qt::Key_PageDown) {
emit nextPageOfEntries();
return;
}
if (key == Qt::Key_PageUp) {
emit prevPageOfEntries();
return;
}
}
if (key == Qt::Key_Return || key == Qt::Key_Enter) {
if (m == 0) {
emit selectedCurrentEntryWithText(this->toPlainText());
return;
}
if (m == Qt::ShiftModifier) {
if (m_allowSelectAll)
emit selectAllEntries();
else
emit shiftSelectCurrentEntry();
return;
}
if (m == Qt::ControlModifier) {
emit selectedCurrentText(this->toPlainText());
return;
}
if (m == Qt::ShiftModifier | Qt::ControlModifier) {
emit getCurrentEntryForEdit();
return;
}
}
if (m == Qt::ControlModifier) {
if (key == Qt::Key_Home) {
emit firstEntry();
return;
}
if (key == Qt::Key_End) {
emit lastEntry();
return;
}
}
QTextEdit::keyPressEvent(e);
}
void FilteringEdit::changeCurrentText(const QString&text)
{
this->setText(text);
}