* 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.
*/
#include "FuncRequest.h"
#include "gettext.h"
#include "GuiFontExample.h"
+#include "GuiKeySymbol.h"
#include "KeyMap.h"
#include "KeySequence.h"
#include "LyXAction.h"
//
/////////////////////////////////////////////////////////////////////
+
+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)
{
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()));
}
}
+void PrefShortcuts::shortcut_clearPB_pressed()
+{
+ shortcut_->shortcutLE->clear();
+ shortcut_->shortcutLE->setFocus();
+}
+
+
/////////////////////////////////////////////////////////////////////
//
// PrefIdentity
* 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.
*/
};
-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;
};
///
void on_shortcutsTW_itemSelectionChanged();
void shortcut_okPB_pressed();
+ void shortcut_clearPB_pressed();
void on_shortcutsTW_itemDoubleClicked();
private:
<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>