2 * \file QCitationDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Kalle Dalheimer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "QCitationDialog.h"
16 #include "ui/QCitationFindUi.h"
17 #include "QCitation.h"
18 #include "qt_helpers.h"
20 #include "controllers/ControlCitation.h"
21 #include "controllers/ButtonController.h"
23 #include <qcheckbox.h>
24 #include <qlineedit.h>
25 #include <q3listbox.h>
26 #include <q3multilineedit.h>
27 #include <qpushbutton.h>
36 QCitationDialog::QCitationDialog(QCitation * form)
40 connect(restorePB, SIGNAL(clicked()),
41 form, SLOT(slotRestore()));
42 connect(okPB, SIGNAL(clicked()),
43 form, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()),
45 form, SLOT(slotApply()));
46 connect(closePB, SIGNAL(clicked()),
47 form, SLOT(slotClose()));
49 connect( citationStyleCO, SIGNAL( activated(int) ), this, SLOT( changed_adaptor() ) );
50 connect( fulllistCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) );
51 connect( forceuppercaseCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) );
52 connect( textBeforeED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
53 connect( textAfterED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
54 connect( upPB, SIGNAL( clicked() ), this, SLOT( up() ) );
55 connect( downPB, SIGNAL( clicked() ), this, SLOT( down() ) );
56 connect( selectedLB, SIGNAL( currentChanged(QListBoxItem*) ), this, SLOT( selectedChanged() ) );
57 connect( addPB, SIGNAL( clicked() ), this, SLOT( add() ) );
58 connect( deletePB, SIGNAL( clicked() ), this, SLOT( del() ) );
60 add_ = new QDialog(this, "", true);
63 connect( ui_.addPB, SIGNAL( clicked() ), this, SLOT( accept() ) );
64 connect( ui_.closePB, SIGNAL( clicked() ), this, SLOT( reject() ) );
66 connect(ui_.previousPB, SIGNAL(clicked()), this, SLOT(previous()));
67 connect(ui_.nextPB, SIGNAL(clicked()), this, SLOT(next()));
68 connect(ui_.availableLB, SIGNAL(currentChanged(Q3ListBoxItem *)), this, SLOT(availableChanged()));
69 connect(ui_.availableLB, SIGNAL(selected(Q3ListBoxItem *)), this, SLOT(addCitation()));
70 connect(ui_.availableLB, SIGNAL(selected(Q3ListBoxItem *)), add_, SLOT(accept()));
71 connect(ui_.addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
72 connect(selectedLB, SIGNAL(returnPressed(Q3ListBoxItem *)), form, SLOT(slotOK()));
76 QCitationDialog::~QCitationDialog()
81 void QCitationDialog::setButtons()
83 if (form_->readOnly())
86 int const sel_nr = selectedLB->currentItem();
87 int const avail_nr = ui_.availableLB->currentItem();
89 ui_.addPB->setEnabled(avail_nr >= 0);
90 deletePB->setEnabled(sel_nr >= 0);
91 upPB->setEnabled(sel_nr > 0);
92 downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
96 void QCitationDialog::openFind()
98 if (form_->readOnly())
101 if (isVisible() && selectedLB->count() == 0
102 && ui_.availableLB->count() != 0){
103 // open the find dialog
105 // and let the user press ok after a selection
106 if (selectedLB->count() != 0)
112 void QCitationDialog::selectedChanged()
115 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
118 int const sel = selectedLB->currentItem();
126 toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
131 void QCitationDialog::previous()
133 find(biblio::BACKWARD);
137 void QCitationDialog::next()
139 find(biblio::FORWARD);
143 void QCitationDialog::availableChanged()
145 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
148 int const sel = ui_.availableLB->currentItem();
156 toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
161 void QCitationDialog::addCitation()
163 int const sel = ui_.availableLB->currentItem();
168 // Add the selected browser_bib keys to browser_cite
169 // multiple selections are possible
170 for (unsigned int i = 0; i != ui_.availableLB->count(); i++) {
171 if (ui_.availableLB->isSelected(i)) {
172 // do not allow duplicates
173 if ((selectedLB->findItem(ui_.availableLB->text(i))) == 0) {
174 selectedLB->insertItem(toqstr(form_->bibkeys[i]));
175 form_->citekeys.push_back(form_->bibkeys[i]);
180 int const n = int(form_->citekeys.size());
181 selectedLB->setSelected(n - 1, true);
189 void QCitationDialog::del()
191 int const sel = selectedLB->currentItem();
193 // Remove the selected key from browser_cite
194 selectedLB->removeItem(sel);
195 form_->citekeys.erase(form_->citekeys.begin() + sel);
203 void QCitationDialog::up()
205 int const sel = selectedLB->currentItem();
207 // Move the selected key up one line
208 vector<string>::iterator it = form_->citekeys.begin() + sel;
209 string const tmp = *it;
211 selectedLB->removeItem(sel);
212 form_->citekeys.erase(it);
214 selectedLB->insertItem(toqstr(tmp), sel - 1);
215 selectedLB->setSelected(sel - 1, true);
216 form_->citekeys.insert(it - 1, tmp);
224 void QCitationDialog::down()
226 int const sel = selectedLB->currentItem();
228 // Move the selected key down one line
229 vector<string>::iterator it = form_->citekeys.begin() + sel;
230 string const tmp = *it;
232 selectedLB->removeItem(sel);
233 form_->citekeys.erase(it);
235 selectedLB->insertItem(toqstr(tmp), sel + 1);
236 selectedLB->setSelected(sel + 1, true);
237 form_->citekeys.insert(it + 1, tmp);
245 void QCitationDialog::add()
251 void QCitationDialog::changed_adaptor()
257 void QCitationDialog::find(biblio::Direction dir)
259 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
261 biblio::Search const type = ui_.searchTypeCB->isChecked()
262 ? biblio::REGEX : biblio::SIMPLE;
264 vector<string>::const_iterator start = form_->bibkeys.begin();
265 int const sel = ui_.availableLB->currentItem();
266 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
269 // Find the NEXT instance...
270 if (dir == biblio::FORWARD)
273 bool const casesens = ui_.searchCaseCB->isChecked();
274 string const str = fromqstr(ui_.searchED->text());
276 vector<string>::const_iterator cit =
277 biblio::searchKeys(theMap, form_->bibkeys, str,
278 start, type, dir, casesens);
280 // not found. let's loop round
281 if (cit == form_->bibkeys.end()) {
282 if (dir == biblio::FORWARD) {
283 start = form_->bibkeys.begin();
285 else start = form_->bibkeys.end() - 1;
287 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
288 start, type, dir, casesens);
290 if (cit == form_->bibkeys.end())
294 int const found = int(cit - form_->bibkeys.begin());
299 // Update the display
300 // note that we have multi selection mode!
301 ui_.availableLB->setSelected(sel, false);
302 ui_.availableLB->setSelected(found, true);
303 ui_.availableLB->setCurrentItem(found);
304 ui_.availableLB->ensureCurrentVisible();
307 } // namespace frontend