]> git.lyx.org Git - features.git/commitdiff
Properly extend qt standard widgets, remove the search button in PrefShortcuts.
authorBo Peng <bpeng@lyx.org>
Thu, 25 Oct 2007 03:08:22 +0000 (03:08 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 25 Oct 2007 03:08:22 +0000 (03:08 +0000)
*  src/frontends/qt4/ui/ShortcutUi.ui: use ShortcutLineEdit
*  src/frontends/qt4/ui/PrefShortcutsUi.ui: remove searchPB
*  src/frontends/qt4/CustomizedWidgets.h|cpp: define ShortcutLineEdit and SearchLineEdit.
*  src/frontends/qt4/GuiPrefs.h|cpp: remove ShortcutEdit
*  src/frontends/qt4/Makefile.am: build system changes
*  development/scons/scons_manifest.py

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21193 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/scons_manifest.py
src/frontends/qt4/CustomizedWidgets.cpp [new file with mode: 0644]
src/frontends/qt4/CustomizedWidgets.h [new file with mode: 0644]
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h
src/frontends/qt4/Makefile.am
src/frontends/qt4/ui/PrefShortcutsUi.ui
src/frontends/qt4/ui/ShortcutUi.ui

index 19b150b508d85848de20f84bd0b48a836eab71a8..6586ba9b99b1ae5b02ee33b0f4a5b4a22574d5b2 100644 (file)
@@ -742,6 +742,7 @@ src_frontends_qt4_header_files = Split('''
     BulletsModule.h
     ButtonController.h
     ColorCache.h
+    CustomizedWidgets.h
     DialogView.h
     DockView.h
     EmptyTable.h
@@ -831,6 +832,7 @@ src_frontends_qt4_files = Split('''
     BulletsModule.cpp
     ButtonController.cpp
     ColorCache.cpp
+    CustomizedWidgets.cpp
     Dialogs.cpp
     EmptyTable.cpp
     FileDialog.cpp
diff --git a/src/frontends/qt4/CustomizedWidgets.cpp b/src/frontends/qt4/CustomizedWidgets.cpp
new file mode 100644 (file)
index 0000000..d97c5a5
--- /dev/null
@@ -0,0 +1,103 @@
+/**
+ * \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"
diff --git a/src/frontends/qt4/CustomizedWidgets.h b/src/frontends/qt4/CustomizedWidgets.h
new file mode 100644 (file)
index 0000000..dde9cf0
--- /dev/null
@@ -0,0 +1,48 @@
+// -*- 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
index 55d81eecf50f7031438dc138a83381ab32280c3b..51d52dd5f8717b818192e04bf0b43f0cd921c461 100644 (file)
@@ -5,21 +5,10 @@
  *
  * \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"
@@ -1706,70 +1695,10 @@ 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);
 }
 
 
@@ -1897,7 +1826,6 @@ void PrefShortcuts::updateShortcutsTW()
        shortcutsTW->sortItems(0, Qt::AscendingOrder);
        QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
        removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
-       searchPB->setEnabled(!searchLE->text().isEmpty());
 }
 
 
@@ -2083,8 +2011,17 @@ void PrefShortcuts::on_removePB_pressed()
 }
 
 
-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);
@@ -2103,25 +2040,13 @@ void PrefShortcuts::on_searchPB_pressed()
 }
 
 
-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;
index 373f14d12717d0a3e32de24d81f28609d0f2095c..d80af4d8adaab00ecf4b345a7f7ad61fcf2f0ada 100644 (file)
@@ -349,24 +349,10 @@ public Q_SLOTS:
 };
 
 
-/**
- * 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;
 };
 
 
@@ -397,7 +383,6 @@ public Q_SLOTS:
        void select_bind();
        void on_newPB_pressed();
        void on_removePB_pressed();
-       void on_searchPB_pressed();
        void on_searchLE_textChanged();
        ///
        void on_shortcutsTW_itemSelectionChanged();
index 3a86a56117e0a43489952c9739d2056630d11830..b54681a41a83bf75cbf39c7305163f8b93b521ce 100644 (file)
@@ -59,6 +59,7 @@ SOURCEFILES = \
        BulletsModule.cpp \
        ButtonController.cpp \
        ColorCache.cpp \
+       CustomizedWidgets.cpp \
        Dialogs.cpp \
        EmptyTable.cpp \
        FileDialog.cpp \
@@ -151,6 +152,7 @@ MOCHEADER = \
        Action.h \
        BulletsModule.h \
        ColorCache.h \
+       CustomizedWidgets.h \
        DockView.h \
        EmptyTable.h \
        FloatPlacement.h \
index 49111e6e6169a98e4c886e9e68bd30d680d3fe5d..9854b4153904964ae8aaef30317062cfb94bb314 100644 (file)
@@ -27,7 +27,7 @@
    <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>
@@ -43,7 +43,7 @@
      </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>
index bf77d33c40f929a17d7259eb52d111bf4f40965d..f3571f5f6329290071ffc12243ceb6bc401062f8 100644 (file)
    <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>