2 * $Id: FormCitationDialogImpl.C,v 1.6 2001/04/02 20:08:43 kalle Exp $
5 #include "FormCitationDialogImpl.h"
7 #include "FormCitation.h"
9 #include "controllers/biblio.h"
10 #include "controllers/ControlCitation.h"
12 #include <qcheckbox.h>
13 #include <qlineedit.h>
15 #include <qmultilineedit.h>
16 #include <qpushbutton.h>
27 * Constructs a FormCitationDialogImpl which is a child of 'parent', with the
28 * name 'name' and widget flags set to 'f'
30 * The dialog will by default be modeless, unless you set 'modal' to
31 * TRUE to construct a modal dialog.
33 FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* parent, const char* name, bool modal, WFlags fl )
34 : FormCitationDialog( parent, name, modal, fl ),
37 connect( okPB, SIGNAL( clicked() ),
38 form, SLOT( slotOK() ) );
39 connect( cancelPB, SIGNAL( clicked() ),
40 form, SLOT( slotCancel() ) );
41 connect( restorePB, SIGNAL( clicked() ),
42 form, SLOT( slotRestore() ) );
43 connect( applyPB, SIGNAL( clicked() ),
44 form, SLOT( slotApply() ) );
48 * Destroys the object and frees any allocated resources
50 FormCitationDialogImpl::~FormCitationDialogImpl()
52 // no need to delete child widgets, Qt does it all for us
56 // These slots correspond to the XForms input() method.
57 void FormCitationDialogImpl::slotBibSelected( int sel )
59 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
61 citeLB->clearSelection();
63 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
64 // form_->bc().input( ButtonPolicy::SMI_NOOP );
68 // Put into browser_info the additional info associated with
69 // the selected browser_bib key
72 infoML->setText( biblio::getInfo( theMap,
73 form_->bibkeys[sel-1] ).c_str() );
75 // Highlight the selected browser_bib key in browser_cite if
77 vector<string>::const_iterator cit =
78 std::find(form_->citekeys.begin(), form_->citekeys.end(),
81 if (cit != form_->citekeys.end()) {
82 int const n = int(cit - form_->citekeys.begin());
83 citeLB->setSelected( n, true );
84 citeLB->setTopItem( n );
87 if (!form_->controller().isReadonly()) {
88 if (cit != form_->citekeys.end()) {
89 form_->setBibButtons(FormCitation::OFF);
90 form_->setCiteButtons(FormCitation::ON);
92 form_->setBibButtons(FormCitation::ON);
93 form_->setCiteButtons(FormCitation::OFF);
97 // form_->bc().input( ButtonPolicy::SMI_VALID );
101 void FormCitationDialogImpl::slotCiteSelected( int sel )
103 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
105 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
106 // form_->bc().input( ButtonPolicy::SMI_NOOP );
110 if (!form_->controller().isReadonly()) {
111 form_->setBibButtons(FormCitation::OFF);
112 form_->setCiteButtons(FormCitation::ON);
115 // Highlight the selected browser_cite key in browser_bib
116 vector<string>::const_iterator cit =
117 std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
119 if (cit != form_->bibkeys.end()) {
120 int const n = int(cit - form_->bibkeys.begin());
121 bibLB->setSelected( n, true );
122 bibLB->setTopItem( n );
124 // Put into browser_info the additional info associated
125 // with the selected browser_cite key
127 infoML->setText( biblio::getInfo( theMap, form_->bibkeys[sel] ).c_str() );
130 // form_->bc().input( ButtonPolicy::SMI_VALID );
134 void FormCitationDialogImpl::slotAddClicked()
136 int const sel = bibLB->currentItem();
137 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
138 // form_->bc().input( ButtonPolicy::SMI_NOOP );
142 // Add the selected browser_bib key to browser_cite
143 citeLB->insertItem( form_->bibkeys[sel].c_str() );
144 form_->citekeys.push_back( form_->bibkeys[sel] );
146 int const n = int(form_->citekeys.size());
147 citeLB->setSelected( n-1, true );
149 form_->setBibButtons(FormCitation::OFF);
150 form_->setCiteButtons(FormCitation::ON);
152 // form_->bc().input( ButtonPolicy::SMI_VALID );
156 void FormCitationDialogImpl::slotDelClicked()
158 int const sel = citeLB->currentItem();
159 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
160 // form_->bc().input( ButtonPolicy::SMI_NOOP );
164 // Remove the selected key from browser_cite
165 citeLB->removeItem( sel );
166 form_->citekeys.erase(form_->citekeys.begin() + sel );
168 form_->setBibButtons(FormCitation::ON);
169 form_->setCiteButtons(FormCitation::OFF);
171 // form_->bc().input( ButtonPolicy::SMI_VALID );
175 void FormCitationDialogImpl::slotUpClicked()
177 int const sel = citeLB->currentItem();
178 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
179 // form_->bc().input( ButtonPolicy::SMI_NOOP );
183 // Move the selected key up one line
184 vector<string>::iterator it = form_->citekeys.begin() + sel;
185 string const tmp = *it;
187 citeLB->removeItem( sel );
188 form_->citekeys.erase(it);
190 citeLB->insertItem( tmp.c_str(), sel-1 );
191 citeLB->setSelected( sel-1, true );
192 form_->citekeys.insert(it-1, tmp);
193 form_->setCiteButtons(FormCitation::ON);
195 // form_->bc().input( ButtonPolicy::SMI_VALID );
199 void FormCitationDialogImpl::slotDownClicked()
201 int const sel = citeLB->currentItem();
202 if (sel < 0 || sel >= (int)form_->citekeys.size()-1) {
203 // form_->bc().input( ButtonPolicy::SMI_NOOP );
207 // Move the selected key down one line
208 vector<string>::iterator it = form_->citekeys.begin() + sel;
209 string const tmp = *it;
211 citeLB->removeItem( sel );
212 form_->citekeys.erase(it);
214 citeLB->insertItem( tmp.c_str(), sel+1 );
215 citeLB->setSelected( sel+1, true );
216 form_->citekeys.insert(it+1, tmp);
217 form_->setCiteButtons(FormCitation::ON);
219 // form_->bc().input( ButtonPolicy::SMI_VALID );
223 void FormCitationDialogImpl::slotPreviousClicked()
225 doPreviousNext( false );
229 void FormCitationDialogImpl::slotNextClicked()
231 doPreviousNext( true );
235 void FormCitationDialogImpl::doPreviousNext( bool next )
237 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
238 string const str = searchED->text().latin1();
240 biblio::Direction const dir =
242 biblio::FORWARD : biblio::BACKWARD;
244 biblio::Search const type =
245 searchTypeCB->isChecked() ?
246 biblio::REGEX : biblio::SIMPLE;
248 vector<string>::const_iterator start = form_->bibkeys.begin();
249 int const sel = bibLB->currentItem();
250 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
253 // Find the NEXT instance...
254 if (dir == biblio::FORWARD)
259 bool const caseSensitive = searchCaseCB->isChecked();
261 vector<string>::const_iterator const cit =
262 biblio::searchKeys(theMap, form_->bibkeys, str,
263 start, type, dir, caseSensitive );
265 if (cit == form_->bibkeys.end()) {
266 // form_->bc().input( ButtonPolicy::SMI_NOOP );
270 int const found = int(cit - form_->bibkeys.begin());
272 // form_->bc().input( ButtonPolicy::SMI_NOOP );
276 // Update the display
277 int const top = max(found-5, 1);
278 bibLB->setTopItem( top );
279 bibLB->setSelected( found, true );
280 slotBibSelected( 0 );
282 // form_->bc().input( ButtonPolicy::SMI_VALID );
286 void FormCitationDialogImpl::slotCitationStyleSelected( int )
288 // form_->bc().input( ButtonPolicy::SMI_VALID );
292 void FormCitationDialogImpl::slotTextBeforeReturn()
294 // form_->bc().input( ButtonPolicy::SMI_VALID );
298 void FormCitationDialogImpl::slotTextAfterReturn()
300 // form_->bc().input( ButtonPolicy::SMI_VALID );