]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_commandedit.cpp
f345f0f6da24ebd951c2f992fb574dc2b80381a8
[architektonas] / src / widgets / qg_commandedit.cpp
1
2 #include "qg_commandedit.h"
3
4 #include "rs_debug.h"
5
6 /**
7  * Default Constructor. You must call init manually if you choose
8  * to use this constructor.
9  */
10 QG_CommandEdit::QG_CommandEdit(QWidget * parent, const char */*name*/):
11 //      QLineEdit(parent, name)
12         QLineEdit(parent)
13 {
14 }
15
16 /**
17  * Destructor
18  */
19 QG_CommandEdit::~QG_CommandEdit()
20 {
21         it = 0;
22 }
23
24 /**
25  * Bypass for key press events from the tab key.
26  */
27 bool QG_CommandEdit::event(QEvent * e)
28 {
29         if (e->type() == QEvent::KeyPress)
30         {
31                 QKeyEvent * k = (QKeyEvent *)e;
32
33                 if (k->key() == Qt::Key_Tab)
34                 {
35                         emit tabPressed();
36                         return true;
37                 }
38         }
39
40         return QLineEdit::event(e);
41 }
42
43 /**
44  * History (arrow key up/down) support, tab.
45  */
46 void QG_CommandEdit::keyPressEvent(QKeyEvent * e)
47 {
48         switch (e->key())
49         {
50         case Qt::Key_Up:
51 #warning "!!! URG !!!"
52 //              if (it != historyList.begin() && it != 0)
53                 if (it != historyList.begin())// && it != 0)
54                 {
55                         it--;
56                         setText(*it);
57                 }
58                 break;
59
60         case Qt::Key_Down:
61 #warning "!!! URG !!!"
62 //              if (it != historyList.end() && it != 0)
63                 if (it != historyList.end())// && it != 0)
64                 {
65                         it++;
66
67                         if (it != historyList.end())
68                                 setText(*it);
69                         else
70                                 setText("");
71                 }
72                 break;
73
74         case Qt::Key_Return:
75                 historyList.append(text());
76                 it = historyList.end();
77                 QLineEdit::keyPressEvent(e);
78                 break;
79
80         case Qt::Key_Escape:
81                 if (text().isEmpty())
82                         emit escape();
83                 else
84                         setText("");
85                 break;
86
87         default:
88                 QLineEdit::keyPressEvent(e);
89                 break;
90         }
91 }
92
93 void QG_CommandEdit::focusInEvent(QFocusEvent * e)
94 {
95         emit focusIn();
96         QLineEdit::focusInEvent(e);
97 }
98
99
100 void QG_CommandEdit::focusOutEvent(QFocusEvent * e)
101 {
102         emit focusOut();
103         QLineEdit::focusOutEvent(e);
104 }
105