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 "GuiKeySymbol.h"
27 #include <QApplication>
28 #include <QCloseEvent>
30 #include "support/qstring_helpers.h"
34 using lyx::KeySequence;
35 using lyx::KeyModifier;
38 ShortcutLineEdit::ShortcutLineEdit(QWidget * parent)
39 : QLineEdit(parent), keysequence_()
41 QApplication::instance()->installEventFilter(this);
46 void ShortcutLineEdit::reset()
49 keysequence_ = KeySequence();
53 bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e)
59 // swallow these if we have focus and they come from elsewhere
60 case QEvent::Shortcut:
61 case QEvent::ShortcutOverride:
71 KeySequence const ShortcutLineEdit::getKeySequence() const
77 void ShortcutLineEdit::keyPressEvent(QKeyEvent * e)
79 int const keyQt = e->key();
84 case Qt::Key_AltGr: //or else we get unicode salad
92 setText(toqstr(keysequence_.print(KeySequence::BindFile)));
97 bool ShortcutLineEdit::event(QEvent * e)
100 case QEvent::FocusOut:
103 case QEvent::FocusIn:
106 case QEvent::ShortcutOverride:
107 keyPressEvent(static_cast<QKeyEvent *>(e));
109 case QEvent::KeyRelease:
110 case QEvent::Shortcut:
111 case QEvent::KeyPress:
116 return QLineEdit::event(e);
120 void ShortcutLineEdit::appendToSequence(QKeyEvent * e)
123 setKeySymbol(&sym, e);
125 KeyModifier mod = lyx::NoModifier;
126 if (e->modifiers() & Qt::SHIFT)
127 mod |= lyx::ShiftModifier;
128 if (e->modifiers() & Qt::CTRL)
129 mod |= lyx::ControlModifier;
130 if (e->modifiers() & Qt::ALT | e->modifiers() & Qt::META)
131 mod |= lyx::AltModifier;
133 keysequence_.addkey(sym, mod, lyx::NoModifier);
137 QString const SearchLineEdit::hintMessage() const
139 return toqstr("Search ...");
143 void SearchLineEdit::focusInEvent(QFocusEvent * e)
145 if (text() == hintMessage())
150 void SearchLineEdit::focusOutEvent(QFocusEvent * e)
152 if (text().isEmpty())
153 setText(hintMessage());
157 #include "CustomizedWidgets_moc.cpp"