3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
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.
24 #include "CustomizedWidgets.h"
25 #include "FuncRequest.h"
26 #include "GuiKeySymbol.h"
28 #include <QApplication>
29 #include <QCloseEvent>
31 #include "support/qstring_helpers.h"
35 using lyx::KeySequence;
36 using lyx::KeyModifier;
39 ShortcutLineEdit::ShortcutLineEdit(QWidget * parent)
40 : QLineEdit(parent), keysequence_()
42 QApplication::instance()->installEventFilter(this);
47 void ShortcutLineEdit::reset()
50 keysequence_ = KeySequence();
54 bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e)
60 // swallow these if we have focus and they come from elsewhere
61 case QEvent::Shortcut:
62 case QEvent::ShortcutOverride:
72 KeySequence const ShortcutLineEdit::getKeySequence() const
78 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
80 int const keyQt = e->key();
85 case Qt::Key_AltGr: //or else we get unicode salad
93 setText(toqstr(keysequence_.print(KeySequence::BindFile)));
98 bool ShortcutLineEdit::event(QEvent * e)
101 case QEvent::FocusOut:
104 case QEvent::FocusIn:
107 case QEvent::ShortcutOverride:
108 keyPressEvent(static_cast<QKeyEvent *>(e));
110 case QEvent::KeyRelease:
111 case QEvent::Shortcut:
112 case QEvent::KeyPress:
117 return QLineEdit::event(e);
121 void ShortcutLineEdit::appendToSequence(QKeyEvent * e)
124 setKeySymbol(&sym, e);
126 KeyModifier mod = lyx::q_key_state(e->modifiers());
128 keysequence_.addkey(sym, mod, lyx::NoModifier);
132 QString const SearchLineEdit::hintMessage() const
134 return toqstr("Search ...");
138 void SearchLineEdit::focusInEvent(QFocusEvent * e)
140 if (text() == hintMessage())
145 void SearchLineEdit::focusOutEvent(QFocusEvent * e)
147 if (text().isEmpty())
148 setText(hintMessage());
152 #include "CustomizedWidgets_moc.cpp"