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;
42 ShortcutLineEdit::ShortcutLineEdit(QWidget * parent)
43 : QLineEdit(parent), keysequence_()
45 QApplication::instance()->installEventFilter(this);
50 void ShortcutLineEdit::reset()
53 keysequence_ = KeySequence();
57 bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e)
63 // swallow these if we have focus and they come from elsewhere
64 case QEvent::Shortcut:
65 case QEvent::ShortcutOverride:
75 KeySequence const ShortcutLineEdit::getKeySequence() const
81 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
83 int const keyQt = e->key();
88 case Qt::Key_AltGr: //or else we get unicode salad
96 setText(toqstr(keysequence_.print(KeySequence::BindFile)));
101 bool ShortcutLineEdit::event(QEvent * e)
104 case QEvent::FocusOut:
107 case QEvent::FocusIn:
110 case QEvent::ShortcutOverride:
111 keyPressEvent(static_cast<QKeyEvent *>(e));
113 case QEvent::KeyRelease:
114 case QEvent::Shortcut:
115 case QEvent::KeyPress:
120 return QLineEdit::event(e);
124 void ShortcutLineEdit::appendToSequence(QKeyEvent * e)
127 setKeySymbol(&sym, e);
129 KeyModifier mod = lyx::q_key_state(e->modifiers());
131 keysequence_.addkey(sym, mod, lyx::NoModifier);
134 } // namespace frontend
137 #include "CustomizedWidgets_moc.cpp"