mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-13 20:09:59 +00:00
Hopefully less confusing shortcut settings UI (bug 5012).
* 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
This commit is contained in:
parent
c6400f4f60
commit
aa176fd56c
@ -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 <donohoe@kde.org>
|
||||
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
||||
@ -27,6 +27,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QShowEvent>
|
||||
|
||||
#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<QKeyEvent *>(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);
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef CUSTOMIZEDWIDGETS_H
|
||||
#define CUSTOMIZEDWIDGETS_H
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
<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/>
|
||||
@ -47,6 +47,9 @@
|
||||
</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>
|
||||
@ -68,7 +71,7 @@
|
||||
<string>&Shortcut:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>shortcutLE</cstring>
|
||||
<cstring>shortcutWG</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -125,7 +128,7 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>lyx::frontend::ShortcutLineEdit</class>
|
||||
<class>lyx::frontend::ShortcutWidget</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>CustomizedWidgets.h</header>
|
||||
</customwidget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user