From 824e24ca60c511e48d94b039ef3a04163b847d3a Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 16 Sep 2016 09:21:04 +0200 Subject: [PATCH] Citation dialog redesign --- src/frontends/qt4/GuiCitation.cpp | 157 +++++---- src/frontends/qt4/GuiCitation.h | 25 +- src/frontends/qt4/ui/CitationUi.ui | 506 ++++++++++++----------------- 3 files changed, 315 insertions(+), 373 deletions(-) diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index a99db88ed6..b294fd8a28 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -16,6 +16,7 @@ #include "GuiCitation.h" +#include "GuiApplication.h" #include "GuiSelectionManager.h" #include "LyXToolBox.h" #include "qt_helpers.h" @@ -34,6 +35,7 @@ #include "support/lstrings.h" #include +#include #include #include #include @@ -93,6 +95,35 @@ GuiCitation::GuiCitation(GuiView & lv) { setupUi(this); + // The filter bar + filter_ = new FancyLineEdit(this); +#if QT_VERSION >= 0x040600 + filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); + filter_->setButtonVisible(FancyLineEdit::Right, true); + filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text")); + filter_->setAutoHideButton(FancyLineEdit::Right, true); +#endif +#if QT_VERSION >= 0x040700 + filter_->setPlaceholderText(qt_("Filter available")); +#endif + + filterBarL->addWidget(filter_, 0); + findKeysLA->setBuddy(filter_); + + // Add search options as button menu + regexp_ = new QAction(qt_("Regular e&xpression"), this); + regexp_->setCheckable(true); + casesense_ = new QAction(qt_("Case se&nsitive"), this); + casesense_->setCheckable(true); + instant_ = new QAction(qt_("Search as you &type"), this); + instant_->setCheckable(true); + + QMenu * searchOpts = new QMenu(this); + searchOpts->addAction(regexp_); + searchOpts->addAction(casesense_); + searchOpts->addAction(instant_); + searchOptionsPB->setMenu(searchOpts); + connect(citationStyleCO, SIGNAL(activated(int)), this, SLOT(on_citationStyleCO_currentIndexChanged(int))); connect(fulllistCB, SIGNAL(clicked()), @@ -103,8 +134,6 @@ GuiCitation::GuiCitation(GuiView & lv) this, SLOT(updateStyles())); connect(textAfterED, SIGNAL(textChanged(QString)), this, SLOT(updateStyles())); - connect(findLE, SIGNAL(returnPressed()), - this, SLOT(on_searchPB_clicked())); connect(textBeforeED, SIGNAL(returnPressed()), this, SLOT(on_okPB_clicked())); connect(textAfterED, SIGNAL(returnPressed()), @@ -119,7 +148,20 @@ GuiCitation::GuiCitation(GuiView & lv) connect(selectionManager, SIGNAL(okHook()), this, SLOT(on_okPB_clicked())); - setFocusProxy(availableLV); + connect(filter_, SIGNAL(rightButtonClicked()), + this, SLOT(resetFilter())); + connect(filter_, SIGNAL(textEdited(QString)), + this, SLOT(filterChanged(QString))); + connect(filter_, SIGNAL(returnPressed()), + this, SLOT(filterPressed())); + connect(regexp_, SIGNAL(triggered()), + this, SLOT(regexChanged())); + connect(casesense_, SIGNAL(triggered()), + this, SLOT(caseChanged())); + connect(instant_, SIGNAL(triggered(bool)), + this, SLOT(instantChanged(bool))); + + setFocusProxy(filter_); } @@ -152,42 +194,12 @@ void GuiCitation::applyView() void GuiCitation::showEvent(QShowEvent * e) { - findLE->clear(); + filter_->clear(); availableLV->setFocus(); - - // Set the minimal size of the QToolbox. Without this, the size of the - // QToolbox is only determined by values in the ui file (e.g. computed by - // qtcreator) and therefore causes portability and localisation issues. Note - // that the page widgets must have a layout with layoutSizeContraint = - // SetMinimumSize or similar. KNOWN ISSUE: the calculations are incorrect - // the first time the dialog is shown. This problem is mitigated by the fact - // that LyX remembers the dialog sizes between sessions. - QSize minimum_size = QSize(0,0); - // Compute the max of the minimal sizes of the pages - QWidget * page; - for (int i = 0; (page = citationTB->widget(i)); ++i) - minimum_size = minimum_size.expandedTo(page->minimumSizeHint()); - // Add the height of the tabs - if (citationTB->currentWidget()) - minimum_size.rheight() += citationTB->height() - - citationTB->currentWidget()->height(); - citationTB->setMinimumSize(minimum_size); - DialogView::showEvent(e); } -void GuiCitation::on_citationTB_currentChanged(int i) -{ - if (i == 0) - findLE->setFocus(); - else if (citationStyleCO->isEnabled()) - citationStyleCO->setFocus(); - else - textAfterED->setFocus(); -} - - void GuiCitation::on_okPB_clicked() { applyView(); @@ -212,6 +224,7 @@ void GuiCitation::on_applyPB_clicked() void GuiCitation::on_restorePB_clicked() { init(); + updateFilterHint(); } @@ -390,8 +403,9 @@ void GuiCitation::findText(QString const & text, bool reset) else entry_type = entries[index]; - bool const case_sentitive = caseCB->checkState(); - bool const reg_exp = regexCB->checkState(); + bool const case_sentitive = casesense_->isChecked(); + bool const reg_exp = regexp_->isChecked(); + findKey(bi, text, onlyKeys, field, entry_type, case_sentitive, reg_exp, reset); //FIXME @@ -405,13 +419,13 @@ void GuiCitation::findText(QString const & text, bool reset) void GuiCitation::on_fieldsCO_currentIndexChanged(int /*index*/) { - findText(findLE->text(), true); + findText(filter_->text(), true); } void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/) { - findText(findLE->text(), true); + findText(filter_->text(), true); } @@ -425,43 +439,58 @@ void GuiCitation::on_citationStyleCO_currentIndexChanged(int index) } -void GuiCitation::on_findLE_textChanged(const QString & text) +void GuiCitation::filterChanged(const QString & text) { - bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked); - searchPB->setDisabled(text.isEmpty() || searchAsWeGo); if (!text.isEmpty()) { - if (searchAsWeGo) - findText(findLE->text()); + if (instant_->isChecked()) + findText(filter_->text()); return; } - findText(findLE->text()); - findLE->setFocus(); + findText(filter_->text()); + filter_->setFocus(); +} + + +void GuiCitation::filterPressed() +{ + findText(filter_->text(), true); } -void GuiCitation::on_searchPB_clicked() + +void GuiCitation::resetFilter() +{ + filter_->setText(QString()); + findText(filter_->text(), true); +} + + +void GuiCitation::caseChanged() { - findText(findLE->text(), true); + findText(filter_->text()); } -void GuiCitation::on_caseCB_stateChanged(int) +void GuiCitation::regexChanged() { - findText(findLE->text()); + findText(filter_->text()); } -void GuiCitation::on_regexCB_stateChanged(int) +void GuiCitation::updateFilterHint() { - findText(findLE->text()); + QString const hint = instant_->isChecked() ? + qt_("Enter the text to search for") : + qt_("Enter the text to search for and press Enter"); + filter_->setToolTip(hint); } -void GuiCitation::on_asTypeCB_stateChanged(int) +void GuiCitation::instantChanged(bool checked) { - bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked); - searchPB->setDisabled(findLE->text().isEmpty() || searchAsWeGo); - if (searchAsWeGo) - findText(findLE->text(), true); + if (checked) + findText(filter_->text(), true); + + updateFilterHint(); } @@ -786,11 +815,11 @@ void GuiCitation::saveSession() const Dialog::saveSession(); QSettings settings; settings.setValue( - sessionKey() + "/regex", regexCB->isChecked()); + sessionKey() + "/regex", regexp_->isChecked()); settings.setValue( - sessionKey() + "/casesensitive", caseCB->isChecked()); + sessionKey() + "/casesensitive", casesense_->isChecked()); settings.setValue( - sessionKey() + "/autofind", asTypeCB->isChecked()); + sessionKey() + "/autofind", instant_->isChecked()); } @@ -798,12 +827,10 @@ void GuiCitation::restoreSession() { Dialog::restoreSession(); QSettings settings; - regexCB->setChecked( - settings.value(sessionKey() + "/regex").toBool()); - caseCB->setChecked( - settings.value(sessionKey() + "/casesensitive").toBool()); - asTypeCB->setChecked( - settings.value(sessionKey() + "/autofind").toBool()); + regexp_->setChecked(settings.value(sessionKey() + "/regex").toBool()); + casesense_->setChecked(settings.value(sessionKey() + "/casesensitive").toBool()); + instant_->setChecked(settings.value(sessionKey() + "/autofind").toBool()); + updateFilterHint(); } diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index cc24eb9fc4..035b2d2e2a 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -17,6 +17,7 @@ #include "DialogView.h" #include "ui_CitationUi.h" +#include "FancyLineEdit.h" #include "insets/InsetCommandParams.h" @@ -44,19 +45,19 @@ public: ~GuiCitation(); private Q_SLOTS: - void on_citationTB_currentChanged(int i); void on_okPB_clicked(); void on_cancelPB_clicked(); void on_restorePB_clicked(); void on_applyPB_clicked(); - void on_searchPB_clicked(); - void on_findLE_textChanged(const QString & text); + void filterPressed(); + void filterChanged(const QString & text); void on_fieldsCO_currentIndexChanged(int index); void on_entriesCO_currentIndexChanged(int index); void on_citationStyleCO_currentIndexChanged(int index); - void on_caseCB_stateChanged(int); - void on_regexCB_stateChanged(int); - void on_asTypeCB_stateChanged(int); + void resetFilter(); + void caseChanged(); + void regexChanged(); + void instantChanged(bool checked); void changed(); /// set the citation keys, mark as changed void setCitedKeys(); @@ -106,6 +107,8 @@ private: void updateFormatting(CitationStyle currentStyle); /// void updateControls(BiblioInfo const & bi); + /// Set the appropriate hinting text on the filter bar + void updateFilterHint(); /// void init(); /// Clear selected keys @@ -151,6 +154,16 @@ private: /// the like, so it should be avoided. BiblioInfo const & bibInfo() const; + /// contains the search box + FancyLineEdit * filter_; + + /// Regexp action + QAction * regexp_; + /// Case sensitive action + QAction * casesense_; + /// Search as you type action + QAction * instant_; + /// last used citation style int style_; /// diff --git a/src/frontends/qt4/ui/CitationUi.ui b/src/frontends/qt4/ui/CitationUi.ui index 360d94150b..fec600dff0 100644 --- a/src/frontends/qt4/ui/CitationUi.ui +++ b/src/frontends/qt4/ui/CitationUi.ui @@ -6,7 +6,7 @@ 0 0 - 590 + 614 506 @@ -16,8 +16,84 @@ true - + + + + + + + + &Filter: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + + + + 0 + 0 + + + + 16 + + + QComboBox::NoInsert + + + QComboBox::AdjustToContents + + + + All fields + + + + + + + + + 0 + 0 + + + + QComboBox::NoInsert + + + QComboBox::AdjustToContents + + + + All entry types + + + + + + + + O&ptions + + + false + + + + + + @@ -104,8 +180,7 @@ - - + .. false @@ -128,8 +203,7 @@ - - + .. false @@ -143,7 +217,7 @@ - S&elected Citations: + Selected &Citations: selectedLV @@ -181,297 +255,127 @@ - - - - - 0 - 0 - - - - - - - 1 + + + + Formatting - - - &Search Citation - - - - QLayout::SetMinimumSize - - - - - Searc&h: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - findLE - - - - - - - Enter the text to search for and press Enter or click the button to search - - - - - - - - - - false - - - Click or press Enter in the search box to search - - - &Search - - - false - - - - - - - Search &field: - - - fieldsCO - - - - - - - - 0 - 0 - - - - 16 - - - QComboBox::NoInsert - - - QComboBox::AdjustToContents - - + + + + + - All fields + Citation st&yle: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Regular e&xpression - - - - - - - Case se&nsitive - - - - - - - Entry t&ypes: - - - entriesCO - - - - - - - - 0 - 0 - - - - QComboBox::NoInsert - - - QComboBox::AdjustToContents - - + + citationStyleCO + + + + + + + Natbib citation style to use + + + + + + + + + - All entry types + Text &before: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Search as you &type - - - - - - - - For&matting - - - - QLayout::SetMinimumSize - - - - - Citation st&yle: - - - citationStyleCO - - - - - - - Natbib citation style to use - - - - - - - Text &before: - - - textBeforeED - - - - - - - Text to place before citation - - - - - - - &Text after: - - - textAfterED - - - - - - - Text to place after citation - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 21 - 26 - - - - - - - - List all authors - - - &Full author list - - - - - - - Force upper case in citation - - - Force u&pper case - - - - - - - + + textBeforeED + + + + + + + Text to place before citation + + + + + + + &Text after: + + + textAfterED + + + + + + + Text to place after citation + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 21 + 26 + + + + + + + + Force upper case in citation + + + Force upcas&ing + + + + + + + List all authors + + + All aut&hors + + + + + + - + 6 @@ -548,28 +452,26 @@ - - - lyx::frontend::LyXToolBox - QToolBox -
LyXToolBox.h
- 1 -
-
+ fieldsCO + entriesCO + searchOptionsPB availableLV + selectedLV addPB deletePB upPB downPB - selectedLV - infoML - fulllistCB + citationStyleCO + textBeforeED + textAfterED forceuppercaseCB + fulllistCB restorePB okPB applyPB cancelPB + infoML qt_i18n.h -- 2.39.2