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 "controllers/ButtonController.h"
15 #include "controllers/ControlExternal.h"
17 #include "support/lstrings.h"
18 #include "support/lyxlib.h"
20 #include "QExternalDialog.h"
22 #include "lengthcombo.h"
23 #include "lengthvalidator.h"
24 #include "qt_helpers.h"
25 #include "QExternal.h"
27 #include <qcheckbox.h>
28 #include <qcombobox.h>
29 #include <qpushbutton.h>
30 #include <qfiledialog.h>
31 #include <qtextview.h>
32 #include <qlineedit.h>
33 #include <qvalidator.h>
35 using lyx::support::float_equal;
36 using lyx::support::isStrDbl;
37 using lyx::support::strToDbl;
43 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
45 LengthValidator * v = new LengthValidator(ed);
46 v->setBottom(LyXLength());
53 QExternalDialog::QExternalDialog(QExternal * form)
54 : QExternalDialogBase(0, 0, false, 0),
57 connect(okPB, SIGNAL(clicked()),
58 form, SLOT(slotOK()));
59 connect(applyPB, SIGNAL(clicked()),
60 form, SLOT(slotApply()));
61 connect(closePB, SIGNAL(clicked()),
62 form, SLOT(slotClose()));
64 QIntValidator * validator = new QIntValidator(displayscaleED);
65 validator->setBottom(1);
66 displayscaleED->setValidator(validator);
68 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
70 xlED->setValidator(new QIntValidator(xlED));
71 ybED->setValidator(new QIntValidator(ybED));
72 xrED->setValidator(new QIntValidator(xrED));
73 ytED->setValidator(new QIntValidator(ytED));
75 // The width is initially set to 'scale' and so should accept
76 // a pure number only.
77 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
78 heightED->setValidator(unsignedLengthValidator(heightED));
82 void QExternalDialog::show()
84 QExternalDialogBase::show();
90 bool QExternalDialog::activateAspectratio() const
92 if (widthUnitCO->currentItem() == 0)
95 string const wstr = fromqstr(widthED->text());
98 bool const wIsDbl = isStrDbl(wstr);
99 if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
102 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
105 string const hstr = fromqstr(heightED->text());
108 bool const hIsDbl = isStrDbl(hstr);
109 if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
111 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
118 void QExternalDialog::bbChanged()
120 form_->controller().bbChanged(true);
125 void QExternalDialog::browseClicked()
128 form_->controller().Browse(fromqstr(fileED->text()));
129 fileED->setText(toqstr(str));
134 void QExternalDialog::change_adaptor()
140 void QExternalDialog::closeEvent(QCloseEvent * e)
147 void QExternalDialog::editClicked()
149 form_->controller().editExternal();
154 void QExternalDialog::extraChanged(const QString& text)
156 std::string const format = fromqstr(extraFormatCO->currentText());
157 form_->extra_[format] = text;
162 void QExternalDialog::formatChanged(const QString& format)
164 extraED->setText(form_->extra_[fromqstr(format)]);
168 void QExternalDialog::getbbClicked()
174 void QExternalDialog::sizeChanged()
176 aspectratioCB->setEnabled(activateAspectratio());
181 void QExternalDialog::templateChanged()
183 form_->updateTemplate();
188 void QExternalDialog::widthUnitChanged()
190 bool useHeight = (widthUnitCO->currentItem() > 0);
193 widthED->setValidator(unsignedLengthValidator(widthED));
195 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
197 heightED->setEnabled(useHeight);
198 heightUnitCO->setEnabled(useHeight);