2 * $Id: FormCitationDialogImpl.C,v 1.4 2001/03/29 21:17:17 kalle Exp $
5 #include "FormCitationDialogImpl.h"
7 #include "FormCitation.h"
9 #include "controllers/biblio.h"
10 #include "controllers/ControlCitation.h"
12 #include <qlineedit.h>
14 #include <qmultilineedit.h>
15 #include <qpushbutton.h>
26 * Constructs a FormCitationDialogImpl which is a child of 'parent', with the
27 * name 'name' and widget flags set to 'f'
29 * The dialog will by default be modeless, unless you set 'modal' to
30 * TRUE to construct a modal dialog.
32 FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* parent, const char* name, bool modal, WFlags fl )
33 : FormCitationDialog( parent, name, modal, fl ),
36 connect( okPB, SIGNAL( clicked() ),
37 form, SLOT( slotOK() ) );
38 connect( cancelPB, SIGNAL( clicked() ),
39 form, SLOT( slotCancel() ) );
40 connect( restorePB, SIGNAL( clicked() ),
41 form, SLOT( slotRestore() ) );
42 connect( applyPB, SIGNAL( clicked() ),
43 form, SLOT( slotApply() ) );
47 * Destroys the object and frees any allocated resources
49 FormCitationDialogImpl::~FormCitationDialogImpl()
51 // no need to delete child widgets, Qt does it all for us
55 // These slots correspond to the XForms input() method.
56 void FormCitationDialogImpl::slotBibSelected( int sel )
58 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
60 citeLB->clearSelection();
62 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
63 form_->bc().input( ButtonPolicy::SMI_NOOP );
67 // Put into browser_info the additional info associated with
68 // the selected browser_bib key
71 infoML->setText( biblio::getInfo( theMap,
72 form_->bibkeys[sel-1] ).c_str() );
74 // Highlight the selected browser_bib key in browser_cite if
76 vector<string>::const_iterator cit =
77 std::find(form_->citekeys.begin(), form_->citekeys.end(),
80 if (cit != form_->citekeys.end()) {
81 int const n = int(cit - form_->citekeys.begin());
82 citeLB->setSelected( n, true );
83 citeLB->setTopItem( n );
86 if (!form_->controller().isReadonly()) {
87 if (cit != form_->citekeys.end()) {
88 form_->setBibButtons(FormCitation::OFF);
89 form_->setCiteButtons(FormCitation::ON);
91 form_->setBibButtons(FormCitation::ON);
92 form_->setCiteButtons(FormCitation::OFF);
96 form_->bc().input( ButtonPolicy::SMI_VALID );
100 void FormCitationDialogImpl::slotCiteSelected( int sel )
102 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
104 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
105 form_->bc().input( ButtonPolicy::SMI_NOOP );
109 if (!form_->controller().isReadonly()) {
110 form_->setBibButtons(FormCitation::OFF);
111 form_->setCiteButtons(FormCitation::ON);
114 // Highlight the selected browser_cite key in browser_bib
115 vector<string>::const_iterator cit =
116 std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
118 if (cit != form_->bibkeys.end()) {
119 int const n = int(cit - form_->bibkeys.begin());
120 bibLB->setSelected( n, true );
121 bibLB->setTopItem( n );
123 // Put into browser_info the additional info associated
124 // with the selected browser_cite key
126 infoML->setText( biblio::getInfo( theMap, form_->bibkeys[sel] ).c_str() );
129 form_->bc().input( ButtonPolicy::SMI_VALID );
133 void FormCitationDialogImpl::slotAddClicked()
135 int const sel = bibLB->currentItem();
136 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
137 form_->bc().input( ButtonPolicy::SMI_NOOP );
141 // Add the selected browser_bib key to browser_cite
142 citeLB->insertItem( form_->bibkeys[sel].c_str() );
143 form_->citekeys.push_back( form_->bibkeys[sel] );
145 int const n = int(form_->citekeys.size());
146 citeLB->setSelected( n-1, true );
148 form_->setBibButtons(FormCitation::OFF);
149 form_->setCiteButtons(FormCitation::ON);
151 form_->bc().input( ButtonPolicy::SMI_VALID );
155 void FormCitationDialogImpl::slotDelClicked()
157 int const sel = citeLB->currentItem();
158 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
159 form_->bc().input( ButtonPolicy::SMI_NOOP );
163 // Remove the selected key from browser_cite
164 citeLB->removeItem( sel );
165 form_->citekeys.erase(form_->citekeys.begin() + sel );
167 form_->setBibButtons(FormCitation::ON);
168 form_->setCiteButtons(FormCitation::OFF);
170 form_->bc().input( ButtonPolicy::SMI_VALID );
174 void FormCitationDialogImpl::slotUpClicked()
176 int const sel = citeLB->currentItem();
177 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
178 form_->bc().input( ButtonPolicy::SMI_NOOP );
182 // Move the selected key up one line
183 vector<string>::iterator it = form_->citekeys.begin() + sel;
184 string const tmp = *it;
186 citeLB->removeItem( sel );
187 form_->citekeys.erase(it);
189 citeLB->insertItem( tmp.c_str(), sel-1 );
190 citeLB->setSelected( sel-1, true );
191 form_->citekeys.insert(it-1, tmp);
192 form_->setCiteButtons(FormCitation::ON);
194 form_->bc().input( ButtonPolicy::SMI_VALID );
198 void FormCitationDialogImpl::slotDownClicked()
200 int const sel = citeLB->currentItem();
201 if (sel < 0 || sel >= (int)form_->citekeys.size()-1) {
202 form_->bc().input( ButtonPolicy::SMI_NOOP );
206 // Move the selected key down one line
207 vector<string>::iterator it = form_->citekeys.begin() + sel;
208 string const tmp = *it;
210 citeLB->removeItem( sel );
211 form_->citekeys.erase(it);
213 citeLB->insertItem( tmp.c_str(), sel+1 );
214 citeLB->setSelected( sel+1, true );
215 form_->citekeys.insert(it+1, tmp);
216 form_->setCiteButtons(FormCitation::ON);
218 form_->bc().input( ButtonPolicy::SMI_VALID );
222 void FormCitationDialogImpl::slotSearchTypeToggled( bool toggle )
225 searchTypePB->setText( _( "Regex" ) );
227 searchTypePB->setText( _( "Simple" ) );
229 form_->bc().input( ButtonPolicy::SMI_NOOP );
233 void FormCitationDialogImpl::slotPreviousClicked()
235 doPreviousNext( false );
239 void FormCitationDialogImpl::slotNextClicked()
241 doPreviousNext( true );
245 void FormCitationDialogImpl::doPreviousNext( bool next )
247 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
248 string const str = searchED->text().latin1();
250 biblio::Direction const dir =
252 biblio::FORWARD : biblio::BACKWARD;
254 biblio::Search const type =
255 searchTypePB->isOn() ?
256 biblio::REGEX : biblio::SIMPLE;
258 vector<string>::const_iterator start = form_->bibkeys.begin();
259 int const sel = bibLB->currentItem();
260 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
263 // Find the NEXT instance...
264 if (dir == biblio::FORWARD)
269 vector<string>::const_iterator const cit =
270 biblio::searchKeys(theMap, form_->bibkeys, str,
273 if (cit == form_->bibkeys.end()) {
274 form_->bc().input( ButtonPolicy::SMI_NOOP );
278 int const found = int(cit - form_->bibkeys.begin());
280 form_->bc().input( ButtonPolicy::SMI_NOOP );
284 // Update the display
285 int const top = max(found-5, 1);
286 bibLB->setTopItem( top );
287 bibLB->setSelected( found, true );
288 slotBibSelected( 0 );
290 form_->bc().input( ButtonPolicy::SMI_VALID );
294 void FormCitationDialogImpl::slotCitationStyleSelected( int )
296 form_->bc().input( ButtonPolicy::SMI_VALID );
300 void FormCitationDialogImpl::slotTextBeforeReturn()
302 form_->bc().input( ButtonPolicy::SMI_VALID );
306 void FormCitationDialogImpl::slotTextAfterReturn()
308 form_->bc().input( ButtonPolicy::SMI_VALID );