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>
32 #include "support/qstring_helpers.h"
36 using lyx::KeySequence;
37 using lyx::KeyModifier;
43 ShortcutLineEdit::ShortcutLineEdit(QWidget * parent)
44 : QLineEdit(parent), keysequence_()
46 QApplication::instance()->installEventFilter(this);
51 void ShortcutLineEdit::reset()
54 keysequence_ = KeySequence();
58 bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e)
64 // swallow these if we have focus and they come from elsewhere
65 case QEvent::Shortcut:
66 case QEvent::ShortcutOverride:
76 KeySequence const ShortcutLineEdit::getKeySequence() const
82 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
84 int const keyQt = e->key();
89 case Qt::Key_AltGr: //or else we get unicode salad
97 setText(toqstr(keysequence_.print(KeySequence::ForGui)));
102 bool ShortcutLineEdit::event(QEvent * e)
105 case QEvent::FocusOut:
108 case QEvent::FocusIn:
111 case QEvent::ShortcutOverride:
112 keyPressEvent(static_cast<QKeyEvent *>(e));
114 case QEvent::KeyRelease:
115 case QEvent::Shortcut:
116 case QEvent::KeyPress:
121 return QLineEdit::event(e);
125 void ShortcutLineEdit::appendToSequence(QKeyEvent * e)
128 setKeySymbol(&sym, e);
130 KeyModifier mod = lyx::q_key_state(e->modifiers());
132 keysequence_.addkey(sym, mod, lyx::NoModifier);
135 } // namespace frontend
138 #include "CustomizedWidgets_moc.cpp"