Moved global.* to mastersettings.*, and converted many error messages to use the...
[tagua/yd.git] / src / histlineedit.cpp
blobc7108d62ad4926485160398fc36635dbbd6b94cd
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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.
9 */
11 #include <QKeyEvent>
12 #include "histlineedit.h"
14 HistLineEdit::HistLineEdit(QWidget* parent)
15 : QLineEdit(parent) {
16 current = 0;
18 connect(this, SIGNAL(returnPressed()), this, SLOT(updateHistory()));
21 void HistLineEdit::keyPressEvent(QKeyEvent* e) {
22 if (echoMode() == Password) {
23 e->ignore();
24 QLineEdit::keyPressEvent(e);
25 return;
28 if (e->key() == Qt::Key_Up) {
29 if (current > 0)
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)
37 emit pageUp();
38 else if (e->key() == Qt::Key_PageDown)
39 emit pageDown();
40 else e->ignore();
42 QLineEdit::keyPressEvent(e);
45 void HistLineEdit::setHistoryText(uint index) {
46 if (current == history.size())
47 buffer = text();
49 if (index == history.size())
50 setText(buffer);
51 else
52 setText(history[index]);
54 current = index;
57 void HistLineEdit::updateHistory() {
58 if (echoMode() != Password) {
60 history.push_back(text());
61 buffer = "";
62 current = history.size();
65 emit receivedInput(text());
66 setText("");