]> git.lyx.org Git - features.git/commitdiff
Hopefully less confusing shortcut settings UI (bug 5012).
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 21 Jul 2008 14:54:07 +0000 (14:54 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 21 Jul 2008 14:54:07 +0000 (14:54 +0000)
* 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

src/frontends/qt4/CustomizedWidgets.cpp
src/frontends/qt4/CustomizedWidgets.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h
src/frontends/qt4/ui/ShortcutUi.ui

index 9a8152bf41875c67ec0be3691909cd1341b2b9c1..bf5d4a741374c96a544d4a0404b413f29ced8e8a 100644 (file)
@@ -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);
index 6b3226c3e4f20821ca0d6ec6a6879bd057a5a7d8..41b2d4c85886e04ccf1f9400d1392f077694732e 100644 (file)
@@ -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;
index e9e8c544c6831e135544ed18ab31e9716c61ba28..010aaf7493467ab20c1665cb3ee468db16d9600b 100644 (file)
@@ -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();
 }
 
 
index b3cc0e57ae7cd9e17b33313538b8549703e5a5d2..453b1b105a00cb202b0a7baf6c886171e0e17a2a 100644 (file)
@@ -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();
 
index cabe9b8094fc6a1ab544be7fbdfb9a207b76508d..88d2766801aeb3af2b6cf4541486586583a93ed7 100644 (file)
     <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&amp;lear</string>
      </property>
@@ -68,7 +71,7 @@
       <string>&amp;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>