From e52c1ed1f90126b8ff3c5d2d6e95cb446b8e3e3f Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 25 Oct 2007 03:08:22 +0000 Subject: [PATCH] Properly extend qt standard widgets, remove the search button in PrefShortcuts. * 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 | 2 + src/frontends/qt4/CustomizedWidgets.cpp | 103 ++++++++++++++++++++++++ src/frontends/qt4/CustomizedWidgets.h | 48 +++++++++++ src/frontends/qt4/GuiPrefs.cpp | 97 +++------------------- src/frontends/qt4/GuiPrefs.h | 15 ---- src/frontends/qt4/Makefile.am | 2 + src/frontends/qt4/ui/PrefShortcutsUi.ui | 39 ++++----- src/frontends/qt4/ui/ShortcutUi.ui | 49 ++++++----- 8 files changed, 215 insertions(+), 140 deletions(-) create mode 100644 src/frontends/qt4/CustomizedWidgets.cpp create mode 100644 src/frontends/qt4/CustomizedWidgets.h diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 19b150b508..6586ba9b99 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -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 index 0000000000..d97c5a586e --- /dev/null +++ b/src/frontends/qt4/CustomizedWidgets.cpp @@ -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 + Copyright (C) 2001 Ellis Whitehead + Copyright (C) 2007 Andreas Hartmetz + Licensed under version 2 of the General Public License and + used here in accordance with the terms of that license. +*/ + +#include + +#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(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 index 0000000000..dde9cf0bea --- /dev/null +++ b/src/frontends/qt4/CustomizedWidgets.h @@ -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 +#include +#include + +/** + * 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 diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 55d81eecf5..51d52dd5f8 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -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 - Copyright (C) 2001 Ellis Whitehead - Copyright (C) 2007 Andreas Hartmetz - Licensed under version 2 of the General Public License and - used here in accordance with the terms of that license. -*/ - #include #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(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(7), static_cast(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 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 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; diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index 373f14d127..d80af4d8ad 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -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(); diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 3a86a56117..b54681a41a 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 \ diff --git a/src/frontends/qt4/ui/PrefShortcutsUi.ui b/src/frontends/qt4/ui/PrefShortcutsUi.ui index 49111e6e61..9854b41539 100644 --- a/src/frontends/qt4/ui/PrefShortcutsUi.ui +++ b/src/frontends/qt4/ui/PrefShortcutsUi.ui @@ -27,7 +27,7 @@ 6 - + Qt::Vertical @@ -43,7 +43,7 @@ - + Qt::Vertical @@ -59,22 +59,10 @@ - - - - - 1 - 0 - 0 - 0 - - - - - + @@ -115,15 +103,30 @@ - - + + + + + 1 + 0 + 0 + 0 + + - Search + Search ... + + + SearchLineEdit + QLineEdit +
CustomizedWidgets.h
+
+
bindFileED bindFilePB diff --git a/src/frontends/qt4/ui/ShortcutUi.ui b/src/frontends/qt4/ui/ShortcutUi.ui index bf77d33c40..f3571f5f63 100644 --- a/src/frontends/qt4/ui/ShortcutUi.ui +++ b/src/frontends/qt4/ui/ShortcutUi.ui @@ -30,27 +30,6 @@ 6 - - - - false - - - - 7 - 0 - 0 - 0 - - - - Enter BibTeX database name - - - - - - @@ -139,8 +118,36 @@
+ + + + true + + + + 13 + 13 + 0 + 0 + + + + Enter BibTeX database name + + + + + + + + + ShortcutLineEdit + QLineEdit +
CustomizedWidgets.h
+
+
lfunLE okPB -- 2.39.2