]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/CustomizedWidgets.cpp
d97c5a586eeba63d58fc5b17335275982573e0eb
[lyx.git] / src / frontends / qt4 / CustomizedWidgets.cpp
1 /**
2  * \file GuiPrefs.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  * \author Edwin Leuven
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 /*
13         The code for the ShortcutLineEdit class was adapted from
14         kkeysequencewidget.cpp, which is part of the KDE libraries.
15         Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
16         Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
17         Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
18         Licensed under version 2 of the General Public License and
19         used here in accordance with the terms of that license.
20 */
21
22 #include <config.h>
23
24 #include "CustomizedWidgets.h"
25 #include "GuiKeySymbol.h"
26
27 #include "support/qstring_helpers.h"
28
29
30 using lyx::KeySymbol;
31 using lyx::toqstr;
32
33 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
34 {
35         int keyQt = e->key();
36         switch(e->key()) {
37                 case Qt::Key_AltGr: //or else we get unicode salad
38                 case Qt::Key_Shift:
39                 case Qt::Key_Control:
40                 case Qt::Key_Alt:
41                 case Qt::Key_Meta:
42                         break;
43                 default:
44                         if (keyQt) {
45                                 uint modifierKeys = e->modifiers();
46
47                                 QString txt;
48                                 if (modifierKeys & Qt::SHIFT)
49                                         txt += "S-";
50                                 if (modifierKeys & Qt::CTRL)
51                                         txt += "C-";
52                                 if (modifierKeys & Qt::ALT)
53                                         txt += "M-";
54
55                                 KeySymbol sym;
56                                 setKeySymbol(&sym, e);
57                                 txt += toqstr(sym.getSymbolName());
58
59                                 if (text().isEmpty())
60                                         setText(txt);
61                                 else
62                                         setText(text() + " " + txt);
63                         }
64         }
65 }
66
67
68 //prevent Qt from special casing Tab and Backtab
69 bool ShortcutLineEdit::event(QEvent* e)
70 {
71         if (e->type() == QEvent::ShortcutOverride)
72                 return false;
73
74         if (e->type() == QEvent::KeyPress) {
75                 keyPressEvent(static_cast<QKeyEvent *>(e));
76                 return true;
77         }
78
79         return QLineEdit::event(e);
80 }
81
82
83 QString const SearchLineEdit::hintMessage()
84 {
85         return toqstr("Search ...");
86 }
87
88
89 void SearchLineEdit::focusInEvent(QFocusEvent * e)
90 {
91         if (text() == hintMessage())
92                 clear();
93 }
94
95
96 void SearchLineEdit::focusOutEvent(QFocusEvent * e)
97 {
98         if (text().isEmpty())
99                 setText(hintMessage());
100 }
101
102
103 #include "CustomizedWidgets_moc.cpp"