]> git.lyx.org Git - features.git/commitdiff
PrefShortcuts: ShortcutEdit, adapted from Edwin's patch
authorBo Peng <bpeng@lyx.org>
Tue, 23 Oct 2007 03:48:02 +0000 (03:48 +0000)
committerBo Peng <bpeng@lyx.org>
Tue, 23 Oct 2007 03:48:02 +0000 (03:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21140 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 694087238766b3226be616a7810c429191f2eef7..fcb8003e0f84b34d1675f7c53f6df85c3ee292b0 100644 (file)
@@ -4,6 +4,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ * \author Bo Peng
+ * \author Edwin Leuven
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -24,6 +26,7 @@
 #include "FuncRequest.h"
 #include "gettext.h"
 #include "GuiFontExample.h"
+#include "GuiKeySymbol.h"
 #include "KeyMap.h"
 #include "KeySequence.h"
 #include "LyXAction.h"
@@ -1692,6 +1695,74 @@ void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
 //
 /////////////////////////////////////////////////////////////////////
 
+
+void ShortcutEdit::keyPressEvent(QKeyEvent * e)
+{
+       int keyQt = e->key();
+       switch(e->key()) {
+               case Qt::Key_AltGr: //or else we get unicode salad
+               case Qt::Key_Shift:
+               case Qt::Key_Control:
+               case Qt::Key_Alt:
+               case Qt::Key_Meta:
+                       break;
+               default:
+                       if (keyQt) {
+                               uint modifierKeys = e->modifiers();
+                               
+                               QString txt;
+                               if (modifierKeys & Qt::SHIFT)
+                                       txt += "S-";
+                               if (modifierKeys & Qt::CTRL)
+                                       txt += "C-";
+                               if (modifierKeys & Qt::ALT)
+                                       txt += "M-";
+
+                               KeySymbol sym;
+                               setKeySymbol(&sym, e);
+                               txt += toqstr(sym.getSymbolName());
+
+                               if (text().isEmpty())
+                                       setText(txt);
+                               else
+                                       setText(text() + " " + txt);
+                       }
+       }
+}
+
+
+//prevent Qt from special casing Tab and Backtab
+bool ShortcutEdit::event(QEvent* e)
+{
+       if (e->type() == QEvent::ShortcutOverride)
+               return false;
+
+       if (e->type() == QEvent::KeyPress) {
+               keyPressEvent(static_cast<QKeyEvent *>(e));
+               return true;
+       }
+
+       return QLineEdit::event(e);
+}
+
+
+GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
+{
+       Ui::shortcutUi::setupUi(this);
+       QDialog::setModal(true);
+       // adapted from ui_ShortcutUi.h
+       shortcutLE = new ShortcutEdit(parent);
+       shortcutLE->setObjectName(QString::fromUtf8("shortcutLE"));
+       QSizePolicy sp(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(0));
+       sp.setHorizontalStretch(0);
+       sp.setVerticalStretch(0);
+       sp.setHeightForWidth(shortcutLE->sizePolicy().hasHeightForWidth());
+       shortcutLE->setSizePolicy(sp);
+       gridLayout->addWidget(shortcutLE, 1, 1, 1, 1);
+       QWidget::setTabOrder(shortcutLE, okPB);
+}
+
+
 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
        : PrefModule(_("Shortcuts"), form, parent)
 {
@@ -1723,6 +1794,8 @@ PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
                this, SIGNAL(changed()));
        connect(shortcut_->cancelPB, SIGNAL(clicked()), 
                shortcut_, SLOT(reject()));
+       connect(shortcut_->clearPB, SIGNAL(clicked()),
+               this, SLOT(shortcut_clearPB_pressed()));
        connect(shortcut_->okPB, SIGNAL(clicked()), 
                this, SLOT(shortcut_okPB_pressed()));
 }
@@ -2073,6 +2146,13 @@ void PrefShortcuts::shortcut_okPB_pressed()
 }
 
 
