diff --git a/src/frontends/qt4/CustomizedWidgets.cpp b/src/frontends/qt4/CustomizedWidgets.cpp index 9a8152bf41..bf5d4a7413 100644 --- a/src/frontends/qt4/CustomizedWidgets.cpp +++ b/src/frontends/qt4/CustomizedWidgets.cpp @@ -10,7 +10,7 @@ */ /* - The code for the ShortcutLineEdit class was adapted from + The code for the ShortcutWidget class was adapted from kkeysequencewidget.cpp, which is part of the KDE libraries. Copyright (C) 1998 Mark Donohoe Copyright (C) 2001 Ellis Whitehead @@ -27,6 +27,7 @@ #include #include +#include #include #include "support/qstring_helpers.h" @@ -40,22 +41,26 @@ using lyx::toqstr; namespace lyx { namespace frontend { -ShortcutLineEdit::ShortcutLineEdit(QWidget * parent) - : QLineEdit(parent), keysequence_() +ShortcutWidget::ShortcutWidget(QWidget * parent) + : QLabel(parent), keysequence_() { QApplication::instance()->installEventFilter(this); has_cursor_ = false; + setFrameShape(QFrame::StyledPanel); + setFrameShadow(QFrame::Raised); + setFocusPolicy(Qt::StrongFocus); + setAlignment(Qt::AlignCenter); } -void ShortcutLineEdit::reset() +void ShortcutWidget::reset() { clear(); keysequence_ = KeySequence(); } -bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e) +bool ShortcutWidget::eventFilter(QObject * obj, QEvent * e) { if (!has_cursor_) return false; @@ -68,18 +73,18 @@ bool ShortcutLineEdit::eventFilter(QObject * obj, QEvent * e) return true; default: break; - } + } return false; } -KeySequence const ShortcutLineEdit::getKeySequence() const +KeySequence const ShortcutWidget::getKeySequence() const { return keysequence_; } -void ShortcutLineEdit::keyPressEvent(QKeyEvent * e) +void ShortcutWidget::keyPressEvent(QKeyEvent * e) { int const keyQt = e->key(); if (!keyQt) @@ -99,14 +104,16 @@ void ShortcutLineEdit::keyPressEvent(QKeyEvent * e) } -bool ShortcutLineEdit::event(QEvent * e) +bool ShortcutWidget::event(QEvent * e) { switch (e->type()) { case QEvent::FocusOut: has_cursor_ = false; + setFrameShadow(QFrame::Raised); break; case QEvent::FocusIn: has_cursor_ = true; + setFrameShadow(QFrame::Sunken); break; case QEvent::ShortcutOverride: keyPressEvent(static_cast(e)); @@ -118,11 +125,11 @@ bool ShortcutLineEdit::event(QEvent * e) default: break; } - return QLineEdit::event(e); + return QLabel::event(e); } -void ShortcutLineEdit::appendToSequence(QKeyEvent * e) +void ShortcutWidget::appendToSequence(QKeyEvent * e) { KeySymbol sym; setKeySymbol(&sym, e); diff --git a/src/frontends/qt4/CustomizedWidgets.h b/src/frontends/qt4/CustomizedWidgets.h index 6b3226c3e4..41b2d4c858 100644 --- a/src/frontends/qt4/CustomizedWidgets.h +++ b/src/frontends/qt4/CustomizedWidgets.h @@ -13,7 +13,7 @@ #ifndef CUSTOMIZEDWIDGETS_H #define CUSTOMIZEDWIDGETS_H -#include +#include #include "KeySequence.h" class QEvent; @@ -23,12 +23,12 @@ namespace lyx { namespace frontend { /** - * A lineedit for inputting shortcuts + * A widget for inputting shortcuts */ -class ShortcutLineEdit : public QLineEdit { +class ShortcutWidget : public QLabel { Q_OBJECT public: - ShortcutLineEdit(QWidget * parent); + ShortcutWidget(QWidget * parent); void reset(); bool eventFilter(QObject*, QEvent* e ); lyx::KeySequence const getKeySequence() const; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index e9e8c544c6..010aaf7493 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2057,6 +2057,8 @@ PrefShortcuts::PrefShortcuts(GuiPreferences * form) this, SLOT(shortcut_clearPB_pressed())); connect(shortcut_->okPB, SIGNAL(clicked()), this, SLOT(shortcut_okPB_pressed())); + connect(shortcut_->cancelPB, SIGNAL(clicked()), + this, SLOT(shortcut_cancelPB_pressed())); } @@ -2265,8 +2267,8 @@ void PrefShortcuts::modifyShortcut() QTreeWidgetItem * item = shortcutsTW->currentItem(); if (item->flags() & Qt::ItemIsSelectable) { shortcut_->lfunLE->setText(item->text(0)); - shortcut_->shortcutLE->setText(item->text(1)); - shortcut_->shortcutLE->setFocus(); + shortcut_->shortcutWG->setText(item->text(1)); + shortcut_->shortcutWG->setFocus(); shortcut_->exec(); } } @@ -2293,7 +2295,7 @@ void PrefShortcuts::on_modifyPB_pressed() void PrefShortcuts::on_newPB_pressed() { shortcut_->lfunLE->clear(); - shortcut_->shortcutLE->reset(); + shortcut_->shortcutWG->reset(); shortcut_->exec(); } @@ -2388,7 +2390,7 @@ void PrefShortcuts::shortcut_okPB_pressed() return; } - KeySequence k = shortcut_->shortcutLE->getKeySequence(); + KeySequence k = shortcut_->shortcutWG->getKeySequence(); if (k.length() == 0) { Alert::error(_("Failed to create shortcut"), _("Invalid or empty key sequence")); @@ -2416,10 +2418,15 @@ void PrefShortcuts::shortcut_okPB_pressed() } +void PrefShortcuts::shortcut_cancelPB_pressed() +{ + shortcut_->shortcutWG->reset(); +} + + void PrefShortcuts::shortcut_clearPB_pressed() { - shortcut_->shortcutLE->reset(); - shortcut_->shortcutLE->setFocus(); + shortcut_->shortcutWG->reset(); } diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index b3cc0e57ae..453b1b105a 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -450,6 +450,7 @@ public Q_SLOTS: /// void on_shortcutsTW_itemSelectionChanged(); void shortcut_okPB_pressed(); + void shortcut_cancelPB_pressed(); void shortcut_clearPB_pressed(); void on_shortcutsTW_itemDoubleClicked(); diff --git a/src/frontends/qt4/ui/ShortcutUi.ui b/src/frontends/qt4/ui/ShortcutUi.ui index cabe9b8094..88d2766801 100644 --- a/src/frontends/qt4/ui/ShortcutUi.ui +++ b/src/frontends/qt4/ui/ShortcutUi.ui @@ -23,12 +23,12 @@ 6 - + true - Type shortcut while the cursor is in this field + Type shortcut after clicking on this field. You can reset the content with the 'Clear' button @@ -47,6 +47,9 @@ + + Clear current shortcut + C&lear @@ -68,7 +71,7 @@ &Shortcut: - shortcutLE + shortcutWG @@ -125,7 +128,7 @@ - lyx::frontend::ShortcutLineEdit + lyx::frontend::ShortcutWidget QLineEdit
CustomizedWidgets.h