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 "ControlExternal.h"
15 #include "qt_helpers.h"
17 #include "insets/ExternalTemplate.h"
18 #include "insets/insetexternal.h"
20 #include "support/lstrings.h"
21 #include "support/tostr.h"
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qcheckbox.h>
26 #include <qcombobox.h>
27 #include <qtextview.h>
29 #include "QExternalDialog.h"
30 #include "QExternal.h"
33 using lyx::support::strToInt;
34 using lyx::support::trim;
39 typedef QController<ControlExternal, QView<QExternalDialog> > base_class;
41 QExternal::QExternal(Dialog & parent)
42 : base_class(parent, _("LyX: External Material"))
47 void QExternal::build_dialog()
49 dialog_.reset(new QExternalDialog(this));
51 bcview().setOK(dialog_->okPB);
52 bcview().setApply(dialog_->applyPB);
53 bcview().setCancel(dialog_->closePB);
54 bcview().addReadOnly(dialog_->externalCO);
55 bcview().addReadOnly(dialog_->fileED);
56 bcview().addReadOnly(dialog_->browsePB);
57 bcview().addReadOnly(dialog_->extraED);
59 std::vector<string> templates(controller().getTemplates());
61 for (std::vector<string>::const_iterator cit = templates.begin();
62 cit != templates.end(); ++cit) {
63 dialog_->externalCO->insertItem(toqstr(*cit), -1);
68 void QExternal::update_contents()
70 InsetExternalParams const & params = controller().params();
73 params.filename.outputFilename(kernel().bufferFilepath());
74 dialog_->fileED->setText(toqstr(name));
76 dialog_->externalCO->setCurrentItem(controller()
77 .getTemplateNumber(params.templatename()));
81 switch (params.display) {
82 case lyx::external::DefaultDisplay: item = 0; break;
83 case lyx::external::MonochromeDisplay: item = 1; break;
84 case lyx::external::GrayscaleDisplay: item = 2; break;
85 case lyx::external::ColorDisplay: item = 3; break;
86 case lyx::external::PreviewDisplay: item = 4; break;
87 case lyx::external::NoDisplay: item = 0; break;
89 dialog_->showCB->setCurrentItem(item);
90 dialog_->showCB->setEnabled(params.display != lyx::external::NoDisplay &&
92 dialog_->displayCB->setChecked(params.display != lyx::external::NoDisplay);
93 dialog_->displayscale->setEnabled(params.display != lyx::external::NoDisplay &&
95 dialog_->displayscale->setText(toqstr(tostr(params.lyxscale)));
101 void QExternal::updateTemplate()
103 namespace external = lyx::external;
105 dialog_->externalTV->setText(toqstr(helpText()));
107 // Ascertain whether the template has any formats supporting
108 // the 'Extra' option
109 QLineEdit * const input = dialog_->extraED;
110 QComboBox * const combo = dialog_->extraFormatCB;
116 external::Template templ =
117 controller().getTemplate(dialog_->externalCO->currentItem());
118 external::Template::Formats::const_iterator it = templ.formats.begin();
119 external::Template::Formats::const_iterator end = templ.formats.end();
120 for (; it != end; ++it) {
121 if (it->second.option_transformers.find(external::Extra) ==
122 it->second.option_transformers.end())
124 string const format = it->first;
125 string const opt = controller().params().extradata.get(format);
126 combo->insertItem(toqstr(format));
127 extra_[format] = toqstr(opt);
130 bool const enabled = combo->count() > 0;
132 input->setEnabled(enabled && !kernel().isBufferReadonly());
133 combo->setEnabled(enabled);
136 combo->setCurrentItem(0);
137 input->setText(extra_[fromqstr(combo->currentText())]);
142 string const QExternal::helpText() const
144 lyx::external::Template templ =
145 controller().getTemplate(dialog_->externalCO->currentItem());
146 return templ.helpText;
150 void QExternal::apply()
152 InsetExternalParams params = controller().params();
154 params.filename.set(fromqstr(dialog_->fileED->text()),
155 kernel().bufferFilepath());
158 controller().getTemplate(dialog_->externalCO->currentItem()).lyxName);
160 switch (dialog_->showCB->currentItem()) {
161 case 0: params.display = lyx::external::DefaultDisplay; break;
162 case 1: params.display = lyx::external::MonochromeDisplay; break;
163 case 2: params.display = lyx::external::GrayscaleDisplay; break;
164 case 3: params.display = lyx::external::ColorDisplay; break;
165 case 4: params.display = lyx::external::PreviewDisplay; break;
169 if (!dialog_->displayCB->isChecked())
170 params.display = lyx::external::NoDisplay;
172 params.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
174 std::map<string, QString>::const_iterator it = extra_.begin();
175 std::map<string, QString>::const_iterator end = extra_.end();
176 for (; it != end; ++it)
177 params.extradata.set(it->first, trim(fromqstr(it->second)));
179 controller().setParams(params);