39 |
39 |
case Qt::Key_Up:
|
40 |
40 |
event->accept();
|
41 |
41 |
|
42 |
|
if(addToHistory(text())) {
|
43 |
|
clear();
|
44 |
|
break;
|
45 |
|
}
|
|
42 |
addToHistory(text(), true);
|
46 |
43 |
|
47 |
44 |
if(idx > 0) {
|
48 |
45 |
idx--;
|
49 |
|
setText(history[idx]);
|
|
46 |
showHistoryEntry();
|
50 |
47 |
}
|
51 |
48 |
|
52 |
49 |
break;
|
... | ... | |
54 |
51 |
case Qt::Key_Down:
|
55 |
52 |
event->accept();
|
56 |
53 |
|
57 |
|
if(addToHistory(text())) {
|
58 |
|
clear();
|
59 |
|
break;
|
60 |
|
}
|
|
54 |
addToHistory(text(), true);
|
61 |
55 |
|
62 |
|
if(idx < history.count())
|
|
56 |
if(idx < history.count()) {
|
63 |
57 |
idx++;
|
64 |
|
|
65 |
|
if(idx < history.count())
|
66 |
|
setText(history[idx]);
|
67 |
|
else
|
68 |
|
clear();
|
|
58 |
if(idx < history.count() || tempHistory.contains(idx)) // tempHistory might have an entry for idx == history.count() + 1
|
|
59 |
showHistoryEntry();
|
|
60 |
else
|
|
61 |
resetLine(); // equals clear() in this case
|
|
62 |
} else {
|
|
63 |
addToHistory(text());
|
|
64 |
resetLine();
|
|
65 |
}
|
69 |
66 |
|
70 |
67 |
break;
|
71 |
68 |
|
... | ... | |
77 |
74 |
}
|
78 |
75 |
}
|
79 |
76 |
|
80 |
|
bool InputLine::addToHistory(const QString &text) {
|
|
77 |
bool InputLine::addToHistory(const QString &text, bool temporary) {
|
81 |
78 |
if(text.isEmpty())
|
82 |
79 |
return false;
|
83 |
80 |
|
84 |
81 |
Q_ASSERT(0 <= idx && idx <= history.count());
|
85 |
82 |
|
86 |
83 |
if(history.isEmpty() || text != history[idx - (int)(idx == history.count())]) {
|
87 |
|
// if we change an entry of the history the changed entry is appended to the list and we seek to the end
|
88 |
|
// we could also easily change the entry in the history... per setting maybe?
|
89 |
|
history << text;
|
90 |
|
idx = history.count();
|
|
84 |
// if an entry of the history is changed, we remember it and show it again at this
|
|
85 |
// position until a line was actually sent
|
|
86 |
// sent lines get appended to the history
|
|
87 |
if(temporary) {
|
|
88 |
tempHistory[idx] = text;
|
|
89 |
} else {
|
|
90 |
history << text;
|
|
91 |
tempHistory.clear();
|
|
92 |
}
|
91 |
93 |
return true;
|
92 |
94 |
} else {
|
93 |
95 |
return false;
|
... | ... | |
97 |
99 |
void InputLine::on_returnPressed() {
|
98 |
100 |
addToHistory(text());
|
99 |
101 |
emit sendText(text());
|
100 |
|
clear();
|
|
102 |
resetLine();
|
101 |
103 |
}
|
102 |
104 |
|
103 |
105 |
void InputLine::on_textChanged(QString newText) {
|
... | ... | |
125 |
127 |
emit returnPressed();
|
126 |
128 |
insert(remainder);
|
127 |
129 |
}
|
128 |
|
|
129 |
130 |
}
|
130 |
131 |
|
|
132 |
void InputLine::resetLine() {
|
|
133 |
// every time the InputLine is cleared we also reset history index
|
|
134 |
idx = history.count();
|
|
135 |
clear();
|
|
136 |
}
|
|
137 |
|
|
138 |
void InputLine::showHistoryEntry() {
|
|
139 |
// if the user changed the history, display the changed line
|
|
140 |
tempHistory.contains(idx) ? setText(tempHistory[idx]) : setText(history[idx]);
|
|
141 |
}
|