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/convert.h"
22 #include "support/lstrings.h"
23 #include "support/lyxlib.h"
25 #include "QExternalDialog.h"
27 #include "lengthcombo.h"
28 #include "lengthvalidator.h"
29 #include "qt_helpers.h"
30 #include "QExternal.h"
32 #include <qcheckbox.h>
33 #include <qcombobox.h>
34 #include <qpushbutton.h>
35 #include <qfiledialog.h>
36 #include <qtextview.h>
37 #include <qlineedit.h>
38 #include <qvalidator.h>
40 using lyx::support::float_equal;
41 using lyx::support::isStrDbl;
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 widthED->setValidator(unsignedLengthValidator(widthED));
82 heightED->setValidator(unsignedLengthValidator(heightED));
86 void QExternalDialog::show()
88 QExternalDialogBase::show();
94 bool QExternalDialog::activateAspectratio() const
96 if (widthUnitCO->currentItem() == 0)
99 string const wstr = fromqstr(widthED->text());
102 bool const wIsDbl = isStrDbl(wstr);
103 if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
106 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
109 string const hstr = fromqstr(heightED->text());
112 bool const hIsDbl = isStrDbl(hstr);
113 if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
115 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
122 void QExternalDialog::bbChanged()
124 form_->controller().bbChanged(true);
129 void QExternalDialog::browseClicked()
131 int const choice = externalCO->currentItem();
132 string const template_name =
133 form_->controller().getTemplate(choice).lyxName;
135 form_->controller().browse(fromqstr(fileED->text()),
137 fileED->setText(toqstr(str));
142 void QExternalDialog::change_adaptor()
148 void QExternalDialog::closeEvent(QCloseEvent * e)
155 void QExternalDialog::editClicked()
157 form_->controller().editExternal();
162 void QExternalDialog::extraChanged(const QString& text)
164 std::string const format = fromqstr(extraFormatCO->currentText());
165 form_->extra_[format] = text;
170 void QExternalDialog::formatChanged(const QString& format)
172 extraED->setText(form_->extra_[fromqstr(format)]);
176 void QExternalDialog::getbbClicked()
182 void QExternalDialog::sizeChanged()
184 aspectratioCB->setEnabled(activateAspectratio());
189 void QExternalDialog::templateChanged()
191 form_->updateTemplate();
196 void QExternalDialog::widthUnitChanged()
198 bool useHeight = (widthUnitCO->currentItem() > 0);
201 widthED->setValidator(unsignedLengthValidator(widthED));
203 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
205 heightED->setEnabled(useHeight);
206 heightUnitCO->setEnabled(useHeight);
210 } // namespace frontend