3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "ControlRef.h"
15 #include "insets/insetref.h"
18 #include "QRefDialog.h"
21 #include <qlineedit.h>
22 #include <qcheckbox.h>
24 #include <qcombobox.h>
25 #include <qpushbutton.h>
28 #include "qt_helpers.h"
34 typedef QController<ControlRef, QView<QRefDialog> > base_class;
37 QRef::QRef(Dialog & parent)
38 : base_class(parent, _("LyX: Cross-reference")),
39 sort_(false), at_ref_(false)
44 void QRef::build_dialog()
46 dialog_.reset(new QRefDialog(this));
48 bcview().setOK(dialog_->okPB);
49 bcview().setApply(dialog_->applyPB);
50 bcview().setCancel(dialog_->closePB);
51 bcview().addReadOnly(dialog_->refsLB);
52 bcview().addReadOnly(dialog_->sortCB);
53 bcview().addReadOnly(dialog_->nameED);
54 bcview().addReadOnly(dialog_->referenceED);
55 bcview().addReadOnly(dialog_->typeCO);
56 bcview().addReadOnly(dialog_->bufferCO);
60 void QRef::update_contents()
62 InsetCommandParams const & params = controller().params();
64 dialog_->referenceED->setText(toqstr(params.getContents()));
66 dialog_->nameED->setText(toqstr(params.getOptions()));
67 dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
69 dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
70 dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
72 dialog_->typeCO->setCurrentItem(0);
74 dialog_->sortCB->setChecked(sort_);
77 dialog_->bufferCO->clear();
78 vector<string> const buffers = controller().getBufferList();
79 for (vector<string>::const_iterator it = buffers.begin();
80 it != buffers.end(); ++it) {
81 dialog_->bufferCO->insertItem(toqstr(*it));
83 dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
91 InsetCommandParams & params = controller().params();
93 params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
94 params.setContents(fromqstr(dialog_->referenceED->text()));
95 params.setOptions(fromqstr(dialog_->nameED->text()));
99 bool QRef::nameAllowed()
101 Kernel::DocTypes doc_type = kernel().docType();
102 return doc_type != Kernel::LATEX &&
103 doc_type != Kernel::LITERATE;
107 bool QRef::typeAllowed()
109 Kernel::DocTypes doc_type = kernel().docType();
110 return doc_type != Kernel::LINUXDOC &&
111 doc_type != Kernel::DOCBOOK;
115 void QRef::setGoBack()
117 dialog_->gotoPB->setText(qt_("&Go Back"));
118 QToolTip::remove(dialog_->gotoPB);
119 QToolTip::add(dialog_->gotoPB, qt_("Jump back"));
123 void QRef::setGotoRef()
125 dialog_->gotoPB->setText(qt_("&Go to Reference"));
126 QToolTip::remove(dialog_->gotoPB);
127 QToolTip::add(dialog_->gotoPB, qt_("Jump to reference"));
133 string ref(fromqstr(dialog_->referenceED->text()));
138 controller().gotoBookmark();
142 controller().gotoRef(ref);
148 void QRef::redoRefs()
150 dialog_->refsLB->setAutoUpdate(false);
151 dialog_->refsLB->clear();
153 // need this because Qt will send a highlight() here for
154 // the first item inserted
155 QString const tmp(dialog_->referenceED->text());
157 for (std::vector<string>::const_iterator iter = refs_.begin();
158 iter != refs_.end(); ++iter) {
159 dialog_->refsLB->insertItem(toqstr(*iter));
163 dialog_->refsLB->sort();
165 dialog_->referenceED->setText(tmp);
167 for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
168 if (tmp == dialog_->refsLB->text(i))
169 dialog_->refsLB->setCurrentItem(i);
172 dialog_->refsLB->setAutoUpdate(true);
173 dialog_->refsLB->update();
177 void QRef::updateRefs()
182 string const name = controller().getBufferName(dialog_->bufferCO->currentItem());
183 refs_ = controller().getLabelList(name);
184 dialog_->sortCB->setEnabled(!refs_.empty());
185 dialog_->refsLB->setEnabled(!refs_.empty());