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 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "qt_helpers.h"
20 #include "controllers/ControlCitation.h"
24 #include <qcheckbox.h>
25 #include <qcombobox.h>
26 #include <qlineedit.h>
28 #include <qmultilineedit.h>
29 #include <qpushbutton.h>
31 #include "QCitationDialog.h"
32 #include "QCitation.h"
33 #include "support/lstrings.h"
40 QCitationDialog::QCitationDialog(QCitation * form)
41 : QCitationDialogBase(0, 0, false, 0),
44 connect(restorePB, SIGNAL(clicked()),
45 form, SLOT(slotRestore()));
46 connect(okPB, SIGNAL(clicked()),
47 form, SLOT(slotOK()));
48 connect(applyPB, SIGNAL(clicked()),
49 form, SLOT(slotApply()));
50 connect(closePB, SIGNAL(clicked()),
51 form, SLOT(slotClose()));
52 connect(searchED, SIGNAL(returnPressed()),
53 this, SLOT(slotNextClicked()));
55 textBeforeED->setText(qt_("Not yet supported"));
56 textBeforeED->setReadOnly(true);
57 textBeforeED->setFocusPolicy(QWidget::NoFocus);
58 citationStyleCO->setEnabled(false);
59 citationStyleCO->setFocusPolicy(QWidget::NoFocus);
63 QCitationDialog::~QCitationDialog()
68 void QCitationDialog::slotBibSelected(int sel)
70 slotBibHighlighted(sel);
72 if (form_->readOnly())
79 void QCitationDialog::slotBibHighlighted(int sel)
81 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
83 citeLB->clearSelection();
85 // FIXME: why would this happen ?
86 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
90 // Put into browser_info the additional info associated with
91 // the selected browser_bib key
94 infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
96 // Highlight the selected browser_bib key in browser_cite if
98 vector<string>::const_iterator cit =
99 std::find(form_->citekeys.begin(), form_->citekeys.end(),
100 form_->bibkeys[sel]);
102 if (cit != form_->citekeys.end()) {
103 int const n = int(cit - form_->citekeys.begin());
104 citeLB->setSelected(n, true);
105 citeLB->setTopItem(n);
108 if (!form_->readOnly()) {
109 if (cit != form_->citekeys.end()) {
110 form_->setBibButtons(QCitation::OFF);
111 form_->setCiteButtons(QCitation::ON);
113 form_->setBibButtons(QCitation::ON);
114 form_->setCiteButtons(QCitation::OFF);
120 void QCitationDialog::slotCiteHighlighted(int sel)
122 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
124 // FIXME: why would this happen ?
125 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
129 if (!form_->readOnly()) {
130 form_->setBibButtons(QCitation::OFF);
131 form_->setCiteButtons(QCitation::ON);
134 // Highlight the selected browser_cite key in browser_bib
135 vector<string>::const_iterator cit =
136 std::find(form_->bibkeys.begin(),
137 form_->bibkeys.end(), form_->citekeys[sel]);
139 if (cit != form_->bibkeys.end()) {
140 int const n = int(cit - form_->bibkeys.begin());
141 bibLB->setSelected(n, true);
142 bibLB->setTopItem(n);
144 // Put into browser_info the additional info associated
145 // with the selected browser_cite key
147 infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
152 void QCitationDialog::slotAddClicked()
154 int const sel = bibLB->currentItem();
157 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
161 // Add the selected browser_bib key to browser_cite
162 citeLB->insertItem(toqstr(form_->bibkeys[sel]));
163 form_->citekeys.push_back(form_->bibkeys[sel]);
165 int const n = int(form_->citekeys.size());
166 citeLB->setSelected(n - 1, true);
168 slotBibHighlighted(sel);
169 form_->setBibButtons(QCitation::OFF);
170 form_->setCiteButtons(QCitation::ON);
175 void QCitationDialog::slotDelClicked()
177 int const sel = citeLB->currentItem();
180 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
184 // Remove the selected key from browser_cite
185 citeLB->removeItem(sel);
186 form_->citekeys.erase(form_->citekeys.begin() + sel);
188 form_->setBibButtons(QCitation::ON);
189 form_->setCiteButtons(QCitation::OFF);
194 void QCitationDialog::slotUpClicked()
196 int const sel = citeLB->currentItem();
199 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
203 // Move the selected key up one line
204 vector<string>::iterator it = form_->citekeys.begin() + sel;
205 string const tmp = *it;
207 citeLB->removeItem(sel);
208 form_->citekeys.erase(it);
210 citeLB->insertItem(toqstr(tmp), sel - 1);
211 citeLB->setSelected(sel - 1, true);
212 form_->citekeys.insert(it - 1, tmp);
213 form_->setCiteButtons(QCitation::ON);
218 void QCitationDialog::slotDownClicked()
220 int const sel = citeLB->currentItem();
223 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
227 // Move the selected key down one line
228 vector<string>::iterator it = form_->citekeys.begin() + sel;
229 string const tmp = *it;
231 citeLB->removeItem(sel);
232 form_->citekeys.erase(it);
234 citeLB->insertItem(toqstr(tmp), sel + 1);
235 citeLB->setSelected(sel + 1, true);
236 form_->citekeys.insert(it + 1, tmp);
237 form_->setCiteButtons(QCitation::ON);
242 void QCitationDialog::slotPreviousClicked()
244 doFind(biblio::BACKWARD);
248 void QCitationDialog::slotNextClicked()
250 doFind(biblio::FORWARD);
254 void QCitationDialog::changed_adaptor()
260 void QCitationDialog::doFind(biblio::Direction dir)
262 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
263 string const str = fromqstr(searchED->text());
265 biblio::Search const type =
266 searchTypeCB->isChecked() ?
267 biblio::REGEX : biblio::SIMPLE;
269 vector<string>::const_iterator start = form_->bibkeys.begin();
270 int const sel = bibLB->currentItem();
271 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
274 // Find the NEXT instance...
275 if (dir == biblio::FORWARD)
280 bool const caseSensitive = searchCaseCB->isChecked();
282 vector<string>::const_iterator cit =
283 biblio::searchKeys(theMap, form_->bibkeys, str,
284 start, type, dir, caseSensitive);
286 // not found. let's loop round
287 if (cit == form_->bibkeys.end()) {
288 if (dir == biblio::FORWARD) {
289 start = form_->bibkeys.begin();
291 else start = form_->bibkeys.end() - 1;
293 cit = biblio::searchKeys(theMap, form_->bibkeys, str,
294 start, type, dir, caseSensitive);
296 if (cit == form_->bibkeys.end())
300 int const found = int(cit - form_->bibkeys.begin());
305 // Update the display
306 int const top = max(found - 5, 1);
307 bibLB->setTopItem(top);
308 bibLB->setSelected(found, true);
309 slotBibHighlighted(0);