From 2f415cfbb132b2124616c7e0e2990a1907ca280e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 25 Mar 2006 21:26:09 +0000 Subject: [PATCH] This new citation dialog follows a new design similar to lyx-1.3: - two panes for Selected/Available keys - find as you search (Regular expression are supported) - advanced search button There are a lot of work still: - selected citations are not inserted in the document - find does not select the found key - the graying/un-graying of buttons does not work properly - the Advanced Search Dialog (which will search inside the citation) is not done yet - ... But the good news is that I have used the Model/View separation of Qt4. QCitation contains the list models and QCitationDialog contains the list views. The idea would be to reuse the model for a new dialog, I am thinking of a simple combo box placed on the toolbar which insert citations with default style, etc. Or a context menu insert->citation... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13496 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/QCitation.C | 280 ++++----- src/frontends/qt4/QCitation.h | 42 +- src/frontends/qt4/QCitationDialog.C | 465 +++++++++----- src/frontends/qt4/QCitationDialog.h | 81 ++- src/frontends/qt4/QLToolbar.C | 2 +- src/frontends/qt4/ui/QCitationFindUi.ui | 545 ++++++++--------- src/frontends/qt4/ui/QCitationUi.ui | 775 ++++++++++++------------ 7 files changed, 1204 insertions(+), 986 deletions(-) diff --git a/src/frontends/qt4/QCitation.C b/src/frontends/qt4/QCitation.C index 9b9313ca10..17e31a7019 100644 --- a/src/frontends/qt4/QCitation.C +++ b/src/frontends/qt4/QCitation.C @@ -13,7 +13,6 @@ #include "QCitation.h" #include "QCitationDialog.h" -#include "ui/QCitationFindUi.h" #include "Qt2BC.h" #include "qt_helpers.h" @@ -24,218 +23,185 @@ #include "support/lstrings.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +using std::cout; +using std::endl; -using std::find; -using std::string; using std::vector; +using std::string; -namespace lyx { +void toQStringList(QStringList & qlist, vector const & v) +{ + qlist.clear(); + for (size_t i=0; i != v.size(); ++i) { + if (v[i].empty()) + continue; + qlist.append(toqstr(v[i])); + } +} + +void toVector(vector & v, const QStringList & qlist) +{ + v.clear(); -using support::getStringFromVector; -using support::getVectorFromString; -using support::trim; + for (size_t i=0; i != qlist.size(); ++i) + v.push_back(fromqstr(qlist[i])); +} +namespace lyx { namespace frontend { typedef QController > base_class; + QCitation::QCitation(Dialog & parent) : base_class(parent, _("Citation")) -{} +{ +} void QCitation::apply() { - vector const & styles = - ControlCitation::getCiteStyles(); + InsetCommandParams & params = controller().params(); + dialog_->update(params); - int const choice = dialog_->citationStyleCO->currentItem(); - bool const full = dialog_->fulllistCB->isChecked(); - bool const force = dialog_->forceuppercaseCB->isChecked(); + params.setContents(fromqstr(selected_keys_.stringList().join("'"))); +} + + +void QCitation::build_dialog() +{ + dialog_.reset(new QCitationDialog(this)); +} - string const command = - biblio::CitationStyle(styles[choice], full, force) - .asLatexStr(); - controller().params().setCmdName(command); - controller().params().setContents(getStringFromVector(citekeys)); +void QCitation::update_contents() +{ + QStringList keys; + + // Make the list of all available bibliography keys + toQStringList(keys, + biblio::getKeys(controller().bibkeysInfo())); + available_keys_.setStringList(keys); - string const before = fromqstr(dialog_->textBeforeED->text()); - controller().params().setSecOptions(before); + // Ditto for the keys cited in this inset + QString str = toqstr(controller().params().getContents()); + if (!str.isEmpty()) { + keys = str.split(","); + selected_keys_.setStringList(keys); + } - string const after = fromqstr(dialog_->textAfterED->text()); - controller().params().setOptions(after); + dialog_->update(controller().params()); - style_ = choice; - open_find_ = false; + bc().valid(isValid()); } - void QCitation::hide() { - citekeys.clear(); - bibkeys.clear(); - open_find_ = true; - QDialogView::hide(); } - -void QCitation::build_dialog() +bool QCitation::isValid() { - dialog_.reset(new QCitationDialog(this)); - - // Manage the ok, apply, restore and cancel/close buttons - bcview().setOK(dialog_->okPB); - bcview().setApply(dialog_->applyPB); - bcview().setCancel(dialog_->closePB); - bcview().setRestore(dialog_->restorePB); - - bcview().addReadOnly(dialog_->addPB); - bcview().addReadOnly(dialog_->deletePB); - bcview().addReadOnly(dialog_->upPB); - bcview().addReadOnly(dialog_->downPB); - bcview().addReadOnly(dialog_->citationStyleCO); - bcview().addReadOnly(dialog_->forceuppercaseCB); - bcview().addReadOnly(dialog_->fulllistCB); - bcview().addReadOnly(dialog_->textBeforeED); - bcview().addReadOnly(dialog_->textAfterED); - - open_find_ = true; + return selected_keys_.rowCount() > 0; } - -void QCitation::fillStyles() +QModelIndex QCitation::findKey(QString const & str, QModelIndex const & index) const { - if (citekeys.empty()) { - dialog_->citationStyleCO->setEnabled(false); - dialog_->citationStyleLA->setEnabled(false); - return; - } - - int const orig = dialog_->citationStyleCO->currentItem(); - - dialog_->citationStyleCO->clear(); - - int curr = dialog_->selectedLB->currentItem(); - if (curr < 0) - curr = 0; + QStringList const avail = available_keys_.stringList(); + int const pos = avail.indexOf(str, index.row()); + if (pos == -1) + return index; + return available_keys_.index(pos); +} - string key = citekeys[curr]; +QModelIndex QCitation::findKey(QString const & str) const +{ + QStringList const avail = available_keys_.stringList(); + int const pos = avail.indexOf(str); + if (pos == -1) + return QModelIndex(); + return available_keys_.index(pos); +} - vector const & sty = controller().getCiteStrings(key); +void QCitation::addKeys(QModelIndexList const & indexes) +{ + // = selectionModel->selectedIndexes(); - biblio::CiteEngine const engine = controller().getEngine(); - bool const basic_engine = engine == biblio::ENGINE_BASIC; + QModelIndex index; - dialog_->citationStyleCO->setEnabled(!sty.empty() && !basic_engine); - dialog_->citationStyleLA->setEnabled(!sty.empty() && !basic_engine); + if (indexes.empty()) + return; - for (vector::const_iterator it = sty.begin(); - it != sty.end(); ++it) { - dialog_->citationStyleCO->insertItem(toqstr(*it)); + QStringList keys = selected_keys_.stringList(); + + foreach(index, indexes) { + if (keys.indexOf(index.data().toString()) == -1) + keys.append(index.data().toString()); } - if (orig != -1 && orig < dialog_->citationStyleCO->count()) - dialog_->citationStyleCO->setCurrentItem(orig); + selected_keys_.setStringList(keys); + + changed(); } - -void QCitation::updateStyle() +void QCitation::deleteKeys(QModelIndexList const & indexes) { - biblio::CiteEngine const engine = controller().getEngine(); - bool const natbib_engine = - engine == biblio::ENGINE_NATBIB_AUTHORYEAR || - engine == biblio::ENGINE_NATBIB_NUMERICAL; - bool const basic_engine = engine == biblio::ENGINE_BASIC; - - dialog_->fulllistCB->setEnabled(natbib_engine); - dialog_->forceuppercaseCB->setEnabled(natbib_engine); - dialog_->textBeforeED->setEnabled(!basic_engine); - - string const & command = controller().params().getCmdName(); - - // Find the style of the citekeys - vector const & styles = - ControlCitation::getCiteStyles(); - biblio::CitationStyle const cs(command); - - vector::const_iterator cit = - find(styles.begin(), styles.end(), cs.style); - - // restore the latest natbib style - if (style_ >= 0 && style_ < dialog_->citationStyleCO->count()) - dialog_->citationStyleCO->setCurrentItem(style_); - else - dialog_->citationStyleCO->setCurrentItem(0); - dialog_->fulllistCB->setChecked(false); - dialog_->forceuppercaseCB->setChecked(false); - - if (cit != styles.end()) { - int const i = int(cit - styles.begin()); - dialog_->citationStyleCO->setCurrentItem(i); - dialog_->fulllistCB->setChecked(cs.full); - dialog_->forceuppercaseCB->setChecked(cs.forceUCase); + QModelIndex index; + + if (indexes.empty()) + return; + + QStringList keys = selected_keys_.stringList(); + + foreach(index, indexes) { + int const pos = keys.indexOf(index.data().toString()); + if (pos != -1) + keys.removeAt(pos); } -} + selected_keys_.setStringList(keys); + + changed(); +} -void QCitation::update_contents() +void QCitation::upKey(QModelIndexList const & indexes) { - // Make the list of all available bibliography keys - bibkeys = biblio::getKeys(controller().bibkeysInfo()); - updateBrowser(dialog_->ui_.availableLB, bibkeys); - - // Ditto for the keys cited in this inset - citekeys = getVectorFromString(controller().params().getContents()); - updateBrowser(dialog_->selectedLB, citekeys); + if (indexes.empty() || indexes.size() > 1) + return; - // No keys have been selected yet, so... - dialog_->infoML->clear(); - dialog_->setButtons(); + int pos = indexes[0].row(); + if (pos < 1) + return; - dialog_->textBeforeED->setText( - toqstr(controller().params().getSecOptions())); - dialog_->textAfterED->setText( - toqstr(controller().params().getOptions())); + QStringList keys = selected_keys_.stringList(); + keys.swap(pos, pos-1); + selected_keys_.setStringList(keys); + + changed(); +} - fillStyles(); - updateStyle(); +void QCitation::downKey(QModelIndexList const & indexes) +{ + if (indexes.empty() || indexes.size() > 1) + return; - // open the find dialog if nothing has been selected (yet) - // the bool prevents that this is also done after "apply" - if (open_find_) - dialog_->openFind(); + int pos = indexes[0].row(); + if (pos >= selected_keys_.rowCount() - 1) + return; - bc().valid(isValid()); + QStringList keys = selected_keys_.stringList(); + keys.swap(pos, pos+1); + selected_keys_.setStringList(keys); + + changed(); } -void QCitation::updateBrowser(Q3ListBox * browser, - vector const & keys) const -{ - browser->clear(); - - for (vector::const_iterator it = keys.begin(); - it < keys.end(); ++it) { - string const key = trim(*it); - // FIXME: why the .empty() test ? - if (!key.empty()) - browser->insertItem(toqstr(key)); - } -} -bool QCitation::isValid() -{ - return dialog_->selectedLB->count() > 0; -} } // namespace frontend diff --git a/src/frontends/qt4/QCitation.h b/src/frontends/qt4/QCitation.h index ba788e5f18..3b52393376 100644 --- a/src/frontends/qt4/QCitation.h +++ b/src/frontends/qt4/QCitation.h @@ -14,9 +14,8 @@ #define QCITATION_H #include "QDialogView.h" -#include -class Q3ListBox; +#include namespace lyx { namespace frontend { @@ -31,8 +30,27 @@ public: friend class QCitationDialog; /// QCitation(Dialog &); + + QStringListModel * available() + { return &available_keys_; } + + QStringListModel * selected() + { return &selected_keys_; } + + QStringListModel * found() + { return &found_keys_; } + + QModelIndex findKey(QString const & str, QModelIndex const & index) const; + QModelIndex findKey(QString const & str) const; + + void addKeys(QModelIndexList const & indexes); + void deleteKeys(QModelIndexList const & indexes); + void upKey(QModelIndexList const & indexes); + void downKey(QModelIndexList const & indexes); + protected: virtual bool isValid(); + private: /// Set the Params variable for the Controller. @@ -44,22 +62,14 @@ private: /// Update dialog before/whilst showing it. virtual void update_contents(); - /// fill the styles combo - void fillStyles(); - - /// set the styles combo - void updateStyle(); - - void updateBrowser(Q3ListBox *, std::vector const &) const; - /// check if apply has been pressed - bool open_find_; + /// available keys + QStringListModel available_keys_; /// selected keys - std::vector citekeys; - /// available bib keys - std::vector bibkeys; - /// selected natbib style - int style_; + QStringListModel selected_keys_; + + /// found keys + QStringListModel found_keys_; }; } // namespace frontend diff --git a/src/frontends/qt4/QCitationDialog.C b/src/frontends/qt4/QCitationDialog.C index b4968b60ce..92d513d6cc 100644 --- a/src/frontends/qt4/QCitationDialog.C +++ b/src/frontends/qt4/QCitationDialog.C @@ -15,29 +15,53 @@ #include "QCitationDialog.h" #include "ui/QCitationFindUi.h" #include "QCitation.h" +#include "Qt2BC.h" #include "qt_helpers.h" +#include "bufferparams.h" + #include "controllers/ControlCitation.h" #include "controllers/ButtonController.h" -#include -#include -#include -#include -#include +#include "support/lstrings.h" +#include +using std::cout; +using std::endl; -using std::vector; +using std::find; using std::string; +using std::vector; + namespace lyx { + +using support::getStringFromVector; +using support::getVectorFromString; +using support::trim; + namespace frontend { +void updateBrowser(Q3ListBox * browser, + vector const & keys) +{ + browser->clear(); + + for (vector::const_iterator it = keys.begin(); + it < keys.end(); ++it) { + string const key = trim(*it); + // FIXME: why the .empty() test ? + if (!key.empty()) + browser->insertItem(toqstr(key)); + } +} + QCitationDialog::QCitationDialog(QCitation * form) : form_(form) { setupUi(this); - connect(restorePB, SIGNAL(clicked()), + +/* connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); @@ -45,263 +69,402 @@ QCitationDialog::QCitationDialog(QCitation * form) form, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); +*/ + // Manage the ok, apply, restore and cancel/close buttons + form_->bcview().setOK(okPB); + form_->bcview().setApply(applyPB); + form_->bcview().setCancel(closePB); + form_->bcview().setRestore(restorePB); + + form_->bcview().addReadOnly(addPB); + form_->bcview().addReadOnly(deletePB); + form_->bcview().addReadOnly(upPB); + form_->bcview().addReadOnly(downPB); + form_->bcview().addReadOnly(citationStyleCO); + form_->bcview().addReadOnly(forceuppercaseCB); + form_->bcview().addReadOnly(fulllistCB); + form_->bcview().addReadOnly(textBeforeED); + form_->bcview().addReadOnly(textAfterED); + + selectedLV->setModel(form_->selected()); + availableLV->setModel(form_->available()); + +// foundLV.setModel(form_->found()); + + 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() ) ); + + +// find_ = new QCitationFind(form_, this); + +// connect(selectedLV, SIGNAL(doubleClicked(const QModelIndex & index)), +// form_, SLOT(on_okPB_clicked()));//SLOT(slotOK())); +} - connect( citationStyleCO, SIGNAL( activated(int) ), this, SLOT( changed_adaptor() ) ); - connect( fulllistCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) ); - connect( forceuppercaseCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) ); - connect( textBeforeED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) ); - connect( textAfterED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) ); - connect( upPB, SIGNAL( clicked() ), this, SLOT( up() ) ); - connect( downPB, SIGNAL( clicked() ), this, SLOT( down() ) ); - connect( selectedLB, SIGNAL( currentChanged(QListBoxItem*) ), this, SLOT( selectedChanged() ) ); - connect( addPB, SIGNAL( clicked() ), this, SLOT( add() ) ); - connect( deletePB, SIGNAL( clicked() ), this, SLOT( del() ) ); - - add_ = new QDialog(this, "", true); - ui_.setupUi(add_); - - connect( ui_.addPB, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( ui_.closePB, SIGNAL( clicked() ), this, SLOT( reject() ) ); - - connect(ui_.previousPB, SIGNAL(clicked()), this, SLOT(previous())); - connect(ui_.nextPB, SIGNAL(clicked()), this, SLOT(next())); - connect(ui_.availableLB, SIGNAL(currentChanged(Q3ListBoxItem *)), this, SLOT(availableChanged())); - connect(ui_.availableLB, SIGNAL(selected(Q3ListBoxItem *)), this, SLOT(addCitation())); - connect(ui_.availableLB, SIGNAL(selected(Q3ListBoxItem *)), add_, SLOT(accept())); - connect(ui_.addPB, SIGNAL(clicked()), this, SLOT(addCitation())); - connect(selectedLB, SIGNAL(returnPressed(Q3ListBoxItem *)), form, SLOT(slotOK())); +QCitationDialog::~QCitationDialog() +{ } -QCitationDialog::~QCitationDialog() +void QCitationDialog::on_okPB_clicked() { + apply(form_->controller().params()); + accept(); } +void QCitationDialog::on_cancelPB_clicked() +{ + reject(); +} -void QCitationDialog::setButtons() +void QCitationDialog::on_applyPB_clicked() { - if (form_->readOnly()) - return; + apply(form_->controller().params()); +} + +void QCitationDialog::on_restorePB_clicked() +{ + form_->update_contents(); +} - int const sel_nr = selectedLB->currentItem(); - int const avail_nr = ui_.availableLB->currentItem(); +void QCitationDialog::apply(InsetCommandParams & params) +{ + vector const & styles = + ControlCitation::getCiteStyles(); - ui_.addPB->setEnabled(avail_nr >= 0); - deletePB->setEnabled(sel_nr >= 0); - upPB->setEnabled(sel_nr > 0); - downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1)); + int const choice = std::max(0, citationStyleCO->currentItem()); + bool const full = fulllistCB->isChecked(); + bool const force = forceuppercaseCB->isChecked(); + + string const command = + biblio::CitationStyle(styles[choice], full, force) + .asLatexStr(); + + params.setCmdName(command); + + string const before = fromqstr(textBeforeED->text()); + params.setSecOptions(before); + + string const after = fromqstr(textAfterED->text()); + params.setOptions(after); + + style_ = choice; } -void QCitationDialog::openFind() +void QCitationDialog::update(InsetCommandParams const & params) { - if (form_->readOnly()) - return; + // No keys have been selected yet, so... + infoML->document()->clear(); + setButtons(); + + textBeforeED->setText( + toqstr(params.getSecOptions())); + textAfterED->setText( + toqstr(params.getOptions())); - if (isVisible() && selectedLB->count() == 0 - && ui_.availableLB->count() != 0){ - // open the find dialog - add(); - // and let the user press ok after a selection - if (selectedLB->count() != 0) - form_->bc().valid(); + fillStyles(); + updateStyle(); + +// find_->update(); +} + +void QCitationDialog::updateStyle() +{ + biblio::CiteEngine const engine = form_->controller().getEngine(); + bool const natbib_engine = + engine == biblio::ENGINE_NATBIB_AUTHORYEAR || + engine == biblio::ENGINE_NATBIB_NUMERICAL; + bool const basic_engine = engine == biblio::ENGINE_BASIC; + + fulllistCB->setEnabled(natbib_engine); + forceuppercaseCB->setEnabled(natbib_engine); + textBeforeED->setEnabled(!basic_engine); + + string const & command = form_->controller().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->setCurrentItem(style_); + else + citationStyleCO->setCurrentItem(0); + fulllistCB->setChecked(false); + forceuppercaseCB->setChecked(false); + + if (cit != styles.end()) { + int const i = int(cit - styles.begin()); + citationStyleCO->setCurrentItem(i); + fulllistCB->setChecked(cs.full); + forceuppercaseCB->setChecked(cs.forceUCase); } } -void QCitationDialog::selectedChanged() +void QCitationDialog::fillStyles() { - form_->fillStyles(); - biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); - infoML->clear(); + if (citekeys.empty()) { + citationStyleCO->setEnabled(false); + citationStyleLA->setEnabled(false); + return; + } - int const sel = selectedLB->currentItem(); - if (sel < 0) { - setButtons(); + int const orig = citationStyleCO->currentItem(); + + citationStyleCO->clear(); + + QStringList selected_keys = form_->selected()->stringList(); + if (selected_keys.empty()) return; + + if (selectedLV->selectionModel()->selectedIndexes().empty()) + return; + + int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem(); + + string key = fromqstr(selected_keys[curr]); + + vector const & sty = form_->controller().getCiteStrings(key); + + biblio::CiteEngine const engine = form_->controller().getEngine(); + bool const basic_engine = engine == biblio::ENGINE_BASIC; + + citationStyleCO->setEnabled(!sty.empty() && !basic_engine); + citationStyleLA->setEnabled(!sty.empty() && !basic_engine); + + for (vector::const_iterator it = sty.begin(); + it != sty.end(); ++it) { + citationStyleCO->insertItem(toqstr(*it)); } - if (!theMap.empty()) - infoML->setText( - toqstr(biblio::getInfo(theMap, form_->citekeys[sel]))); - setButtons(); + if (orig != -1 && orig < citationStyleCO->count()) + citationStyleCO->setCurrentItem(orig); } -void QCitationDialog::previous() +void QCitationDialog::setButtons() { - find(biblio::BACKWARD); -} + if (form_->readOnly()) + return; + int const row_count = selectedLV->model()->rowCount(); -void QCitationDialog::next() -{ - find(biblio::FORWARD); -} + int sel_nr=-1; + if (! selectedLV->selectionModel()->selectedIndexes().empty()) { + sel_nr = + selectedLV->selectionModel()->selectedIndexes()[0].row(); + } + deletePB->setEnabled(sel_nr >= 0); + upPB->setEnabled(sel_nr > 0); + downPB->setEnabled(sel_nr >= 0 && sel_nr < row_count - 1); +} -void QCitationDialog::availableChanged() +/* +void QCitationDialog::on_selectedLV_currentChanged(Q3ListBoxItem*) { - biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); - ui_.infoML->clear(); + fillStyles(); + infoML->document()->clear(); - int const sel = ui_.availableLB->currentItem(); + int const sel = selectedLB->currentItem(); if (sel < 0) { setButtons(); return; } - if (!theMap.empty()) - ui_.infoML->setText( - toqstr(biblio::getInfo(theMap, form_->bibkeys[sel]))); + infoML->document()->setPlainText(form_->getKeyInfo(sel)); + setButtons(); } +*/ -void QCitationDialog::addCitation() +void QCitationDialog::on_addPB_clicked() { - int const sel = ui_.availableLB->currentItem(); + form_->addKeys(availableLV->selectionModel()->selectedIndexes()); +} - if (sel < 0) - return; +void QCitationDialog::on_deletePB_clicked() +{ + form_->addKeys(selectedLV->selectionModel()->selectedIndexes()); + changed(); +} - // Add the selected browser_bib keys to browser_cite - // multiple selections are possible - for (unsigned int i = 0; i != ui_.availableLB->count(); i++) { - if (ui_.availableLB->isSelected(i)) { - // do not allow duplicates - if ((selectedLB->findItem(ui_.availableLB->text(i))) == 0) { - selectedLB->insertItem(toqstr(form_->bibkeys[i])); - form_->citekeys.push_back(form_->bibkeys[i]); - } - } - } - int const n = int(form_->citekeys.size()); - selectedLB->setSelected(n - 1, true); +void QCitationDialog::on_upPB_clicked() +{ + form_->upKey(selectedLV->selectionModel()->selectedIndexes()); + changed(); +} + - form_->changed(); - form_->fillStyles(); - setButtons(); +void QCitationDialog::on_downPB_clicked() +{ + form_->downKey(selectedLV->selectionModel()->selectedIndexes()); + changed(); } +void QCitationDialog::on_findLE_textChanged(const QString & text) +{ + QModelIndex const index = form_->findKey(text); + if (! index.isValid()) + return; +// QItemSelection selection(index, index); + availableLV->selectionModel()->select(index, QItemSelectionModel::Select); + changed(); +} -void QCitationDialog::del() +void QCitationDialog::on_advancedSearchPB_clicked() { - int const sel = selectedLB->currentItem(); +// find_->exec(); + changed(); +} - // Remove the selected key from browser_cite - selectedLB->removeItem(sel); - form_->citekeys.erase(form_->citekeys.begin() + sel); - form_->changed(); - form_->fillStyles(); +void QCitationDialog::changed() +{ + fillStyles(); setButtons(); } -void QCitationDialog::up() + +QCitationFind::QCitationFind(QCitation * form, QWidget * parent, Qt::WFlags f) +: form_(form), QDialog(parent, f) { - int const sel = selectedLB->currentItem(); + setupUi(this); + connect(addPB, SIGNAL(clicked()), this, SLOT(accept())); + connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); + connect(previousPB, SIGNAL(clicked()), this, SLOT(previous())); + connect(nextPB, SIGNAL(clicked()), this, SLOT(next())); +} - // Move the selected key up one line - vector::iterator it = form_->citekeys.begin() + sel; - string const tmp = *it; +void QCitationFind::update() +{ +// updateBrowser(availableLB, form_->availableKeys()); +} - selectedLB->removeItem(sel); - form_->citekeys.erase(it); +void QCitationFind::on_availableLB_currentChanged(Q3ListBoxItem *) +{ + infoML->document()->clear(); - selectedLB->insertItem(toqstr(tmp), sel - 1); - selectedLB->setSelected(sel - 1, true); - form_->citekeys.insert(it - 1, tmp); + int const sel = availableLB->currentItem(); + if (sel < 0) { + addPB->setEnabled(false); + return; + } - form_->changed(); - form_->fillStyles(); - setButtons(); + addPB->setEnabled(true); +// infoML->document()->setPlainText(form_->getKeyInfo(sel)); } -void QCitationDialog::down() +void QCitationFind::on_availableLB_selected(Q3ListBoxItem *) { - int const sel = selectedLB->currentItem(); + int const sel = availableLB->currentItem(); + foundkeys.clear(); +// foundkeys.push_back(form_->availableKeys()[sel]); + emit newCitations(); + accept(); +} - // Move the selected key down one line - vector::iterator it = form_->citekeys.begin() + sel; - string const tmp = *it; +void QCitationFind::on_addPB_clicked() +{ +// form_->addKeys(availableLB->selectionModel()->selectedIndexes()); - selectedLB->removeItem(sel); - form_->citekeys.erase(it); + int const sel = availableLB->currentItem(); - selectedLB->insertItem(toqstr(tmp), sel + 1); - selectedLB->setSelected(sel + 1, true); - form_->citekeys.insert(it + 1, tmp); + if (sel < 0) + return; - form_->changed(); - form_->fillStyles(); - setButtons(); + QStringList bibkeys = form_->available()->stringList(); + + // Add the selected browser_bib keys to browser_cite + // multiple selections are possible + for (unsigned int i = 0; i != availableLB->count(); i++) { + if (availableLB->isSelected(i)) { + foundkeys.push_back(fromqstr(bibkeys[i])); + } + } + + emit newCitations(); + accept(); } -void QCitationDialog::add() +void QCitationFind::previous() { - add_->exec(); + find(biblio::BACKWARD); } -void QCitationDialog::changed_adaptor() +void QCitationFind::next() { - form_->changed(); + find(biblio::FORWARD); } -void QCitationDialog::find(biblio::Direction dir) +void QCitationFind::find(biblio::Direction dir) { +/* QStringList bibkeys = form_->available()->stringList(); + biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); - biblio::Search const type = ui_.searchTypeCB->isChecked() + biblio::Search const type = searchTypeCB->isChecked() ? biblio::REGEX : biblio::SIMPLE; - vector::const_iterator start = form_->bibkeys.begin(); - int const sel = ui_.availableLB->currentItem(); - if (sel >= 0 && sel <= int(form_->bibkeys.size()-1)) + vector::const_iterator start = bibkeys.begin(); + int const sel = availableLB->currentItem(); + if (sel >= 0 && sel <= int(bibkeys.size()-1)) start += sel; // Find the NEXT instance... if (dir == biblio::FORWARD) start += 1; - bool const casesens = ui_.searchCaseCB->isChecked(); - string const str = fromqstr(ui_.searchED->text()); + bool const casesens = searchCaseCB->isChecked(); + string const str = fromqstr(searchED->text()); vector::const_iterator cit = - biblio::searchKeys(theMap, form_->bibkeys, str, + biblio::searchKeys(theMap, bibkeys, str, start, type, dir, casesens); // not found. let's loop round - if (cit == form_->bibkeys.end()) { + if (cit == bibkeys.end()) { if (dir == biblio::FORWARD) { - start = form_->bibkeys.begin(); + start = bibkeys.begin(); } - else start = form_->bibkeys.end() - 1; + else start = bibkeys.end() - 1; - cit = biblio::searchKeys(theMap, form_->bibkeys, str, + cit = biblio::searchKeys(theMap, bibkeys, str, start, type, dir, casesens); - if (cit == form_->bibkeys.end()) + if (cit == bibkeys.end()) return; } - int const found = int(cit - form_->bibkeys.begin()); + int const found = int(cit - bibkeys.begin()); if (found == sel) { return; } // Update the display // note that we have multi selection mode! - ui_.availableLB->setSelected(sel, false); - ui_.availableLB->setSelected(found, true); - ui_.availableLB->setCurrentItem(found); - ui_.availableLB->ensureCurrentVisible(); + availableLB->setSelected(sel, false); + availableLB->setSelected(found, true); + availableLB->setCurrentItem(found); + availableLB->ensureCurrentVisible(); +*/ } } // namespace frontend diff --git a/src/frontends/qt4/QCitationDialog.h b/src/frontends/qt4/QCitationDialog.h index 712fcc8150..0eb96da84e 100644 --- a/src/frontends/qt4/QCitationDialog.h +++ b/src/frontends/qt4/QCitationDialog.h @@ -15,12 +15,20 @@ #include "ui/QCitationUi.h" #include "ui/QCitationFindUi.h" #include "controllers/biblio.h" + #include +#include + +class Q3ListBox; +class Q3ListBoxItem; + +class InsetCommandParams; namespace lyx { namespace frontend { class QCitation; +class QCitationFind; class QCitationDialog : public QDialog, public Ui::QCitationUi { Q_OBJECT @@ -30,29 +38,82 @@ public: ~QCitationDialog(); + void update(InsetCommandParams const & params); + void apply(InsetCommandParams & params); + +// virtual bool isValid(); + +protected slots: + +// void on_selectedLB_currentChanged(Q3ListBoxItem*); + + void on_okPB_clicked(); + void on_cancelPB_clicked(); + void on_restorePB_clicked(); + void on_applyPB_clicked(); + void on_addPB_clicked(); + + void on_deletePB_clicked(); + void on_upPB_clicked(); + void on_downPB_clicked(); + void on_findLE_textChanged(const QString & text); + void on_advancedSearchPB_clicked(); + + virtual void changed(); + +private: void setButtons(); /// open the find dialog if nothing selected void openFind(); - Ui::QCitationFindUi ui_; - QDialog * add_; + /// fill the styles combo + void fillStyles(); + + /// set the styles combo + void updateStyle(); + + /// check if apply has been pressed + bool open_find_; + + /// selected keys + std::vector citekeys; + + /// selected natbib style + int style_; + + QCitation * form_; + QCitationFind * find_; +}; + + +class QCitationFind: public QDialog, public Ui::QCitationFindUi { + Q_OBJECT + +public: + QCitationFind(QCitation * form, QWidget * parent = 0, Qt::WFlags f = 0); + + void update(); + + std::vector const & foundCitations() + { return foundkeys; } + +signals: + void newCitations(); protected slots: - virtual void availableChanged(); - virtual void selectedChanged(); - virtual void up(); - virtual void down(); - virtual void del(); - virtual void addCitation(); - virtual void add(); + void on_availableLB_currentChanged(Q3ListBoxItem *); + void on_availableLB_selected(Q3ListBoxItem *); + void on_addPB_clicked(); virtual void previous(); virtual void next(); - virtual void changed_adaptor(); private: void find(biblio::Direction dir); + /// selected keys + std::vector foundkeys; + QCitation * form_; }; diff --git a/src/frontends/qt4/QLToolbar.C b/src/frontends/qt4/QLToolbar.C index 46325af00a..d8b4dd2ef9 100644 --- a/src/frontends/qt4/QLToolbar.C +++ b/src/frontends/qt4/QLToolbar.C @@ -84,7 +84,7 @@ QLayoutBox::QLayoutBox(QToolBar * toolbar, QtView & owner) combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents); combo_->setFocusPolicy(Qt::ClickFocus); combo_->setMinimumWidth(combo_->sizeHint().width()); - combo_->setMaxVisibleItems(30); + combo_->setMaxVisibleItems(100); QObject::connect(combo_, SIGNAL(activated(const QString &)), this, SLOT(selected(const QString &))); diff --git a/src/frontends/qt4/ui/QCitationFindUi.ui b/src/frontends/qt4/ui/QCitationFindUi.ui index 32bba44241..f160a2f9af 100644 --- a/src/frontends/qt4/ui/QCitationFindUi.ui +++ b/src/frontends/qt4/ui/QCitationFindUi.ui @@ -1,287 +1,272 @@ - - - - - QCitationFindUi - - - - 0 - 0 - 375 - 257 - - - - - 1 - 1 - 0 - 0 - - - - LyX: Add Citation - - + + + + + QCitationFindUi + + + + 0 + 0 + 375 + 257 + + + + + 1 + 1 + 0 + 0 + + + + LyX: Add Citation + + + true + + + + 11 + + + 6 + + + + + 0 + + + 6 + + + + + Available bibliography keys + + + Q3ScrollView::AlwaysOn + + + Q3ScrollView::AlwaysOff + + + Q3ListBox::Extended + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + Cancel + + + false + + + + + + + &Add + + + false + + true - + + + + - - 11 - - + + 0 + + + 6 + + + + + + 3 + 0 + 0 + 0 + + + + &Previous + + + false + + + + + + + + 7 + 0 + 0 + 0 + + + + Browse the available bibliography entries + + + + + + + + 1 + 0 + 0 + 0 + + + + Make the search case-sensitive + + + Case &sensitive + + + + + + + + 3 + 0 + 0 + 0 + + + + &Next + + + 276824142 + + + false + + + + + + + 0 + + 6 - - - - - 0 - - - 6 - - - - - Q3ScrollView::AlwaysOn - - - Q3ScrollView::AlwaysOff - - - Q3ListBox::Extended - - - Available bibliography keys - - - - New Item - - - - - - - - - - - 3 - 7 - 0 - 0 - - - - Qt::NoFocus - - - WidgetWidth - - - true - - - Bibliography entry - + + + + + + 0 + 1 + 0 + 0 + + + + &Find: + + + searchED + - - - - - - 20 - 20 - - - - Expanding - - - Horizontal - + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + - - - - - Cancel - - - false - - - - - - - &Add - - - false - - - true - - - - - - - 0 - - - 6 - - - - - - 3 - 0 - 0 - 0 - - - - &Previous - - - false - - - - - - - - 7 - 0 - 0 - 0 - - - - Browse the available bibliography entries - - - - - - - - 1 - 0 - 0 - 0 - - - - Case &sensitive - - - Make the search case-sensitive - - - - - - - - 3 - 0 - 0 - 0 - - - - &Next - - - 276824142 - - - false - - - - - - - 0 - - - 6 - - - - - - 0 - 1 - 0 - 0 - - - - &Find: - - - searchED - - - - - - - - 20 - 20 - - - - Expanding - - - Horizontal - - - - - - - - - - 1 - 0 - 0 - 0 - - - - &Regular Expression - - - Interpret search entry as a regular expression - - - - - + + + + + + + + 1 + 0 + 0 + 0 + + + + Interpret search entry as a regular expression + + + &Regular Expression + + + - - qPixmapFromMimeSource - - availableLB - searchED - searchCaseCB - searchTypeCB - previousPB - nextPB - addPB - closePB - + + + + + + + qPixmapFromMimeSource + + + Q3ListBox + +
q3listbox.h
+ 0 + +
+
+ + availableLB + searchED + searchCaseCB + searchTypeCB + previousPB + nextPB + addPB + closePB + + +
diff --git a/src/frontends/qt4/ui/QCitationUi.ui b/src/frontends/qt4/ui/QCitationUi.ui index 66f98c3dda..e4fdf2b9ed 100644 --- a/src/frontends/qt4/ui/QCitationUi.ui +++ b/src/frontends/qt4/ui/QCitationUi.ui @@ -1,379 +1,412 @@ - - - - - QCitationUi - - - - 0 - 0 - 400 - 310 - + + + + + QCitationUi + + + + 0 + 0 + 401 + 457 + + + + + 1 + 1 + 0 + 0 + + + + + + + true + + + + + 320 + 20 + 79 + 118 + + + + + 0 - - - 1 - 1 - 0 - 0 - + + 6 - - + + + + A&pply + + + + + + + Cancel + + + false + + + + + + + &Restore + + + + + + + &OK + + + true + + + true + + + + + + + + + 10 + 220 + 201 + 156 + + + + Style + + + + 11 - - true + + 6 - - - 11 + + + + Citation &style: + + + citationStyleCO + + + + + + + + 3 + 0 + 0 + 0 + + + + Natbib citation style to use + + + + + + + Force upper case in citation + + + Force &upper case + + + + + + + &Text after: + + + textAfterED + + + + + + + + 5 + 0 + 0 + 0 + + + + Text to place after citation + + + + + + + + 5 + 0 + 0 + 0 + + + + Text to place before citation - - 6 + + + + + + Text &before: - - - - - 5 - 7 - 0 - 0 - - - - Qt::NoFocus - - - WidgetWidth - - - true - - - Bibliography entry - - - - - - - 0 - - - 6 - - - - - - 0 - 0 - 0 - 0 - - - - - - - image0 - - - Move the selected citation down - - - - - - - Q3ScrollView::AlwaysOn - - - Q3ScrollView::AlwaysOff - - - Q3ListBox::Single - - - Citations currently selected - - - - New Item - - - - - - - - D&elete - - - - - - - - 0 - 0 - 0 - 0 - - - - - - - image1 - - - Move the selected citation up - - - - - - - &Citations: - - - selectedLB - - - - - - - &Add... - - - true - - - - - - - - - - - 20 - 20 - - - - Expanding - - - Vertical - - - - - - - - - 0 - - - 6 - - - - - &Restore - - - - - - - - 20 - 20 - - - - Expanding - - - Horizontal - - - - - - - &OK - - - true - - - true - - - - - - - A&pply - - - - - - - Cancel - - - false - - - - - - - - - Style - - - - 11 - - - 6 - - - - - Citation &style: - - - citationStyleCO - - - - - - - - 3 - 0 - 0 - 0 - - - - Natbib citation style to use - - - - - - - Force &upper case - - - Force upper case in citation - - - - - - - &Text after: - - - textAfterED - - - - - - - - 5 - 0 - 0 - 0 - - - - Text to place after citation - - - - - - - - 5 - 0 - 0 - 0 - - - - Text to place before citation - - - - - - - Text &before: - - - textAfterED - - - - - - - &Full author list - - - List all authors - - - - - - - + + textAfterED + + + + + + + List all authors + + + &Full author list + + + + + + + + + 140 + 110 + 41 + 25 + + + + + 0 + 0 + 0 + 0 + + + + Move the selected citation down + + + &Down + + + + + + + + + 140 + 80 + 41 + 25 + + + + + 0 + 0 + 0 + 0 + + + + Move the selected citation up + + + &Up + + + + + + + + + 140 + 50 + 41 + 25 + + + + D&elete + + + + + + 140 + 20 + 41 + 25 + + + + + + + &Add + + + true + + + + + + 10 + 0 + 111 + 16 + + + + &Citations to insert: + + + selectedLV + + + + + + 190 + 0 + 111 + 16 + + + + &Available Citations: + + + selectedLB + + + + + + 160 + 206 + 23 + 20 + + + + &Find: + + + selectedLV + + + + + + 260 + 240 + 111 + 31 + + + + Advanced &Search... + + + + + + 10 + 380 + 371 + 71 + + + + Citation Information + + + + + + 10 + 20 + 120 + 181 + + + + + + + 190 + 20 + 120 + 181 + + + + + + + 190 + 204 + 120 + 20 + + + + + - - - selectedLB - upPB - downPB - addPB - deletePB - citationStyleCO - textBeforeED - textAfterED - fulllistCB - forceuppercaseCB - restorePB - okPB - applyPB - closePB - - - - 789ca5d2cb6ee2301480e13d4f11c10e8da6101293a89a45e9fd02a59745a5aa0bc7760ab4909424b4a1eabbd7e71c9b409559d562914fbf8d4dcc5edb79180f9df65e23cb793e158e98f0a5d396c57c5e3e3efdfb6c345dd7d11f2f70bacd3f8de65f4738a364a1e059e9e7560707b0850c7ac27781d744cf63c80b43c138b024f6fdd003ae0c43e288188611f2c45046129811235720ef0c193131e4c46343257d6041142ef114d8ed301944c017a23dd587a10c05f01c19b06e1f279f19fa410f288981cf71ed3dd1eebb24da7d5343538f806e27e2c4055130e21019dab5b7c05ed7324786924bbc140ef45dce05d60324b7efea90a8bf1927df001997ae62c035b0dfb3c778230a45754eb49367c020928c3801869ead0343ae70a367a4b093a740ee4945758cd4fbc458df8191548c780514bee2c44b62ecc6313002ca4d8d81b092aa00c61bbe2271e09fb976fcb2b4cca8293c1242ffae9a123f4fa6b397baf23a5f24697d795b66f97f4a91e5abdd42877ad725fd50386c51e57a7dc0078747d9f1c9eaf4ecfc625374ba8caf06c324cb92341d5dabad7d5439beb9d5212b720ad509742a92adb07536487755d83eb54ef755d879d7aa9c5561f7165459851ff7a3aaf0db3bfd59bef61bdf12452a24 - - - 789cc5d4c96edb301006e0bb9f42086f413191686d44d143f67ddf53f4409192b7388be3c4498abe7ba99911112768e34b5133877ce63f143779613eb838d80de6175a0f633dee99c074f52898b78fc3e1cbf71fdf7eb6e6a40cdc5f960572ee4b6bee701c9860eff6a6ac01a18308f1838ebc73b464c7ec2b761e515eb30d7bc59bf2961c85643160c712f3a260e752613e43e791610b72db243879b821c761a2d16376cc7e699c52fe926dc8a2ef4df92e3909d9176c9b15e87372aaf236d677d836a7fe5d7216b1cfd84ac5e823b65506bd4cce23f6035b69caefb02d7be84df953b2b205f55f930b6912f4c8dba237d92959e079456116f1fc5276c2ee905542e38b8aac9382c6db2217a5a5e73d918d644fd8dad2fd5a42fbe7c3335bb3efc996f3a2575b867e3f37c8fe7909d94a1e7f0fad9af3135db6caf0bce090eccfcbd46e47beff84ece71fb353f61dbb59cf23d93fff18ad7449fb2f4ab2dfff6d7229cb14fbf13ec751635864a7ec03b4f6f35d2737fb25f07d4ab4df8ffddaa96cee9700b29fef2a5aeb88cfefb576d6568aef4fc16eee13ee7f563853fe96ecebdb645b96343eae376f37eb873572333f61c86ebd94c7f73f2f6cb37e452ed38a9cd736b6925585c6fb674b6f7c7f2bfcd08fd9eced7fe541809e3defd20518b0b3e55dba840a3ad0fd58f131efd23de8c300ae610837ef2bdee75dfa16d377700f237880f174c574dea71fe10926aee2d955bcbcad789b77e9571efbc98d3d72158bb004cb6e562b1ff32ebdea56b906ebb0019b98df7215dbb003bb6e567a3aefd27bb00f07700847700c2758318153388373b8804bd77f35950f21c226dd7f036843ecf209a490b96feaef4308ffb89f3928013012426851ccb0ff7dcabbd5a6b3e585c1fcfd8ce3e7c28a525430119d59f2a22b7a2e59b7be187c9a9760c5801aac40f459feefed9fe77f7d6dfd06af616644 - - + + + + upPB + downPB + addPB + deletePB + citationStyleCO + textBeforeED + textAfterED + fulllistCB + forceuppercaseCB + restorePB + okPB + applyPB + closePB + + + -- 2.39.2