]> Shamusworld >> Repos - architektonas/blob - src/widgets/commandedit.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / widgets / commandedit.cpp
1 // commandedit.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/22/2010  Added this text. :-)
15 //
16
17 #include "commandedit.h"
18
19 #include "debug.h"
20
21 /**
22  * Default Constructor. You must call init manually if you choose
23  * to use this constructor.
24  */
25 CommandEdit::CommandEdit(QWidget * parent, const char */*name*/):
26 //      QLineEdit(parent, name)
27         QLineEdit(parent)
28 {
29 }
30
31 /**
32  * Destructor
33  */
34 CommandEdit::~CommandEdit()
35 {
36         it = 0;
37 }
38
39 /**
40  * Bypass for key press events from the tab key.
41  */
42 bool CommandEdit::event(QEvent * e)
43 {
44         if (e->type() == QEvent::KeyPress)
45         {
46                 QKeyEvent * k = (QKeyEvent *)e;
47
48                 if (k->key() == Qt::Key_Tab)
49                 {
50                         emit tabPressed();
51                         return true;
52                 }
53         }
54
55         return QLineEdit::event(e);
56 }
57
58 /**
59  * History (arrow key up/down) support, tab.
60  */
61 void CommandEdit::keyPressEvent(QKeyEvent * e)
62 {
63         switch (e->key())
64         {
65         case Qt::Key_Up:
66 #warning "!!! URG !!!"
67 //              if (it != historyList.begin() && it != 0)
68                 if (it != historyList.begin())// && it != 0)
69                 {
70                         it--;
71                         setText(*it);
72                 }
73                 break;
74
75         case Qt::Key_Down:
76 #warning "!!! URG !!!"
77 //              if (it != historyList.end() && it != 0)
78                 if (it != historyList.end())// && it != 0)
79                 {
80                         it++;
81
82                         if (it != historyList.end())
83                                 setText(*it);
84                         else
85                                 setText("");
86                 }
87                 break;
88
89         case Qt::Key_Return:
90                 historyList.append(text());
91                 it = historyList.end();
92                 QLineEdit::keyPressEvent(e);
93                 break;
94
95         case Qt::Key_Escape:
96                 if (text().isEmpty())
97                         emit escape();
98                 else
99                         setText("");
100                 break;
101
102         default:
103                 QLineEdit::keyPressEvent(e);
104                 break;
105         }
106 }
107
108 void CommandEdit::focusInEvent(QFocusEvent * e)
109 {
110         emit focusIn();
111         QLineEdit::focusInEvent(e);
112 }
113
114
115 void CommandEdit::focusOutEvent(QFocusEvent * e)
116 {
117         emit focusOut();
118         QLineEdit::focusOutEvent(e);
119 }
120