]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiCommandEdit.cpp
22dd9c8f033a4476cfa762e75a729b5367058435
[features.git] / src / frontends / qt / GuiCommandEdit.cpp
1 /**
2  * \file GuiCommandEdit.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiCommandEdit.h"
14
15 #include <QKeyEvent>
16 #include <QEvent>
17
18 #undef KeyPress
19
20 namespace lyx {
21 namespace frontend {
22
23 GuiCommandEdit::GuiCommandEdit(QWidget * parent)
24         : QLineEdit(parent)
25 {
26         setFocusPolicy(Qt::ClickFocus);
27 }
28
29
30 void GuiCommandEdit::keyPressEvent(QKeyEvent * e)
31 {
32         switch (e->key()) {
33         case Qt::Key_Escape:
34                 // emit signal
35                 escapePressed();
36                 break;
37
38         case Qt::Key_Up:
39                 // emit signal
40                 upPressed();
41                 break;
42
43         case Qt::Key_Down:
44                 // emit signal
45                 downPressed();
46                 break;
47
48         default:
49                 QLineEdit::keyPressEvent(e);
50                 break;
51         }
52 }
53
54
55 bool GuiCommandEdit::event(QEvent * e)
56 {
57         if (e->type() != QEvent::KeyPress)
58                 return QLineEdit::event(e);
59
60         QKeyEvent * ev = (QKeyEvent *)e;
61
62         if (ev->key() != Qt::Key_Tab)
63                 return QLineEdit::event(e);
64
65         // emit signal
66         tabPressed();
67         return true;
68 }
69
70 } // namespace frontend
71 } // namespace lyx
72
73 #include "moc_GuiCommandEdit.cpp"