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>
30 #include "support/qstring_helpers.h"
34 using lyx::KeySequence;
35 using lyx::KeyModifier;
41 ShortcutLineEdit::ShortcutLineEdit(QWidget * parent)
42 : QLineEdit(parent), keysequence_()
44 QApplication::instance()->installEventFilter(this);
49 void ShortcutLineEdit::reset()
52 keysequence_ = KeySequence();
56 bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e)
62 // swallow these if we have focus and they come from elsewhere
63 case QEvent::Shortcut:
64 case QEvent::ShortcutOverride:
74 KeySequence const ShortcutLineEdit::getKeySequence() const
80 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
82 int const keyQt = e->key();
87 case Qt::Key_AltGr: //or else we get unicode salad
95 setText(toqstr(keysequence_.print(KeySequence::ForGui)));
100 bool ShortcutLineEdit::event(QEvent * e)
103 case QEvent::FocusOut:
106 case QEvent::FocusIn:
109 case QEvent::ShortcutOverride:
110 keyPressEvent(static_cast<QKeyEvent *>(e));
112 case QEvent::KeyRelease:
113 case QEvent::Shortcut:
114 case QEvent::KeyPress:
119 return QLineEdit::event(e);
123 void ShortcutLineEdit::appendToSequence(QKeyEvent * e)
126 setKeySymbol(&sym, e);
128 KeyModifier mod = lyx::q_key_state(e->modifiers());
130 keysequence_.addkey(sym, mod, lyx::NoModifier);
133 } // namespace frontend
136 #include "CustomizedWidgets_moc.cpp"