From d5483e355148aadc4887948ac5b7288dc37c9936 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 31 Aug 2007 22:37:05 +0000 Subject: [PATCH] somewhat more uniform naming git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19962 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/qmake/qt4/qt4.pro | 16 +- development/scons/scons_manifest.py | 16 +- po/POTFILES.in | 8 +- src/frontends/qt4/Dialogs.cpp | 7 +- src/frontends/qt4/GuiCitation.cpp | 428 ++++++++++++++++- src/frontends/qt4/GuiCitation.h | 81 ++++ src/frontends/qt4/GuiCitationDialog.cpp | 432 ------------------ src/frontends/qt4/GuiCitationDialog.h | 108 ----- ...uiDelimiterDialog.cpp => GuiDelimiter.cpp} | 8 +- .../{GuiDelimiterDialog.h => GuiDelimiter.h} | 0 ...MathMatrixDialog.cpp => GuiMathMatrix.cpp} | 6 +- ...{GuiMathMatrixDialog.h => GuiMathMatrix.h} | 0 .../qt4/{GuiURLDialog.cpp => GuiURL.cpp} | 7 +- .../qt4/{GuiURLDialog.h => GuiURL.h} | 0 src/frontends/qt4/Makefile.am | 14 +- 15 files changed, 534 insertions(+), 597 deletions(-) delete mode 100644 src/frontends/qt4/GuiCitationDialog.cpp delete mode 100644 src/frontends/qt4/GuiCitationDialog.h rename src/frontends/qt4/{GuiDelimiterDialog.cpp => GuiDelimiter.cpp} (98%) rename src/frontends/qt4/{GuiDelimiterDialog.h => GuiDelimiter.h} (100%) rename src/frontends/qt4/{GuiMathMatrixDialog.cpp => GuiMathMatrix.cpp} (96%) rename src/frontends/qt4/{GuiMathMatrixDialog.h => GuiMathMatrix.h} (100%) rename src/frontends/qt4/{GuiURLDialog.cpp => GuiURL.cpp} (96%) rename src/frontends/qt4/{GuiURLDialog.h => GuiURL.h} (100%) diff --git a/development/qmake/qt4/qt4.pro b/development/qmake/qt4/qt4.pro index ce046c1b6e..96a39bee12 100644 --- a/development/qmake/qt4/qt4.pro +++ b/development/qmake/qt4/qt4.pro @@ -30,12 +30,11 @@ HPP += GuiBranches.h HPP += GuiBranch.h HPP += GuiChanges.h HPP += GuiCharacter.h -HPP += GuiCitationDialog.h HPP += GuiCitation.h HPP += GuiClipboard.h HPP += GuiCommandBuffer.h HPP += GuiCommandEdit.h -HPP += GuiDelimiterDialog.h +HPP += GuiDelimiter.h HPP += GuiDialogView.h HPP += GuiDocument.h HPP += GuiErrorList.h @@ -53,7 +52,7 @@ HPP += GuiIndex.h HPP += GuiKeySymbol.h HPP += GuiListings.h HPP += GuiLog.h -HPP += GuiMathMatrixDialog.h +HPP += GuiMathMatrix.h HPP += GuiMenubar.h HPP += GuiNomencl.h HPP += GuiNote.h @@ -61,7 +60,6 @@ HPP += GuiPainter.h HPP += GuiParagraph.h HPP += GuiPopupMenu.h HPP += GuiPrefs.h -HPP += GuiPrintDialog.h HPP += GuiPrint.h HPP += GuiRef.h HPP += GuiSearch.h @@ -77,7 +75,7 @@ HPP += GuiTexinfo.h HPP += GuiThesaurus.h HPP += GuiToc.h HPP += GuiToolbar.h -HPP += GuiURLDialog.h +HPP += GuiURL.h HPP += GuiView.h HPP += GuiViewSource.h HPP += GuiVSpace.h @@ -115,11 +113,10 @@ CPP += GuiBranches.cpp CPP += GuiChanges.cpp CPP += GuiCharacter.cpp CPP += GuiCitation.cpp -CPP += GuiCitationDialog.cpp CPP += GuiClipboard.cpp CPP += GuiCommandBuffer.cpp CPP += GuiCommandEdit.cpp -CPP += GuiDelimiterDialog.cpp +CPP += GuiDelimiter.cpp CPP += GuiDialogView.cpp CPP += GuiDocument.cpp CPP += GuiErrorList.cpp @@ -137,7 +134,7 @@ CPP += GuiIndex.cpp CPP += GuiKeySymbol.cpp CPP += GuiListings.cpp CPP += GuiLog.cpp -CPP += GuiMathMatrixDialog.cpp +CPP += GuiMathMatrix.cpp CPP += GuiMenubar.cpp CPP += GuiNomencl.cpp CPP += GuiNote.cpp @@ -146,7 +143,6 @@ CPP += GuiParagraph.cpp CPP += GuiPopupMenu.cpp CPP += GuiPrefs.cpp CPP += GuiPrint.cpp -CPP += GuiPrintDialog.cpp CPP += GuiRef.cpp CPP += GuiSearch.cpp CPP += GuiSelection.cpp @@ -161,7 +157,7 @@ CPP += GuiTexinfo.cpp CPP += GuiThesaurus.cpp CPP += GuiToc.cpp CPP += GuiToolbar.cpp -CPP += GuiURLDialog.cpp +CPP += GuiURL.cpp CPP += GuiView.cpp CPP += GuiViewSource.cpp CPP += GuiVSpace.cpp diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 899dacd47c..49ab43ab4d 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -859,12 +859,11 @@ src_frontends_qt4_header_files = Split(''' GuiChanges.h GuiCharacter.h GuiCharacter.h - GuiCitationDialog.h GuiCitation.h GuiClipboard.h GuiCommandBuffer.h GuiCommandEdit.h - GuiDelimiterDialog.h + GuiDelimiter.h GuiDialogView.h GuiDocument.h GuiEmbeddedFiles.h @@ -883,7 +882,7 @@ src_frontends_qt4_header_files = Split(''' GuiKeySymbol.h GuiListings.h GuiLog.h - GuiMathMatrixDialog.h + GuiMathMatrix.h GuiMenubar.h GuiNomencl.h GuiNote.h @@ -891,7 +890,6 @@ src_frontends_qt4_header_files = Split(''' GuiParagraph.h GuiPopupMenu.h GuiPrefs.h - GuiPrintDialog.h GuiPrint.h GuiRef.h GuiSearch.h @@ -907,7 +905,7 @@ src_frontends_qt4_header_files = Split(''' GuiThesaurus.h GuiToc.h GuiToolbar.h - GuiURLDialog.h + GuiURL.h GuiView.h GuiViewSource.h GuiVSpace.h @@ -947,11 +945,10 @@ src_frontends_qt4_files = Split(''' GuiChanges.cpp GuiCharacter.cpp GuiCitation.cpp - GuiCitationDialog.cpp GuiClipboard.cpp GuiCommandBuffer.cpp GuiCommandEdit.cpp - GuiDelimiterDialog.cpp + GuiDelimiter.cpp GuiDialogView.cpp GuiDocument.cpp GuiEmbeddedFiles.cpp @@ -970,7 +967,7 @@ src_frontends_qt4_files = Split(''' GuiKeySymbol.cpp GuiListings.cpp GuiLog.cpp - GuiMathMatrixDialog.cpp + GuiMathMatrix.cpp GuiMenubar.cpp GuiNomencl.cpp GuiNote.cpp @@ -979,7 +976,6 @@ src_frontends_qt4_files = Split(''' GuiPopupMenu.cpp GuiPrefs.cpp GuiPrint.cpp - GuiPrintDialog.cpp GuiRef.cpp GuiSearch.cpp GuiSelection.cpp @@ -994,7 +990,7 @@ src_frontends_qt4_files = Split(''' GuiThesaurus.cpp GuiToc.cpp GuiToolbar.cpp - GuiURLDialog.cpp + GuiURL.cpp GuiView.cpp GuiViewSource.cpp GuiVSpace.cpp diff --git a/po/POTFILES.in b/po/POTFILES.in index b3b61268d2..bcd9d336a9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -59,9 +59,9 @@ src/frontends/qt4/GuiBranch.cpp src/frontends/qt4/GuiBranches.cpp src/frontends/qt4/GuiChanges.cpp src/frontends/qt4/GuiCharacter.cpp -src/frontends/qt4/GuiCitationDialog.cpp +src/frontends/qt4/GuiCitation.cpp src/frontends/qt4/GuiCommandBuffer.cpp -src/frontends/qt4/GuiDelimiterDialog.cpp +src/frontends/qt4/GuiDelimiter.cpp src/frontends/qt4/GuiDocument.cpp src/frontends/qt4/GuiERT.cpp src/frontends/qt4/GuiExternal.cpp @@ -69,7 +69,7 @@ src/frontends/qt4/GuiFloat.cpp src/frontends/qt4/GuiGraphics.cpp src/frontends/qt4/GuiInclude.cpp src/frontends/qt4/GuiListings.cpp -src/frontends/qt4/GuiMathMatrixDialog.cpp +src/frontends/qt4/GuiMathMatrix.cpp src/frontends/qt4/GuiNote.cpp src/frontends/qt4/GuiParagraph.cpp src/frontends/qt4/GuiPrefs.cpp @@ -83,12 +83,12 @@ src/frontends/qt4/GuiTabular.cpp src/frontends/qt4/GuiTabularCreate.cpp src/frontends/qt4/GuiTexinfo.cpp src/frontends/qt4/GuiThesaurus.cpp +src/frontends/qt4/GuiUrl.cpp src/frontends/qt4/GuiVSpace.cpp src/frontends/qt4/GuiView.cpp src/frontends/qt4/GuiWrap.cpp src/frontends/qt4/IconPalette.cpp src/frontends/qt4/Qt2BC.h -src/frontends/qt4/UrlView.cpp src/frontends/qt4/Validator.cpp src/frontends/qt4/alert_pimpl.cpp src/gettext.h diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 5a29b43883..918cd1e636 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -56,8 +56,7 @@ #include "GuiChanges.h" #include "GuiCharacter.h" #include "GuiCitation.h" -#include "GuiCitationDialog.h" -#include "GuiDelimiterDialog.h" +#include "GuiDelimiter.h" #include "GuiDocument.h" #include "GuiEmbeddedFiles.h" #include "GuiErrorList.h" @@ -67,7 +66,7 @@ #include "GuiGraphics.h" #include "GuiInclude.h" #include "GuiIndex.h" -#include "GuiMathMatrixDialog.h" +#include "GuiMathMatrix.h" #include "GuiNomencl.h" #include "GuiListings.h" #include "GuiLog.h" @@ -86,7 +85,7 @@ #include "GuiTexinfo.h" #include "GuiToc.h" #include "TocWidget.h" -#include "GuiURLDialog.h" +#include "GuiURL.h" #include "GuiVSpace.h" #include "GuiWrap.h" diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 84bc19e6ed..1bf47e6d80 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -6,7 +6,7 @@ * \author Angus Leeming * \author Kalle Dalheimer * \author Abdelrazak Younes - * \author Richard Heck (adapted to QSelectionManager) + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -15,21 +15,31 @@ #include "GuiCitation.h" +#include "debug.h" +#include "gettext.h" +#include "frontend_helpers.h" #include "qt_helpers.h" #include "support/lstrings.h" #include "support/docstring.h" -#include "debug.h" - #include #include +#include + +#undef KeyPress + +#include +#include +#include + using std::vector; using std::string; -template static QStringList to_qstring_list(vector const & v) +template +static QStringList to_qstring_list(vector const & v) { QStringList qlist; @@ -42,7 +52,7 @@ template static QStringList to_qstring_list(vector cons } -static vector const to_docstring_vector(QStringList const & qlist) +static vector to_docstring_vector(QStringList const & qlist) { vector v; for (int i = 0; i != qlist.size(); ++i) { @@ -57,6 +67,400 @@ static vector const to_docstring_vector(QStringList const & qlis namespace lyx { namespace frontend { +/////////////////////////////////////////////////////////////////////// +// +// GuiCitationDialog +// +/////////////////////////////////////////////////////////////////////// + + +GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form) + : Dialog::View(dialog, _("Citation")), form_(form) +{ + setupUi(this); + + setWindowTitle(toqstr("LyX: " + getTitle())); + + connect(citationStyleCO, SIGNAL(activated(int)), + this, SLOT(changed())); + connect(fulllistCB, SIGNAL(clicked()), + this, SLOT(changed())); + connect(forceuppercaseCB, SIGNAL(clicked()), + this, SLOT(changed())); + connect(textBeforeED, SIGNAL(textChanged(const QString&)), + this, SLOT(changed())); + connect(textAfterED, SIGNAL(textChanged(const QString&)), + this, SLOT(changed())); + connect(clearPB, SIGNAL(clicked()), + findLE, SLOT(clear())); + connect(this, SIGNAL(rejected()), this, SLOT(cleanUp())); + + selectionManager = + new GuiSelectionManager(availableLV, selectedLV, + addPB, deletePB, upPB, downPB, + form_->available(), form_->selected()); + connect(selectionManager, SIGNAL(selectionChanged()), + this, SLOT(setCitedKeys())); + connect(selectionManager, SIGNAL(updateHook()), + this, SLOT(updateDialog())); + connect(selectionManager, SIGNAL(okHook()), + this, SLOT(on_okPB_clicked())); + +} + + +GuiCitationDialog::~GuiCitationDialog() +{} + + +void GuiCitationDialog::cleanUp() +{ + form_->clearSelection(); + form_->clearParams(); + close(); +} + + +void GuiCitationDialog::closeEvent(QCloseEvent * e) +{ + form_->clearSelection(); + form_->clearParams(); + e->accept(); +} + + +void GuiCitationDialog::apply() +{ + int const choice = std::max(0, citationStyleCO->currentIndex()); + style_ = choice; + bool const full = fulllistCB->isChecked(); + bool const force = forceuppercaseCB->isChecked(); + + QString const before = textBeforeED->text(); + QString const after = textAfterED->text(); + + form_->apply(choice, full, force, before, after); +} + + +void GuiCitationDialog::hide() +{ + form_->clearParams(); + accept(); +} + + +void GuiCitationDialog::show() +{ + findLE->clear(); + availableLV->setFocus(); + QDialog::show(); + raise(); + activateWindow(); +} + + +bool GuiCitationDialog::isVisible() const +{ + return QDialog::isVisible(); +} + + +void GuiCitationDialog::on_okPB_clicked() +{ + apply(); + form_->clearSelection(); + hide(); +} + + +void GuiCitationDialog::on_cancelPB_clicked() +{ + form_->clearSelection(); + hide(); +} + + +void GuiCitationDialog::on_applyPB_clicked() +{ + apply(); +} + + +void GuiCitationDialog::on_restorePB_clicked() +{ + form_->init(); + update(); +} + + +void GuiCitationDialog::update() +{ + fillFields(); + fillEntries(); + updateDialog(); +} + + +//The main point of separating this out is that the fill*() methods +//called in update() do not need to be called for INTERNAL updates, +//such as when addPB is pressed, as the list of fields, entries, etc, +//will not have changed. At the moment, however, the division between +//fillStyles() and updateStyles() doesn't lend itself to dividing the +//two methods, though they should be divisible. +void GuiCitationDialog::updateDialog() +{ + if (selectionManager->selectedFocused()) { + if (selectedLV->selectionModel()->selectedIndexes().isEmpty()) + updateInfo(availableLV->currentIndex()); + else + updateInfo(selectedLV->currentIndex()); + } else { + if (availableLV->selectionModel()->selectedIndexes().isEmpty()) + updateInfo(QModelIndex()); + else + updateInfo(availableLV->currentIndex()); + } + setButtons(); + + textBeforeED->setText(form_->textBefore()); + textAfterED->setText(form_->textAfter()); + fillStyles(); + updateStyle(); +} + + +void GuiCitationDialog::updateStyle() +{ + biblio::CiteEngine const engine = form_->getEngine(); + bool const natbib_engine = + engine == biblio::ENGINE_NATBIB_AUTHORYEAR || + engine == biblio::ENGINE_NATBIB_NUMERICAL; + bool const basic_engine = engine == biblio::ENGINE_BASIC; + + bool const haveSelection = + selectedLV->model()->rowCount() > 0; + fulllistCB->setEnabled(natbib_engine && haveSelection); + forceuppercaseCB->setEnabled(natbib_engine && haveSelection); + textBeforeED->setEnabled(!basic_engine && haveSelection); + textBeforeLA->setEnabled(!basic_engine && haveSelection); + textAfterED->setEnabled(haveSelection); + textAfterLA->setEnabled(haveSelection); + citationStyleCO->setEnabled(!basic_engine && haveSelection); + citationStyleLA->setEnabled(!basic_engine && haveSelection); + + string const & command = form_->params().getCmdName(); + + // Find the style of the citekeys + vector const & styles = + ControlCitation::getCiteStyles(); + biblio::CitationStyle const cs(command); + + vector::const_iterator cit = + std::find(styles.begin(), styles.end(), cs.style); + + // restore the latest natbib style + if (style_ >= 0 && style_ < citationStyleCO->count()) + citationStyleCO->setCurrentIndex(style_); + else + citationStyleCO->setCurrentIndex(0); + + if (cit != styles.end()) { + int const i = int(cit - styles.begin()); + citationStyleCO->setCurrentIndex(i); + fulllistCB->setChecked(cs.full); + forceuppercaseCB->setChecked(cs.forceUCase); + } else { + fulllistCB->setChecked(false); + forceuppercaseCB->setChecked(false); + } +} + + +//This one needs to be called whenever citationStyleCO needs +//to be updated---and this would be on anything that changes the +//selection in selectedLV, or on a general update. +void GuiCitationDialog::fillStyles() +{ + int const oldIndex = citationStyleCO->currentIndex(); + + citationStyleCO->clear(); + + QStringList selected_keys = form_->selected()->stringList(); + if (selected_keys.empty()) { + citationStyleCO->setEnabled(false); + citationStyleLA->setEnabled(false); + return; + } + + int curr = selectedLV->model()->rowCount() - 1; + if (curr < 0) + return; + + if (!selectedLV->selectionModel()->selectedIndexes().empty()) + curr = selectedLV->selectionModel()->selectedIndexes()[0].row(); + + QStringList sty = form_->citationStyles(curr); + + bool const basic_engine = + (form_->getEngine() == biblio::ENGINE_BASIC); + + citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine); + citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine); + + if (sty.isEmpty() || basic_engine) + return; + + citationStyleCO->insertItems(0, sty); + + if (oldIndex != -1 && oldIndex < citationStyleCO->count()) + citationStyleCO->setCurrentIndex(oldIndex); +} + + +void GuiCitationDialog::fillFields() +{ + fieldsCO->blockSignals(true); + int const oldIndex = fieldsCO->currentIndex(); + fieldsCO->clear(); + QStringList const & fields = form_->getFieldsAsQStringList(); + fieldsCO->insertItem(0, qt_("All Fields")); + fieldsCO->insertItem(1, qt_("Keys")); + fieldsCO->insertItems(2, fields); + if (oldIndex != -1 && oldIndex < fieldsCO->count()) + fieldsCO->setCurrentIndex(oldIndex); + fieldsCO->blockSignals(false); +} + + +void GuiCitationDialog::fillEntries() +{ + entriesCO->blockSignals(true); + int const oldIndex = entriesCO->currentIndex(); + entriesCO->clear(); + QStringList const & entries = form_->getEntriesAsQStringList(); + entriesCO->insertItem(0, qt_("All Entry Types")); + entriesCO->insertItems(1, entries); + if (oldIndex != -1 && oldIndex < entriesCO->count()) + entriesCO->setCurrentIndex(oldIndex); + entriesCO->blockSignals(false); +} + + +bool GuiCitationDialog::isSelected(const QModelIndex & idx) +{ + QString const str = idx.data().toString(); + return form_->selected()->stringList().contains(str); +} + + +void GuiCitationDialog::setButtons() +{ + selectionManager->update(); + int const srows = selectedLV->model()->rowCount(); + applyPB->setEnabled(srows > 0); + okPB->setEnabled(srows > 0); +} + + +void GuiCitationDialog::updateInfo(QModelIndex const & idx) +{ + if (idx.isValid()) { + QString const keytxt = form_->getKeyInfo(idx.data().toString()); + infoML->document()->setPlainText(keytxt); + } else + infoML->document()->clear(); +} + + +void GuiCitationDialog::setCitedKeys() +{ + form_->setCitedKeys(); +} + + +void GuiCitationDialog::findText(QString const & text, bool reset) +{ + //"All Fields" and "Keys" are the first two + int index = fieldsCO->currentIndex() - 2; + vector const & fields = form_->availableFields(); + docstring field; + + if (index <= -1 || index >= int(fields.size())) + //either "All Fields" or "Keys" or an invalid value + field = from_ascii(""); + else + field = fields[index]; + + //Was it "Keys"? + bool const onlyKeys = index == -1; + + //"All Entry Types" is first. + index = entriesCO->currentIndex() - 1; + vector const & entries = form_->availableEntries(); + docstring entryType; + if (index < 0 || index >= int(entries.size())) + entryType = from_ascii(""); + else + entryType = entries[index]; + + bool const case_sentitive = caseCB->checkState(); + bool const reg_exp = regexCB->checkState(); + form_->findKey(text, onlyKeys, field, entryType, + case_sentitive, reg_exp, reset); + //FIXME + //It'd be nice to save and restore the current selection in + //availableLV. Currently, we get an automatic reset, since the + //model is reset. + + updateDialog(); +} + + +void GuiCitationDialog::on_fieldsCO_currentIndexChanged(int /*index*/) +{ + findText(findLE->text(), true); +} + + +void GuiCitationDialog::on_entriesCO_currentIndexChanged(int /*index*/) +{ + findText(findLE->text(), true); +} + + +void GuiCitationDialog::on_findLE_textChanged(const QString & text) +{ + clearPB->setDisabled(text.isEmpty()); + if (text.isEmpty()) + findLE->setFocus(); + findText(text); +} + + +void GuiCitationDialog::on_caseCB_stateChanged(int) +{ + findText(findLE->text()); +} + + +void GuiCitationDialog::on_regexCB_stateChanged(int) +{ + findText(findLE->text()); +} + + +void GuiCitationDialog::changed() +{ + fillStyles(); + setButtons(); +} + +/////////////////////////////////////////////////////////////////////// +// +// GuiCitation +// +/////////////////////////////////////////////////////////////////////// GuiCitation::GuiCitation(Dialog & parent) : ControlCitation(parent) @@ -166,8 +570,8 @@ void GuiCitation::findKey(QString const & str, bool only_keys, QStringList result; - //First, filter by entryType, which will be faster than - //what follows, so we may get to do that on less. + // First, filter by entryType, which will be faster than + // what follows, so we may get to do that on less. vector keyVector = to_docstring_vector(keys); filterByEntryType(keyVector, entryType); @@ -181,12 +585,14 @@ void GuiCitation::findKey(QString const & str, bool only_keys, } -QStringList GuiCitation::getFieldsAsQStringList() { +QStringList GuiCitation::getFieldsAsQStringList() +{ return to_qstring_list(availableFields()); } -QStringList GuiCitation::getEntriesAsQStringList() { +QStringList GuiCitation::getEntriesAsQStringList() +{ return to_qstring_list(availableEntries()); } @@ -208,6 +614,8 @@ void GuiCitation::setCitedKeys() cited_keys_ = selected_model_.stringList(); } - } // namespace frontend } // namespace lyx + +#include "GuiCitation_moc.cpp" + diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index 7059106ef8..573525cc31 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -15,15 +15,96 @@ #ifndef GUICITATION_H #define GUICITATION_H +#include "Dialog.h" +#include "GuiSelectionManager.h" +#include "ui_CitationUi.h" #include "ControlCitation.h" #include "support/docstring.h" +#include #include #include namespace lyx { namespace frontend { +class GuiCitation; + +class GuiCitationDialog : public QDialog, + public Ui::CitationUi, public Dialog::View +{ + Q_OBJECT + +public: + GuiCitationDialog(Dialog &, GuiCitation * form ); + + virtual ~GuiCitationDialog(); + + virtual void apply(); + + /// Hide the dialog from sight + void hide(); + + /// Redraw the dialog (e.g. if the colors have been remapped). + void redraw() {} + + /// Create the dialog if necessary, update it and display it. + void show(); + + /// \return true if the dialog is visible. + bool isVisible() const; + +public Q_SLOTS: + /// Update the display of the dialog whilst it is still visible. + void update(); + +protected: + void closeEvent(QCloseEvent * e); + /// prepares a call to GuiCitation::searchKeys when we + /// are ready to search the BibTeX entries + void findText(QString const & text, bool reset = false); + /// check whether key is already selected + bool isSelected(const QModelIndex &); + /// update the display of BibTeX information + void updateInfo(QModelIndex const &); + +protected Q_SLOTS: + void cleanUp(); + void on_okPB_clicked(); + void on_cancelPB_clicked(); + void on_restorePB_clicked(); + void on_applyPB_clicked(); + void on_findLE_textChanged(const QString & text); + void on_fieldsCO_currentIndexChanged(int index); + void on_entriesCO_currentIndexChanged(int index); + void on_caseCB_stateChanged(int); + void on_regexCB_stateChanged(int); + virtual void changed(); + /// + void setCitedKeys(); + /// performs a limited update, suitable for internal call + void updateDialog(); + +private: + /// enable/disable buttons + void setButtons(); + /// fill the styles combo + void fillStyles(); + /// fill the fields combo + void fillFields(); + /// fill the entries combo + void fillEntries(); + /// set the styles combo + void updateStyle(); + /// last used citation style + int style_; + + GuiCitation * form_; + + GuiSelectionManager * selectionManager; +}; + + class GuiCitation : public ControlCitation { public: diff --git a/src/frontends/qt4/GuiCitationDialog.cpp b/src/frontends/qt4/GuiCitationDialog.cpp deleted file mode 100644 index 4d2b50e564..0000000000 --- a/src/frontends/qt4/GuiCitationDialog.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/** - * \file GuiCitationDialog.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Kalle Dalheimer - * \author John Levon - * \author Jürgen Spitzmüller - * \author Abdelrazak Younes - * \author Richard Heck - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "GuiCitationDialog.h" - -#include "GuiCitation.h" - -#include "frontends/controllers/frontend_helpers.h" -#include "frontends/controllers/ControlCitation.h" -#include "qt_helpers.h" - -#include "support/docstring.h" - -#include "debug.h" -#include "gettext.h" - -#include -#include -#include - -#include -#include - -#undef KeyPress - -using std::vector; -using std::string; - -namespace lyx { -namespace frontend { - - -GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form) - : Dialog::View(dialog, _("Citation")), form_(form) -{ - setupUi(this); - - setWindowTitle(toqstr("LyX: " + getTitle())); - - connect(citationStyleCO, SIGNAL(activated(int)), - this, SLOT(changed())); - connect(fulllistCB, SIGNAL(clicked()), - this, SLOT(changed())); - connect(forceuppercaseCB, SIGNAL(clicked()), - this, SLOT(changed())); - connect(textBeforeED, SIGNAL(textChanged(const QString&)), - this, SLOT(changed())); - connect(textAfterED, SIGNAL(textChanged(const QString&)), - this, SLOT(changed())); - connect(clearPB, SIGNAL(clicked()), - findLE, SLOT(clear())); - connect(this, SIGNAL(rejected()), this, SLOT(cleanUp())); - - selectionManager = - new GuiSelectionManager(availableLV, selectedLV, - addPB, deletePB, upPB, downPB, - form_->available(), form_->selected()); - connect(selectionManager, SIGNAL(selectionChanged()), - this, SLOT(setCitedKeys())); - connect(selectionManager, SIGNAL(updateHook()), - this, SLOT(updateDialog())); - connect(selectionManager, SIGNAL(okHook()), - this, SLOT(on_okPB_clicked())); - -} - - -GuiCitationDialog::~GuiCitationDialog() -{} - - -void GuiCitationDialog::cleanUp() -{ - form_->clearSelection(); - form_->clearParams(); - close(); -} - - -void GuiCitationDialog::closeEvent(QCloseEvent * e) -{ - form_->clearSelection(); - form_->clearParams(); - e->accept(); -} - - -void GuiCitationDialog::apply() -{ - int const choice = std::max(0, citationStyleCO->currentIndex()); - style_ = choice; - bool const full = fulllistCB->isChecked(); - bool const force = forceuppercaseCB->isChecked(); - - QString const before = textBeforeED->text(); - QString const after = textAfterED->text(); - - form_->apply(choice, full, force, before, after); -} - - -void GuiCitationDialog::hide() -{ - form_->clearParams(); - accept(); -} - - -void GuiCitationDialog::show() -{ - findLE->clear(); - availableLV->setFocus(); - QDialog::show(); - raise(); - activateWindow(); -} - - -bool GuiCitationDialog::isVisible() const -{ - return QDialog::isVisible(); -} - - -void GuiCitationDialog::on_okPB_clicked() -{ - apply(); - form_->clearSelection(); - hide(); -} - - -void GuiCitationDialog::on_cancelPB_clicked() -{ - form_->clearSelection(); - hide(); -} - - -void GuiCitationDialog::on_applyPB_clicked() -{ - apply(); -} - - -void GuiCitationDialog::on_restorePB_clicked() -{ - form_->init(); - update(); -} - - -void GuiCitationDialog::update() -{ - fillFields(); - fillEntries(); - updateDialog(); -} - - -//The main point of separating this out is that the fill*() methods -//called in update() do not need to be called for INTERNAL updates, -//such as when addPB is pressed, as the list of fields, entries, etc, -//will not have changed. At the moment, however, the division between -//fillStyles() and updateStyles() doesn't lend itself to dividing the -//two methods, though they should be divisible. -void GuiCitationDialog::updateDialog() -{ - if (selectionManager->selectedFocused()) { - if (selectedLV->selectionModel()->selectedIndexes().isEmpty()) - updateInfo(availableLV->currentIndex()); - else - updateInfo(selectedLV->currentIndex()); - } else { - if (availableLV->selectionModel()->selectedIndexes().isEmpty()) - updateInfo(QModelIndex()); - else - updateInfo(availableLV->currentIndex()); - } - setButtons(); - - textBeforeED->setText(form_->textBefore()); - textAfterED->setText(form_->textAfter()); - fillStyles(); - updateStyle(); -} - - -void GuiCitationDialog::updateStyle() -{ - biblio::CiteEngine const engine = form_->getEngine(); - bool const natbib_engine = - engine == biblio::ENGINE_NATBIB_AUTHORYEAR || - engine == biblio::ENGINE_NATBIB_NUMERICAL; - bool const basic_engine = engine == biblio::ENGINE_BASIC; - - bool const haveSelection = - selectedLV->model()->rowCount() > 0; - fulllistCB->setEnabled(natbib_engine && haveSelection); - forceuppercaseCB->setEnabled(natbib_engine && haveSelection); - textBeforeED->setEnabled(!basic_engine && haveSelection); - textBeforeLA->setEnabled(!basic_engine && haveSelection); - textAfterED->setEnabled(haveSelection); - textAfterLA->setEnabled(haveSelection); - citationStyleCO->setEnabled(!basic_engine && haveSelection); - citationStyleLA->setEnabled(!basic_engine && haveSelection); - - string const & command = form_->params().getCmdName(); - - // Find the style of the citekeys - vector const & styles = - ControlCitation::getCiteStyles(); - biblio::CitationStyle const cs(command); - - vector::const_iterator cit = - std::find(styles.begin(), styles.end(), cs.style); - - // restore the latest natbib style - if (style_ >= 0 && style_ < citationStyleCO->count()) - citationStyleCO->setCurrentIndex(style_); - else - citationStyleCO->setCurrentIndex(0); - - if (cit != styles.end()) { - int const i = int(cit - styles.begin()); - citationStyleCO->setCurrentIndex(i); - fulllistCB->setChecked(cs.full); - forceuppercaseCB->setChecked(cs.forceUCase); - } else { - fulllistCB->setChecked(false); - forceuppercaseCB->setChecked(false); - } -} - - -//This one needs to be called whenever citationStyleCO needs -//to be updated---and this would be on anything that changes the -//selection in selectedLV, or on a general update. -void GuiCitationDialog::fillStyles() -{ - int const oldIndex = citationStyleCO->currentIndex(); - - citationStyleCO->clear(); - - QStringList selected_keys = form_->selected()->stringList(); - if (selected_keys.empty()) { - citationStyleCO->setEnabled(false); - citationStyleLA->setEnabled(false); - return; - } - - int curr = selectedLV->model()->rowCount() - 1; - if (curr < 0) - return; - - if (!selectedLV->selectionModel()->selectedIndexes().empty()) - curr = selectedLV->selectionModel()->selectedIndexes()[0].row(); - - QStringList sty = form_->citationStyles(curr); - - bool const basic_engine = - (form_->getEngine() == biblio::ENGINE_BASIC); - - citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine); - citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine); - - if (sty.isEmpty() || basic_engine) - return; - - citationStyleCO->insertItems(0, sty); - - if (oldIndex != -1 && oldIndex < citationStyleCO->count()) - citationStyleCO->setCurrentIndex(oldIndex); -} - - -void GuiCitationDialog::fillFields() -{ - fieldsCO->blockSignals(true); - int const oldIndex = fieldsCO->currentIndex(); - fieldsCO->clear(); - QStringList const & fields = form_->getFieldsAsQStringList(); - fieldsCO->insertItem(0, qt_("All Fields")); - fieldsCO->insertItem(1, qt_("Keys")); - fieldsCO->insertItems(2, fields); - if (oldIndex != -1 && oldIndex < fieldsCO->count()) - fieldsCO->setCurrentIndex(oldIndex); - fieldsCO->blockSignals(false); -} - - -void GuiCitationDialog::fillEntries() -{ - entriesCO->blockSignals(true); - int const oldIndex = entriesCO->currentIndex(); - entriesCO->clear(); - QStringList const & entries = form_->getEntriesAsQStringList(); - entriesCO->insertItem(0, qt_("All Entry Types")); - entriesCO->insertItems(1, entries); - if (oldIndex != -1 && oldIndex < entriesCO->count()) - entriesCO->setCurrentIndex(oldIndex); - entriesCO->blockSignals(false); -} - - -bool GuiCitationDialog::isSelected(const QModelIndex & idx) -{ - QString const str = idx.data().toString(); - return form_->selected()->stringList().contains(str); -} - - -void GuiCitationDialog::setButtons() -{ - selectionManager->update(); - int const srows = selectedLV->model()->rowCount(); - applyPB->setEnabled(srows > 0); - okPB->setEnabled(srows > 0); -} - - -void GuiCitationDialog::updateInfo(QModelIndex const & idx) -{ - if (idx.isValid()) { - QString const keytxt = form_->getKeyInfo(idx.data().toString()); - infoML->document()->setPlainText(keytxt); - } else - infoML->document()->clear(); -} - - -void GuiCitationDialog::setCitedKeys() -{ - form_->setCitedKeys(); -} - - -void GuiCitationDialog::findText(QString const & text, bool reset) -{ - //"All Fields" and "Keys" are the first two - int index = fieldsCO->currentIndex() - 2; - vector const & fields = form_->availableFields(); - docstring field; - - if (index <= -1 || index >= int(fields.size())) - //either "All Fields" or "Keys" or an invalid value - field = from_ascii(""); - else - field = fields[index]; - - //Was it "Keys"? - bool const onlyKeys = index == -1; - - //"All Entry Types" is first. - index = entriesCO->currentIndex() - 1; - vector const & entries = form_->availableEntries(); - docstring entryType; - if (index < 0 || index >= int(entries.size())) - entryType = from_ascii(""); - else - entryType = entries[index]; - - bool const case_sentitive = caseCB->checkState(); - bool const reg_exp = regexCB->checkState(); - form_->findKey(text, onlyKeys, field, entryType, - case_sentitive, reg_exp, reset); - //FIXME - //It'd be nice to save and restore the current selection in - //availableLV. Currently, we get an automatic reset, since the - //model is reset. - - updateDialog(); -} - - -void GuiCitationDialog::on_fieldsCO_currentIndexChanged(int /*index*/) -{ - findText(findLE->text(), true); -} - - -void GuiCitationDialog::on_entriesCO_currentIndexChanged(int /*index*/) -{ - findText(findLE->text(), true); -} - - -void GuiCitationDialog::on_findLE_textChanged(const QString & text) -{ - clearPB->setDisabled(text.isEmpty()); - if (text.isEmpty()) - findLE->setFocus(); - findText(text); -} - - -void GuiCitationDialog::on_caseCB_stateChanged(int) -{ - findText(findLE->text()); -} - - -void GuiCitationDialog::on_regexCB_stateChanged(int) -{ - findText(findLE->text()); -} - - -void GuiCitationDialog::changed() -{ - fillStyles(); - setButtons(); -} - - -} // namespace frontend -} // namespace lyx - -#include "GuiCitationDialog_moc.cpp" diff --git a/src/frontends/qt4/GuiCitationDialog.h b/src/frontends/qt4/GuiCitationDialog.h deleted file mode 100644 index d4e5050629..0000000000 --- a/src/frontends/qt4/GuiCitationDialog.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- -/** - * \file GuiCitationDialog.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Kalle Dalheimer - * \author Abdelrazak Younes - * \author Richard Heck - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef GUICITATIONDIALOG_H -#define GUICITATIONDIALOG_H - -#include "Dialog.h" -#include "GuiSelectionManager.h" -#include "ui_CitationUi.h" - -#include -#include -#include -#include - -namespace lyx { -namespace frontend { - -class GuiCitation; - -class GuiCitationDialog : public QDialog, - public Ui::CitationUi, public Dialog::View -{ - Q_OBJECT - -public: - GuiCitationDialog(Dialog &, GuiCitation * form ); - - virtual ~GuiCitationDialog(); - - virtual void apply(); - - /// Hide the dialog from sight - void hide(); - - /// Redraw the dialog (e.g. if the colors have been remapped). - void redraw() {} - - /// Create the dialog if necessary, update it and display it. - void show(); - - /// \return true if the dialog is visible. - bool isVisible() const; - -public Q_SLOTS: - /// Update the display of the dialog whilst it is still visible. - void update(); - -protected: - void closeEvent (QCloseEvent * e); - /// prepares a call to GuiCitation::searchKeys when we - /// are ready to search the BibTeX entries - void findText(QString const & text, bool reset = false); - /// check whether key is already selected - bool isSelected(const QModelIndex &); - /// update the display of BibTeX information - void updateInfo(QModelIndex const &); - -protected Q_SLOTS: - void cleanUp(); - void on_okPB_clicked(); - void on_cancelPB_clicked(); - void on_restorePB_clicked(); - void on_applyPB_clicked(); - void on_findLE_textChanged(const QString & text); - void on_fieldsCO_currentIndexChanged(int index); - void on_entriesCO_currentIndexChanged(int index); - void on_caseCB_stateChanged(int); - void on_regexCB_stateChanged(int); - virtual void changed(); - /// - void setCitedKeys(); - /// performs a limited update, suitable for internal call - void updateDialog(); - -private: - /// enable/disable buttons - void setButtons(); - /// fill the styles combo - void fillStyles(); - /// fill the fields combo - void fillFields(); - /// fill the entries combo - void fillEntries(); - /// set the styles combo - void updateStyle(); - /// last used citation style - int style_; - - GuiCitation * form_; - - GuiSelectionManager * selectionManager; -}; - -} // namespace frontend -} // namespace lyx - -#endif // GUICITATIOINDIALOG_H diff --git a/src/frontends/qt4/GuiDelimiterDialog.cpp b/src/frontends/qt4/GuiDelimiter.cpp similarity index 98% rename from src/frontends/qt4/GuiDelimiterDialog.cpp rename to src/frontends/qt4/GuiDelimiter.cpp index a9690aafe8..40eb280d0f 100644 --- a/src/frontends/qt4/GuiDelimiterDialog.cpp +++ b/src/frontends/qt4/GuiDelimiter.cpp @@ -1,5 +1,5 @@ /** - * \file GuiDelimiterDialog.cpp + * \file GuiDelimiter.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,7 +10,7 @@ #include -#include "GuiDelimiterDialog.h" +#include "GuiDelimiter.h" #include "GuiApplication.h" #include "GuiView.h" @@ -22,8 +22,6 @@ #include #include -#include - // Set to zero if unicode symbols are preferred. #define USE_PIXMAP 1 @@ -248,4 +246,4 @@ void GuiDelimiterDialog::on_matchCB_stateChanged(int state) } // namespace frontend } // namespace lyx -#include "GuiDelimiterDialog_moc.cpp" +#include "GuiDelimiter_moc.cpp" diff --git a/src/frontends/qt4/GuiDelimiterDialog.h b/src/frontends/qt4/GuiDelimiter.h similarity index 100% rename from src/frontends/qt4/GuiDelimiterDialog.h rename to src/frontends/qt4/GuiDelimiter.h diff --git a/src/frontends/qt4/GuiMathMatrixDialog.cpp b/src/frontends/qt4/GuiMathMatrix.cpp similarity index 96% rename from src/frontends/qt4/GuiMathMatrixDialog.cpp rename to src/frontends/qt4/GuiMathMatrix.cpp index ba88f541a6..5a83b0d09d 100644 --- a/src/frontends/qt4/GuiMathMatrixDialog.cpp +++ b/src/frontends/qt4/GuiMathMatrix.cpp @@ -1,5 +1,5 @@ /** - * \file GuiMathMatrixDialog.cpp + * \file GuiMathMatrix.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,7 +10,7 @@ #include -#include "GuiMathMatrixDialog.h" +#include "GuiMathMatrix.h" #include "EmptyTable.h" #include "qt_helpers.h" @@ -121,4 +121,4 @@ void GuiMathMatrixDialog::slotClose() } // namespace frontend } // namespace lyx -#include "GuiMathMatrixDialog_moc.cpp" +#include "GuiMathMatrix_moc.cpp" diff --git a/src/frontends/qt4/GuiMathMatrixDialog.h b/src/frontends/qt4/GuiMathMatrix.h similarity index 100% rename from src/frontends/qt4/GuiMathMatrixDialog.h rename to src/frontends/qt4/GuiMathMatrix.h diff --git a/src/frontends/qt4/GuiURLDialog.cpp b/src/frontends/qt4/GuiURL.cpp similarity index 96% rename from src/frontends/qt4/GuiURLDialog.cpp rename to src/frontends/qt4/GuiURL.cpp index 2728fa2a58..518987cfa1 100644 --- a/src/frontends/qt4/GuiURLDialog.cpp +++ b/src/frontends/qt4/GuiURL.cpp @@ -1,5 +1,5 @@ /** - * \file GuiURLDialog.cpp + * \file GuiURL.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,7 +10,7 @@ #include -#include "GuiURLDialog.h" +#include "GuiURL.h" #include "Qt2BC.h" #include "qt_helpers.h" #include "ButtonController.h" @@ -111,4 +111,5 @@ bool UrlView::isValid() } // namespace frontend } // namespace lyx -#include "GuiURLDialog_moc.cpp" + +#include "GuiURL_moc.cpp" diff --git a/src/frontends/qt4/GuiURLDialog.h b/src/frontends/qt4/GuiURL.h similarity index 100% rename from src/frontends/qt4/GuiURLDialog.h rename to src/frontends/qt4/GuiURL.h diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index c331f7f0b8..2835115028 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -54,11 +54,10 @@ SOURCEFILES = \ GuiChanges.cpp \ GuiCharacter.cpp \ GuiCitation.cpp \ - GuiCitationDialog.cpp \ GuiClipboard.cpp \ GuiCommandBuffer.cpp \ GuiCommandEdit.cpp \ - GuiDelimiterDialog.cpp \ + GuiDelimiter.cpp \ GuiDialogView.cpp \ GuiDocument.cpp \ GuiEmbeddedFiles.cpp \ @@ -78,7 +77,7 @@ SOURCEFILES = \ GuiKeySymbol.cpp \ GuiListings.cpp \ GuiLog.cpp \ - GuiMathMatrixDialog.cpp \ + GuiMathMatrix.cpp \ GuiMenubar.cpp \ GuiNomencl.cpp \ GuiNote.cpp \ @@ -101,7 +100,7 @@ SOURCEFILES = \ GuiThesaurus.cpp \ GuiToc.cpp \ GuiToolbar.cpp \ - GuiURLDialog.cpp \ + GuiURL.cpp \ GuiView.cpp \ GuiViewSource.cpp \ GuiVSpace.cpp \ @@ -146,11 +145,10 @@ MOCHEADER = \ GuiBranch.h \ GuiChanges.h \ GuiCharacter.h \ - GuiCitationDialog.h \ GuiCitation.h \ GuiCommandBuffer.h \ GuiCommandEdit.h \ - GuiDelimiterDialog.h \ + GuiDelimiter.h \ GuiDialogView.h \ GuiDocument.h \ GuiEmbeddedFiles.h \ @@ -166,7 +164,7 @@ MOCHEADER = \ GuiKeySymbol.h \ GuiListings.h \ GuiLog.h \ - GuiMathMatrixDialog.h \ + GuiMathMatrix.h \ GuiMenubar.h \ GuiNomencl.h \ GuiNote.h \ @@ -187,7 +185,7 @@ MOCHEADER = \ GuiThesaurus.h \ GuiToc.h \ GuiToolbar.h \ - GuiURLDialog.h \ + GuiURL.h \ GuiView.h \ GuiViewSource.h \ GuiVSpace.h \ -- 2.39.2