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
This commit is contained in:
Bo Peng 2007-10-25 03:08:22 +00:00
parent f4cc71b7dd
commit e52c1ed1f9
8 changed files with 242 additions and 167 deletions

View File

@ -742,6 +742,7 @@ src_frontends_qt4_header_files = Split('''
BulletsModule.h BulletsModule.h
ButtonController.h ButtonController.h
ColorCache.h ColorCache.h
CustomizedWidgets.h
DialogView.h DialogView.h
DockView.h DockView.h
EmptyTable.h EmptyTable.h
@ -831,6 +832,7 @@ src_frontends_qt4_files = Split('''
BulletsModule.cpp BulletsModule.cpp
ButtonController.cpp ButtonController.cpp
ColorCache.cpp ColorCache.cpp
CustomizedWidgets.cpp
Dialogs.cpp Dialogs.cpp
EmptyTable.cpp EmptyTable.cpp
FileDialog.cpp FileDialog.cpp

View File

@ -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"

View File

@ -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

View File

@ -5,21 +5,10 @@
* *
* \author John Levon * \author John Levon
* \author Bo Peng * \author Bo Peng
* \author Edwin Leuven
* *
* Full author contact details are available in file CREDITS. * 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 <config.h>
#include "GuiPrefs.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) GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
{ {
Ui::shortcutUi::setupUi(this); Ui::shortcutUi::setupUi(this);
QDialog::setModal(true); 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); shortcutsTW->sortItems(0, Qt::AscendingOrder);
QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems(); QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty()); 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 // search both columns
QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(), QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0); 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() void PrefShortcuts::shortcut_okPB_pressed()
{ {
string shortcut = fromqstr(shortcut_->shortcutLE->text()); string shortcut = fromqstr(shortcut_->shortcutLE->text());
string lfun = fromqstr(shortcut_->lfunLE->text()); string lfun = fromqstr(shortcut_->lfunLE->text());
FuncRequest func = lyxaction.lookupFunc(lfun); 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"), Alert::error(_("Failed to create shortcut"),
_("Unknown or invalid LyX function")); _("Unknown or invalid LyX function"));
return; return;

View 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 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
{ {
public: public:
GuiShortcutDialog(QWidget * parent); GuiShortcutDialog(QWidget * parent);
ShortcutEdit * shortcutLE;
}; };
@ -397,7 +383,6 @@ public Q_SLOTS:
void select_bind(); void select_bind();
void on_newPB_pressed(); void on_newPB_pressed();
void on_removePB_pressed(); void on_removePB_pressed();
void on_searchPB_pressed();
void on_searchLE_textChanged(); void on_searchLE_textChanged();
/// ///
void on_shortcutsTW_itemSelectionChanged(); void on_shortcutsTW_itemSelectionChanged();

View File

@ -59,6 +59,7 @@ SOURCEFILES = \
BulletsModule.cpp \ BulletsModule.cpp \
ButtonController.cpp \ ButtonController.cpp \
ColorCache.cpp \ ColorCache.cpp \
CustomizedWidgets.cpp \
Dialogs.cpp \ Dialogs.cpp \
EmptyTable.cpp \ EmptyTable.cpp \
FileDialog.cpp \ FileDialog.cpp \
@ -151,6 +152,7 @@ MOCHEADER = \
Action.h \ Action.h \
BulletsModule.h \ BulletsModule.h \
ColorCache.h \ ColorCache.h \
CustomizedWidgets.h \
DockView.h \ DockView.h \
EmptyTable.h \ EmptyTable.h \
FloatPlacement.h \ FloatPlacement.h \

View File

@ -27,54 +27,42 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<item row="8" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>51</width>
<height>83</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>51</width>
<height>83</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="2" > <item row="6" column="2" >
<widget class="QLineEdit" name="searchLE" > <spacer>
<property name="sizePolicy" > <property name="orientation" >
<sizepolicy> <enum>Qt::Vertical</enum>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</widget> <property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>51</width>
<height>83</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>51</width>
<height>83</height>
</size>
</property>
</spacer>
</item> </item>
<item row="0" column="1" > <item row="0" column="1" >
<widget class="QLineEdit" name="bindFileED" /> <widget class="QLineEdit" name="bindFileED" />
</item> </item>
<item rowspan="7" row="2" column="0" colspan="2" > <item rowspan="5" row="2" column="0" colspan="2" >
<widget class="QTreeWidget" name="shortcutsTW" /> <widget class="QTreeWidget" name="shortcutsTW" />
</item> </item>
<item row="3" column="2" > <item row="3" column="2" >
@ -115,15 +103,30 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="2" > <item row="5" column="2" >
<widget class="QPushButton" name="searchPB" > <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" > <property name="text" >
<string>Search</string> <string>Search ...</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>SearchLineEdit</class>
<extends>QLineEdit</extends>
<header>CustomizedWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>bindFileED</tabstop> <tabstop>bindFileED</tabstop>
<tabstop>bindFilePB</tabstop> <tabstop>bindFilePB</tabstop>

View File

@ -30,27 +30,6 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </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" > <item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="lfunLE" > <widget class="QLineEdit" name="lfunLE" >
<property name="sizePolicy" > <property name="sizePolicy" >
@ -139,8 +118,36 @@
</item> </item>
</layout> </layout>
</item> </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> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ShortcutLineEdit</class>
<extends>QLineEdit</extends>
<header>CustomizedWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>lfunLE</tabstop> <tabstop>lfunLE</tabstop>
<tabstop>okPB</tabstop> <tabstop>okPB</tabstop>