2 * \file QExternalDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
14 #include "insets/ExternalTemplate.h"
16 #include "controllers/ButtonController.h"
17 #include "controllers/ControlExternal.h"
19 #include "support/lstrings.h"
20 #include "support/lyxlib.h"
22 #include "QExternalDialog.h"
24 #include "lengthcombo.h"
25 #include "lengthvalidator.h"
26 #include "qt_helpers.h"
27 #include "QExternal.h"
29 #include <qcheckbox.h>
30 #include <qcombobox.h>
31 #include <qpushbutton.h>
32 #include <qfiledialog.h>
33 #include <qtextview.h>
34 #include <qlineedit.h>
35 #include <qvalidator.h>
37 using lyx::support::float_equal;
38 using lyx::support::isStrDbl;
39 using lyx::support::strToDbl;
45 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
47 LengthValidator * v = new LengthValidator(ed);
48 v->setBottom(LyXLength());
55 QExternalDialog::QExternalDialog(QExternal * form)
56 : QExternalDialogBase(0, 0, false, 0),
59 connect(okPB, SIGNAL(clicked()),
60 form, SLOT(slotOK()));
61 connect(applyPB, SIGNAL(clicked()),
62 form, SLOT(slotApply()));
63 connect(closePB, SIGNAL(clicked()),
64 form, SLOT(slotClose()));
66 QIntValidator * validator = new QIntValidator(displayscaleED);
67 validator->setBottom(1);
68 displayscaleED->setValidator(validator);
70 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
72 xlED->setValidator(new QIntValidator(xlED));
73 ybED->setValidator(new QIntValidator(ybED));
74 xrED->setValidator(new QIntValidator(xrED));
75 ytED->setValidator(new QIntValidator(ytED));
77 // The width is initially set to 'scale' and so should accept
78 // a pure number only.
79 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
80 heightED->setValidator(unsignedLengthValidator(heightED));
84 void QExternalDialog::show()
86 QExternalDialogBase::show();
92 bool QExternalDialog::activateAspectratio() const
94 if (widthUnitCO->currentItem() == 0)
97 string const wstr = fromqstr(widthED->text());
100 bool const wIsDbl = isStrDbl(wstr);
101 if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
104 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
107 string const hstr = fromqstr(heightED->text());
110 bool const hIsDbl = isStrDbl(hstr);
111 if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
113 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
120 void QExternalDialog::bbChanged()
122 form_->controller().bbChanged(true);
127 void QExternalDialog::browseClicked()
129 int const choice = externalCO->currentItem();
130 string const template_name =
131 form_->controller().getTemplate(choice).lyxName;
133 form_->controller().browse(fromqstr(fileED->text()),
135 fileED->setText(toqstr(str));
140 void QExternalDialog::change_adaptor()
146 void QExternalDialog::closeEvent(QCloseEvent * e)
153 void QExternalDialog::editClicked()
155 form_->controller().editExternal();
160 void QExternalDialog::extraChanged(const QString& text)
162 std::string const format = fromqstr(extraFormatCO->currentText());
163 form_->extra_[format] = text;
168 void QExternalDialog::formatChanged(const QString& format)
170 extraED->setText(form_->extra_[fromqstr(format)]);
174 void QExternalDialog::getbbClicked()
180 void QExternalDialog::sizeChanged()
182 aspectratioCB->setEnabled(activateAspectratio());
187 void QExternalDialog::templateChanged()
189 form_->updateTemplate();
194 void QExternalDialog::widthUnitChanged()
196 bool useHeight = (widthUnitCO->currentItem() > 0);
199 widthED->setValidator(unsignedLengthValidator(widthED));
201 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
203 heightED->setEnabled(useHeight);
204 heightUnitCO->setEnabled(useHeight);