2 * $Id: FormCitationDialogImpl.C,v 1.7 2001/06/05 17:05:51 lasgouttes Exp $
7 #include "FormCitationDialogImpl.h"
9 #include "FormCitation.h"
11 #include "controllers/biblio.h"
12 #include "controllers/ControlCitation.h"
14 #include <qcheckbox.h>
15 #include <qlineedit.h>
17 #include <qmultilineedit.h>
18 #include <qpushbutton.h>
29 * Constructs a FormCitationDialogImpl which is a child of 'parent', with the
30 * name 'name' and widget flags set to 'f'
32 * The dialog will by default be modeless, unless you set 'modal' to
33 * TRUE to construct a modal dialog.
35 FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* parent, const char* name, bool modal, WFlags fl )
36 : FormCitationDialog( parent, name, modal, fl ),
39 connect( okPB, SIGNAL( clicked() ),
40 form, SLOT( slotOK() ) );
41 connect( cancelPB, SIGNAL( clicked() ),
42 form, SLOT( slotCancel() ) );
43 connect( restorePB, SIGNAL( clicked() ),
44 form, SLOT( slotRestore() ) );
45 connect( applyPB, SIGNAL( clicked() ),
46 form, SLOT( slotApply() ) );
50 * Destroys the object and frees any allocated resources
52 FormCitationDialogImpl::~FormCitationDialogImpl()
54 // no need to delete child widgets, Qt does it all for us
58 // These slots correspond to the XForms input() method.
59 void FormCitationDialogImpl::slotBibSelected( int sel )
61 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
63 citeLB->clearSelection();
65 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
66 // form_->bc().input( ButtonPolicy::SMI_NOOP );
70 // Put into browser_info the additional info associated with
71 // the selected browser_bib key
74 infoML->setText( biblio::getInfo( theMap,
75 form_->bibkeys[sel-1] ).c_str() );
77 // Highlight the selected browser_bib key in browser_cite if
79 vector<string>::const_iterator cit =
80 std::find(form_->citekeys.begin(), form_->citekeys.end(),
83 if (cit != form_->citekeys.end()) {
84 int const n = int(cit - form_->citekeys.begin());
85 citeLB->setSelected( n, true );
86 citeLB->setTopItem( n );
89 if (!form_->controller().isReadonly()) {
90 if (cit != form_->citekeys.end()) {
91 form_->setBibButtons(FormCitation::OFF);
92 form_->setCiteButtons(FormCitation::ON);
94 form_->setBibButtons(FormCitation::ON);
95 form_->setCiteButtons(FormCitation::OFF);
99 // form_->bc().input( ButtonPolicy::SMI_VALID );
103 void FormCitationDialogImpl::slotCiteSelected( int sel )
105 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
107 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
108 // form_->bc().input( ButtonPolicy::SMI_NOOP );
112 if (!form_->controller().isReadonly()) {
113 form_->setBibButtons(FormCitation::OFF);
114 form_->setCiteButtons(FormCitation::ON);
117 // Highlight the selected browser_cite key in browser_bib
118 vector<string>::const_iterator cit =
119 std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
121 if (cit != form_->bibkeys.end()) {
122 int const n = int(cit - form_->bibkeys.begin());
123 bibLB->setSelected( n, true );
124 bibLB->setTopItem( n );
126 // Put into browser_info the additional info associated
127 // with the selected browser_cite key
129 infoML->setText( biblio::getInfo( theMap, form_->bibkeys[sel] ).c_str() );
132 // form_->bc().input( ButtonPolicy::SMI_VALID );
136 void FormCitationDialogImpl::slotAddClicked()
138 int const sel = bibLB->currentItem();
139 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
140 // form_->bc().input( ButtonPolicy::SMI_NOOP );
144 // Add the selected browser_bib key to browser_cite
145 citeLB->insertItem( form_->bibkeys[sel].c_str() );
146 form_->citekeys.push_back( form_->bibkeys[sel] );
148 int const n = int(form_->citekeys.size());
149 citeLB->setSelected( n-1, true );
151 form_->setBibButtons(FormCitation::OFF);
152 form_->setCiteButtons(FormCitation::ON);
154 // form_->bc().input( ButtonPolicy::SMI_VALID );
158 void FormCitationDialogImpl::slotDelClicked()
160 int const sel = citeLB->currentItem();
161 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
162 // form_->bc().input( ButtonPolicy::SMI_NOOP );
166 // Remove the selected key from browser_cite
167 citeLB->removeItem( sel );
168 form_->citekeys.erase(form_->citekeys.begin() + sel );
170 form_->setBibButtons(FormCitation::ON);
171 form_->setCiteButtons(FormCitation::OFF);
173 // form_->bc().input( ButtonPolicy::SMI_VALID );
177 void FormCitationDialogImpl::slotUpClicked()
179 int const sel = citeLB->currentItem();
180 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
181 // form_->bc().input( ButtonPolicy::SMI_NOOP );
185 // Move the selected key up one line
186 vector<string>::iterator it = form_->citekeys.begin() + sel;
187 string const tmp = *it;
189 citeLB->removeItem( sel );
190 form_->citekeys.erase(it);
192 citeLB->insertItem( tmp.c_str(), sel-1 );
193 citeLB->setSelected( sel-1, true );
194 form_->citekeys.insert(it-1, tmp);
195 form_->setCiteButtons(FormCitation::ON);
197 // form_->bc().input( ButtonPolicy::SMI_VALID );
201 void FormCitationDialogImpl::slotDownClicked()
203 int const sel = citeLB->currentItem();
204 if (sel < 0 || sel >= (int)form_->citekeys.size()-1) {
205 // form_->bc().input( ButtonPolicy::SMI_NOOP );
209 // Move the selected key down one line
210 vector<string>::iterator it = form_->citekeys.begin() + sel;
211 string const tmp = *it;
213 citeLB->removeItem( sel );
214 form_->citekeys.erase(it);
216 citeLB->insertItem( tmp.c_str(), sel+1 );
217 citeLB->setSelected( sel+1, true );
218 form_->citekeys.insert(it+1, tmp);
219 form_->setCiteButtons(FormCitation::ON);
221 // form_->bc().input( ButtonPolicy::SMI_VALID );
225 void FormCitationDialogImpl::slotPreviousClicked()
227 doPreviousNext( false );
231 void FormCitationDialogImpl::slotNextClicked()
233 doPreviousNext( true );
237 void FormCitationDialogImpl::doPreviousNext( bool next )
239 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
240 string const str = searchED->text().latin1();
242 biblio::Direction const dir =
244 biblio::FORWARD : biblio::BACKWARD;
246 biblio::Search const type =
247 searchTypeCB->isChecked() ?
248 biblio::REGEX : biblio::SIMPLE;
250 vector<string>::const_iterator start = form_->bibkeys.begin();
251 int const sel = bibLB->currentItem();
252 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
255 // Find the NEXT instance...
256 if (dir == biblio::FORWARD)
261 bool const caseSensitive = searchCaseCB->isChecked();
263 vector<string>::const_iterator const cit =
264 biblio::searchKeys(theMap, form_->bibkeys, str,
265 start, type, dir, caseSensitive );
267 if (cit == form_->bibkeys.end()) {
268 // form_->bc().input( ButtonPolicy::SMI_NOOP );
272 int const found = int(cit - form_->bibkeys.begin());
274 // form_->bc().input( ButtonPolicy::SMI_NOOP );
278 // Update the display
279 int const top = max(found-5, 1);
280 bibLB->setTopItem( top );
281 bibLB->setSelected( found, true );
282 slotBibSelected( 0 );
284 // form_->bc().input( ButtonPolicy::SMI_VALID );
288 void FormCitationDialogImpl::slotCitationStyleSelected( int )
290 // form_->bc().input( ButtonPolicy::SMI_VALID );
294 void FormCitationDialogImpl::slotTextBeforeReturn()
296 // form_->bc().input( ButtonPolicy::SMI_VALID );
300 void FormCitationDialogImpl::slotTextAfterReturn()
302 // form_->bc().input( ButtonPolicy::SMI_VALID );