* src/frontends/qt4/CustomizedWidgets{cpp,h}:
- rename ShortcutLineEdit to ShortcutWidget and build it on
top of QLabel instead of QLineEdit
* src/frontends/qt4/GuiPrefs.{cpp,h}:
* src/frontends/qt4/ui/ShortcutUi.ui:
- improve shortcut editing
- rename shortcutLE to shortcutWG
- add/improve tooltips
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25770
a592a061-630c-0410-9148-
cb99ea01b6c8
*/
/*
- 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 <donohoe@kde.org>
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
#include <QApplication>
#include <QKeyEvent>
+#include <QMouseEvent>
#include <QShowEvent>
#include "support/qstring_helpers.h"
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;
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)
}
-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<QKeyEvent *>(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);
#ifndef CUSTOMIZEDWIDGETS_H
#define CUSTOMIZEDWIDGETS_H
-#include <QLineEdit>
+#include <QLabel>
#include "KeySequence.h"
class QEvent;
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;
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()));
}
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();
}
}
void PrefShortcuts::on_newPB_pressed()
{
shortcut_->lfunLE->clear();
- shortcut_->shortcutLE->reset();
+ shortcut_->shortcutWG->reset();
shortcut_->exec();
}
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"));
}
+void PrefShortcuts::shortcut_cancelPB_pressed()
+{
+ shortcut_->shortcutWG->reset();
+}
+
+
void PrefShortcuts::shortcut_clearPB_pressed()
{
- shortcut_->shortcutLE->reset();
- shortcut_->shortcutLE->setFocus();
+ shortcut_->shortcutWG->reset();
}
///
void on_shortcutsTW_itemSelectionChanged();
void shortcut_okPB_pressed();
+ void shortcut_cancelPB_pressed();
void shortcut_clearPB_pressed();
void on_shortcutsTW_itemDoubleClicked();
<number>6</number>
</property>
<item row="1" column="1" >
- <widget class="lyx::frontend::ShortcutLineEdit" name="shortcutLE" >
+ <widget class="lyx::frontend::ShortcutWidget" name="shortcutWG" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="toolTip" >
- <string>Type shortcut while the cursor is in this field</string>
+ <string>Type shortcut after clicking on this field. You can reset the content with the 'Clear' button</string>
</property>
<property name="text" >
<string/>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="clearPB" >
+ <property name="toolTip" >
+ <string>Clear current shortcut</string>
+ </property>
<property name="text" >
<string>C&lear</string>
</property>
<string>&Shortcut:</string>
</property>
<property name="buddy" >
- <cstring>shortcutLE</cstring>
+ <cstring>shortcutWG</cstring>
</property>
</widget>
</item>
</widget>
<customwidgets>
<customwidget>
- <class>lyx::frontend::ShortcutLineEdit</class>
+ <class>lyx::frontend::ShortcutWidget</class>
<extends>QLineEdit</extends>
<header>CustomizedWidgets.h</header>
</customwidget>