2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
12 #include "histlineedit.h"
14 HistLineEdit::HistLineEdit(QWidget
* parent
)
18 connect(this, SIGNAL(returnPressed()), this, SLOT(updateHistory()));
21 void HistLineEdit::keyPressEvent(QKeyEvent
* e
) {
22 if (echoMode() == Password
) {
24 QLineEdit::keyPressEvent(e
);
28 if (e
->key() == Qt::Key_Up
) {
30 setHistoryText(current
-1);
32 else if (e
->key() == Qt::Key_Down
) {
33 if (current
< history
.size())
34 setHistoryText(current
+1);
36 else if (e
->key() == Qt::Key_PageUp
)
38 else if (e
->key() == Qt::Key_PageDown
)
42 QLineEdit::keyPressEvent(e
);
45 void HistLineEdit::setHistoryText(uint index
) {
46 if (current
== history
.size())
49 if (index
== history
.size())
52 setText(history
[index
]);
57 void HistLineEdit::updateHistory() {
58 if (echoMode() != Password
) {
60 history
.push_back(text());
62 current
= history
.size();
65 receivedInput(text());