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 // Qt defines a macro 'signals' that clashes with a boost namespace.
15 // All is well if the namespace is visible first.
16 #include "insets/ExternalTemplate.h"
18 #include "controllers/ButtonController.h"
19 #include "controllers/ControlExternal.h"
21 #include "support/lstrings.h"
22 #include "support/lyxlib.h"
24 #include "QExternalDialog.h"
26 #include "lengthcombo.h"
27 #include "lengthvalidator.h"
28 #include "qt_helpers.h"
29 #include "QExternal.h"
31 #include <qcheckbox.h>
32 #include <qcombobox.h>
33 #include <qpushbutton.h>
34 #include <qfiledialog.h>
35 #include <qtextview.h>
36 #include <qlineedit.h>
37 #include <qvalidator.h>
39 using lyx::support::float_equal;
40 using lyx::support::isStrDbl;
41 using lyx::support::strToDbl;
49 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
51 LengthValidator * v = new LengthValidator(ed);
52 v->setBottom(LyXLength());
59 QExternalDialog::QExternalDialog(QExternal * form)
60 : QExternalDialogBase(0, 0, false, 0),
63 connect(okPB, SIGNAL(clicked()),
64 form, SLOT(slotOK()));
65 connect(applyPB, SIGNAL(clicked()),
66 form, SLOT(slotApply()));
67 connect(closePB, SIGNAL(clicked()),
68 form, SLOT(slotClose()));
70 QIntValidator * validator = new QIntValidator(displayscaleED);
71 validator->setBottom(1);
72 displayscaleED->setValidator(validator);
74 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
76 xlED->setValidator(new QIntValidator(xlED));
77 ybED->setValidator(new QIntValidator(ybED));
78 xrED->setValidator(new QIntValidator(xrED));
79 ytED->setValidator(new QIntValidator(ytED));
81 // The width is initially set to 'scale' and so should accept
82 // a pure number only.
83 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
84 heightED->setValidator(unsignedLengthValidator(heightED));
88 void QExternalDialog::show()
90 QExternalDialogBase::show();
96 bool QExternalDialog::activateAspectratio() const
98 if (widthUnitCO->currentItem() == 0)
101 string const wstr = fromqstr(widthED->text());
104 bool const wIsDbl = isStrDbl(wstr);
105 if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
108 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
111 string const hstr = fromqstr(heightED->text());
114 bool const hIsDbl = isStrDbl(hstr);
115 if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
117 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
124 void QExternalDialog::bbChanged()
126 form_->controller().bbChanged(true);
131 void QExternalDialog::browseClicked()
133 int const choice = externalCO->currentItem();
134 string const template_name =
135 form_->controller().getTemplate(choice).lyxName;
137 form_->controller().browse(fromqstr(fileED->text()),
139 fileED->setText(toqstr(str));
144 void QExternalDialog::change_adaptor()
150 void QExternalDialog::closeEvent(QCloseEvent * e)
157 void QExternalDialog::editClicked()
159 form_->controller().editExternal();
164 void QExternalDialog::extraChanged(const QString& text)
166 std::string const format = fromqstr(extraFormatCO->currentText());
167 form_->extra_[format] = text;
172 void QExternalDialog::formatChanged(const QString& format)
174 extraED->setText(form_->extra_[fromqstr(format)]);
178 void QExternalDialog::getbbClicked()
184 void QExternalDialog::sizeChanged()
186 aspectratioCB->setEnabled(activateAspectratio());
191 void QExternalDialog::templateChanged()
193 form_->updateTemplate();
198 void QExternalDialog::widthUnitChanged()
200 bool useHeight = (widthUnitCO->currentItem() > 0);
203 widthED->setValidator(unsignedLengthValidator(widthED));
205 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
207 heightED->setEnabled(useHeight);
208 heightUnitCO->setEnabled(useHeight);
212 } // namespace frontend