+void PrefShortcuts::shortcut_clearPB_pressed()
+{
+       shortcut_->shortcutLE->clear();
+       shortcut_->shortcutLE->setFocus();
+}
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // PrefIdentity
index e4b5f19a96b6578f7cebec5fc1f667c0629852bb..373f14d12717d0a3e32de24d81f28609d0f2095c 100644 (file)
@@ -5,6 +5,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ * \author Bo Peng
+ * \author Edwin Leuven
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -347,14 +349,24 @@ public Q_SLOTS:
 };
 
 
-class GuiShortcutDialog : public QDialog, public Ui::ShortcutUi
+/**
+ * A lineedit for inputting shortcuts
+ */
+class ShortcutEdit : public QLineEdit {
+       Q_OBJECT
+public:
+       ShortcutEdit(QWidget * parent) : QLineEdit(parent) {}
+protected Q_SLOTS:
+       void keyPressEvent(QKeyEvent * e);
+       bool event(QEvent* e);
+};
+
+
+class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
 {
 public:
-       GuiShortcutDialog(QWidget * parent) : QDialog(parent)
-       {
-               Ui::ShortcutUi::setupUi(this);
-               QDialog::setModal(true);
-       }
+       GuiShortcutDialog(QWidget * parent);
+       ShortcutEdit * shortcutLE;
 };
 
 
@@ -390,6 +402,7 @@ public Q_SLOTS:
        ///
        void on_shortcutsTW_itemSelectionChanged();
        void shortcut_okPB_pressed();
+       void shortcut_clearPB_pressed();
        void on_shortcutsTW_itemDoubleClicked();
 
 private:
index 0f36f31105ba770cc142754e4a801127b9e4fa8c..bf77d33c40f929a17d7259eb52d111bf4f40965d 100644 (file)
@@ -1,11 +1,11 @@
 <ui version="4.0" >
- <class>ShortcutUi</class>
+ <class>shortcutUi</class>
  <widget class="QDialog" name="shortcutUi" >
   <property name="geometry" >
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>221</width>
+    <width>277</width>
     <height>147</height>
    </rect>
   </property>
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="2" column="0" colspan="2" >
+   <item row="1" column="1" >
+    <widget class="QLineEdit" name="placeholderLE" >
+     <property name="enabled" >
+      <bool>false</bool>
+     </property>
+     <property name="sizePolicy" >
+      <sizepolicy>
+       <hsizetype>7</hsizetype>
+       <vsizetype>0</vsizetype>
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="toolTip" >
+      <string>Enter BibTeX database name</string>
+     </property>
+     <property name="text" >
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1" colspan="2" >
+    <widget class="QLineEdit" name="lfunLE" >
+     <property name="sizePolicy" >
+      <sizepolicy>
+       <hsizetype>7</hsizetype>
+       <vsizetype>0</vsizetype>
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="toolTip" >
+      <string>Enter BibTeX database name</string>
+     </property>
+     <property name="text" >
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="2" >
+    <widget class="QPushButton" name="clearPB" >
+     <property name="text" >
+      <string>Clear</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" >
+    <widget class="QLabel" name="shortcutLBL" >
+     <property name="text" >
+      <string>Shortcut</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" >
+    <widget class="QLabel" name="lfunLBL" >
+     <property name="text" >
+      <string>Function:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="3" >
     <layout class="QHBoxLayout" >
      <property name="margin" >
       <number>0</number>
      </item>
     </layout>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="lfunLBL" >
-     <property name="text" >
-      <string>Function:</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0" >
-    <widget class="QLabel" name="shortcutLBL" >
-     <property name="text" >
-      <string>Shortcut</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="1" >
-    <widget class="QLineEdit" name="shortcutLE" >
-     <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>7</hsizetype>
-       <vsizetype>0</vsizetype>
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="toolTip" >
-      <string>Enter BibTeX database name</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="1" >
-    <widget class="QLineEdit" name="lfunLE" >
-     <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>7</hsizetype>
-       <vsizetype>0</vsizetype>
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="toolTip" >
-      <string>Enter BibTeX database name</string>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <tabstops>