2 * $Id: FormCitationDialogImpl.C,v 1.8 2001/06/16 14:48:12 leeming 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>
30 * Constructs a FormCitationDialogImpl which is a child of 'parent', with the
31 * name 'name' and widget flags set to 'f'
33 * The dialog will by default be modeless, unless you set 'modal' to
34 * TRUE to construct a modal dialog.
36 FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* parent, const char* name, bool modal, WFlags fl )
37 : FormCitationDialog( parent, name, modal, fl ),
40 connect( okPB, SIGNAL( clicked() ),
41 form, SLOT( slotOK() ) );
42 connect( cancelPB, SIGNAL( clicked() ),
43 form, SLOT( slotCancel() ) );
44 connect( restorePB, SIGNAL( clicked() ),
45 form, SLOT( slotRestore() ) );
46 connect( applyPB, SIGNAL( clicked() ),
47 form, SLOT( slotApply() ) );
51 * Destroys the object and frees any allocated resources
53 FormCitationDialogImpl::~FormCitationDialogImpl()
55 // no need to delete child widgets, Qt does it all for us
59 // These slots correspond to the XForms input() method.
60 void FormCitationDialogImpl::slotBibSelected( int sel )
62 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
64 citeLB->clearSelection();
66 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
67 // form_->bc().input( ButtonPolicy::SMI_NOOP );
71 // Put into browser_info the additional info associated with
72 // the selected browser_bib key
75 infoML->setText( biblio::getInfo( theMap,
76 form_->bibkeys[sel-1] ).c_str() );
78 // Highlight the selected browser_bib key in browser_cite if
80 vector<string>::const_iterator cit =
81 std::find(form_->citekeys.begin(), form_->citekeys.end(),
84 if (cit != form_->citekeys.end()) {
85 int const n = int(cit - form_->citekeys.begin());
86 citeLB->setSelected( n, true );
87 citeLB->setTopItem( n );
90 if (!form_->controller().isReadonly()) {
91 if (cit != form_->citekeys.end()) {
92 form_->setBibButtons(FormCitation::OFF);
93 form_->setCiteButtons(FormCitation::ON);
95 form_->setBibButtons(FormCitation::ON);
96 form_->setCiteButtons(FormCitation::OFF);
100 // form_->bc().input( ButtonPolicy::SMI_VALID );
104 void FormCitationDialogImpl::slotCiteSelected( int sel )
106 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
108 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
109 // form_->bc().input( ButtonPolicy::SMI_NOOP );
113 if (!form_->controller().isReadonly()) {
114 form_->setBibButtons(FormCitation::OFF);
115 form_->setCiteButtons(FormCitation::ON);
118 // Highlight the selected browser_cite key in browser_bib
119 vector<string>::const_iterator cit =
120 std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
122 if (cit != form_->bibkeys.end()) {
123 int const n = int(cit - form_->bibkeys.begin());
124 bibLB->setSelected( n, true );
125 bibLB->setTopItem( n );
127 // Put into browser_info the additional info associated
128 // with the selected browser_cite key
130 infoML->setText( biblio::getInfo( theMap, form_->bibkeys[sel] ).c_str() );
133 // form_->bc().input( ButtonPolicy::SMI_VALID );
137 void FormCitationDialogImpl::slotAddClicked()
139 int const sel = bibLB->currentItem();
140 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
141 // form_->bc().input( ButtonPolicy::SMI_NOOP );
145 // Add the selected browser_bib key to browser_cite
146 citeLB->insertItem( form_->bibkeys[sel].c_str() );
147 form_->citekeys.push_back( form_->bibkeys[sel] );
149 int const n = int(form_->citekeys.size());
150 citeLB->setSelected( n-1, true );
152 form_->setBibButtons(FormCitation::OFF);
153 form_->setCiteButtons(FormCitation::ON);
155 // form_->bc().input( ButtonPolicy::SMI_VALID );
159 void FormCitationDialogImpl::slotDelClicked()
161 int const sel = citeLB->currentItem();
162 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
163 // form_->bc().input( ButtonPolicy::SMI_NOOP );
167 // Remove the selected key from browser_cite
168 citeLB->removeItem( sel );
169 form_->citekeys.erase(form_->citekeys.begin() + sel );
171 form_->setBibButtons(FormCitation::ON);
172 form_->setCiteButtons(FormCitation::OFF);
174 // form_->bc().input( ButtonPolicy::SMI_VALID );
178 void FormCitationDialogImpl::slotUpClicked()
180 int const sel = citeLB->currentItem();
181 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
182 // form_->bc().input( ButtonPolicy::SMI_NOOP );
186 // Move the selected key up one line
187 vector<string>::iterator it = form_->citekeys.begin() + sel;
188 string const tmp = *it;
190 citeLB->removeItem( sel );
191 form_->citekeys.erase(it);
193 citeLB->insertItem( tmp.c_str(), sel-1 );
194 citeLB->setSelected( sel-1, true );
195 form_->citekeys.insert(it-1, tmp);
196 form_->setCiteButtons(FormCitation::ON);
198 // form_->bc().input( ButtonPolicy::SMI_VALID );
202 void FormCitationDialogImpl::slotDownClicked()
204 int const sel = citeLB->currentItem();
205 if (sel < 0 || sel >= (int)form_->citekeys.size()-1) {
206 // form_->bc().input( ButtonPolicy::SMI_NOOP );
210 // Move the selected key down one line
211 vector<string>::iterator it = form_->citekeys.begin() + sel;
212 string const tmp = *it;
214 citeLB->removeItem( sel );
215 form_->citekeys.erase(it);
217 citeLB->insertItem( tmp.c_str(), sel+1 );
218 citeLB->setSelected( sel+1, true );
219 form_->citekeys.insert(it+1, tmp);
220 form_->setCiteButtons(FormCitation::ON);
222 // form_->bc().input( ButtonPolicy::SMI_VALID );
226 void FormCitationDialogImpl::slotPreviousClicked()
228 doPreviousNext( false );
232 void FormCitationDialogImpl::slotNextClicked()
234 doPreviousNext( true );
238 void FormCitationDialogImpl::doPreviousNext( bool next )
240 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
241 string const str = searchED->text().latin1();
243 biblio::Direction const dir =
245 biblio::FORWARD : biblio::BACKWARD;
247 biblio::Search const type =
248 searchTypeCB->isChecked() ?
249 biblio::REGEX : biblio::SIMPLE;
251 vector<string>::const_iterator start = form_->bibkeys.begin();
252 int const sel = bibLB->currentItem();
253 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
256 // Find the NEXT instance...
257 if (dir == biblio::FORWARD)
262 bool const caseSensitive = searchCaseCB->isChecked();
264 vector<string>::const_iterator const cit =
265 biblio::searchKeys(theMap, form_->bibkeys, str,
266 start, type, dir, caseSensitive );
268 if (cit == form_->bibkeys.end()) {
269 // form_->bc().input( ButtonPolicy::SMI_NOOP );
273 int const found = int(cit - form_->bibkeys.begin());
275 // form_->bc().input( ButtonPolicy::SMI_NOOP );
279 // Update the display
280 int const top = max(found-5, 1);
281 bibLB->setTopItem( top );
282 bibLB->setSelected( found, true );
283 slotBibSelected( 0 );
285 // form_->bc().input( ButtonPolicy::SMI_VALID );
289 void FormCitationDialogImpl::slotCitationStyleSelected( int )
291 // form_->bc().input( ButtonPolicy::SMI_VALID );
295 void FormCitationDialogImpl::slotTextBeforeReturn()
297 // form_->bc().input( ButtonPolicy::SMI_VALID );
301 void FormCitationDialogImpl::slotTextAfterReturn()
303 // form_->bc().input( ButtonPolicy::SMI_VALID );