BulletsModule.h
ButtonController.h
ColorCache.h
+ CustomizedWidgets.h
DialogView.h
DockView.h
EmptyTable.h
BulletsModule.cpp
ButtonController.cpp
ColorCache.cpp
+ CustomizedWidgets.cpp
Dialogs.cpp
EmptyTable.cpp
FileDialog.cpp
--- /dev/null
+/**
+ * \file GuiPrefs.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+/*
+ The code for the ShortcutLineEdit 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>
+ Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
+ Licensed under version 2 of the General Public License and
+ used here in accordance with the terms of that license.
+*/
+
+#include <config.h>
+
+#include "CustomizedWidgets.h"
+#include "GuiKeySymbol.h"
+
+#include "support/qstring_helpers.h"
+
+
+using lyx::KeySymbol;
+using lyx::toqstr;
+
+void ShortcutLineEdit::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 ShortcutLineEdit::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);
+}
+
+
+QString const SearchLineEdit::hintMessage()
+{
+ return toqstr("Search ...");
+}
+
+
+void SearchLineEdit::focusInEvent(QFocusEvent * e)
+{
+ if (text() == hintMessage())
+ clear();
+}
+
+
+void SearchLineEdit::focusOutEvent(QFocusEvent * e)
+{
+ if (text().isEmpty())
+ setText(hintMessage());
+}
+
+
+#include "CustomizedWidgets_moc.cpp"
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file CustomizedWidgets.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Bo Peng
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CUSTOMIZEDWIDGETS_H
+#define CUSTOMIZEDWIDGETS_H
+
+#include <QEvent>
+#include <QCloseEvent>
+#include <QLineEdit>
+
+/**
+ * A lineedit for inputting shortcuts
+ */
+class ShortcutLineEdit : public QLineEdit {
+ Q_OBJECT
+public:
+ ShortcutLineEdit(QWidget * parent) : QLineEdit(parent) {}
+protected Q_SLOTS:
+ void keyPressEvent(QKeyEvent * e);
+ bool event(QEvent* e);
+};
+
+
+/**
+ * A lineedit that displays a hint message when there is no
+ * text and not under focus.
+ */
+class SearchLineEdit : public QLineEdit {
+ Q_OBJECT
+public:
+ QString const hintMessage();
+ SearchLineEdit(QWidget * parent) : QLineEdit(parent) {}
+protected Q_SLOTS:
+ void focusInEvent(QFocusEvent * e);
+ void focusOutEvent(QFocusEvent * e);
+};
+
+
+#endif // CUSTOMIZEDWIDGETS_H
*
* \author John Levon
* \author Bo Peng
- * \author Edwin Leuven
*
* Full author contact details are available in file CREDITS.
*/
-/*
- The code for the ShortcutEdit 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>
- Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
- Licensed under version 2 of the General Public License and
- used here in accordance with the terms of that license.
-*/
-
#include <config.h>
#include "GuiPrefs.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);
}
shortcutsTW->sortItems(0, Qt::AscendingOrder);
QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
- searchPB->setEnabled(!searchLE->text().isEmpty());
}
}
-void PrefShortcuts::on_searchPB_pressed()
+void PrefShortcuts::on_searchLE_textChanged()
{
+ if (searchLE->text() == searchLE->hintMessage())
+ return;
+ if (searchLE->text().isEmpty()) {
+ // show all hidden items
+ QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
+ while (*it)
+ shortcutsTW->setItemHidden(*it++, false);
+ return;
+ }
// search both columns
QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
}
-void PrefShortcuts::on_searchLE_textChanged()
-{
- searchPB->setEnabled(!searchLE->text().isEmpty());
- if (searchLE->text().isEmpty()) {
- // show all hidden items
- QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
- while (*it)
- shortcutsTW->setItemHidden(*it++, false);
- }
-}
-
-
void PrefShortcuts::shortcut_okPB_pressed()
{
string shortcut = fromqstr(shortcut_->shortcutLE->text());
string lfun = fromqstr(shortcut_->lfunLE->text());
FuncRequest func = lyxaction.lookupFunc(lfun);
- if (func.action == LFUN_UNKNOWN_ACTION) {
+ if (shortcut.empty() || func.action == LFUN_UNKNOWN_ACTION) {
Alert::error(_("Failed to create shortcut"),
_("Unknown or invalid LyX function"));
return;
};
-/**
- * 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);
- ShortcutEdit * shortcutLE;
};
void select_bind();
void on_newPB_pressed();
void on_removePB_pressed();
- void on_searchPB_pressed();
void on_searchLE_textChanged();
///
void on_shortcutsTW_itemSelectionChanged();
BulletsModule.cpp \
ButtonController.cpp \
ColorCache.cpp \
+ CustomizedWidgets.cpp \
Dialogs.cpp \
EmptyTable.cpp \
FileDialog.cpp \
Action.h \
BulletsModule.h \
ColorCache.h \
+ CustomizedWidgets.h \
DockView.h \
EmptyTable.h \
FloatPlacement.h \
<property name="spacing" >
<number>6</number>
</property>
- <item row="8" column="2" >
+ <item row="6" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
- <item row="5" column="2" >
+ <item row="4" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
- <item row="6" column="2" >
- <widget class="QLineEdit" name="searchLE" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>1</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
<item row="0" column="1" >
<widget class="QLineEdit" name="bindFileED" />
</item>
- <item rowspan="7" row="2" column="0" colspan="2" >
+ <item rowspan="5" row="2" column="0" colspan="2" >
<widget class="QTreeWidget" name="shortcutsTW" />
</item>
<item row="3" column="2" >
</property>
</widget>
</item>
- <item row="7" column="2" >
- <widget class="QPushButton" name="searchPB" >
+ <item row="5" column="2" >
+ <widget class="SearchLineEdit" name="searchLE" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text" >
- <string>Search</string>
+ <string>Search ...</string>
</property>
</widget>
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>SearchLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>CustomizedWidgets.h</header>
+ </customwidget>
+ </customwidgets>
<tabstops>
<tabstop>bindFileED</tabstop>
<tabstop>bindFilePB</tabstop>
<property name="spacing" >
<number>6</number>
</property>
- <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" >
</item>
</layout>
</item>
+ <item row="1" column="1" >
+ <widget class="ShortcutLineEdit" name="shortcutLE" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>13</hsizetype>
+ <vsizetype>13</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>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>ShortcutLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>CustomizedWidgets.h</header>
+ </customwidget>
+ </customwidgets>
<tabstops>
<tabstop>lfunLE</tabstop>
<tabstop>okPB</tabstop>