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 "validators.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>
40 using lyx::support::float_equal;
41 using lyx::support::isStrDbl;
47 QExternalDialog::QExternalDialog(QExternal * form)
48 : QExternalDialogBase(0, 0, false, 0),
51 connect(okPB, SIGNAL(clicked()),
52 form, SLOT(slotOK()));
53 connect(applyPB, SIGNAL(clicked()),
54 form, SLOT(slotApply()));
55 connect(closePB, SIGNAL(clicked()),
56 form, SLOT(slotClose()));
58 QIntValidator * validator = new QIntValidator(displayscaleED);
59 validator->setBottom(1);
60 displayscaleED->setValidator(validator);
62 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
64 xlED->setValidator(new QIntValidator(xlED));
65 ybED->setValidator(new QIntValidator(ybED));
66 xrED->setValidator(new QIntValidator(xrED));
67 ytED->setValidator(new QIntValidator(ytED));
69 widthED->setValidator(unsignedLengthValidator(widthED));
70 heightED->setValidator(unsignedLengthValidator(heightED));
72 fileED->setValidator(new PathValidator(true, fileED));
76 void QExternalDialog::show()
78 QExternalDialogBase::show();
84 bool QExternalDialog::activateAspectratio() const
86 if (widthUnitCO->currentItem() == 0)
89 string const wstr = fromqstr(widthED->text());
92 bool const wIsDbl = isStrDbl(wstr);
93 if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
96 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
99 string const hstr = fromqstr(heightED->text());
102 bool const hIsDbl = isStrDbl(hstr);
103 if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
105 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
112 void QExternalDialog::bbChanged()
114 form_->controller().bbChanged(true);
119 void QExternalDialog::browseClicked()
121 int const choice = externalCO->currentItem();
122 string const template_name =
123 form_->controller().getTemplate(choice).lyxName;
125 form_->controller().browse(fromqstr(fileED->text()),
127 fileED->setText(toqstr(str));
132 void QExternalDialog::change_adaptor()
138 void QExternalDialog::closeEvent(QCloseEvent * e)
145 void QExternalDialog::editClicked()
147 form_->controller().editExternal();
152 void QExternalDialog::extraChanged(const QString& text)
154 std::string const format = fromqstr(extraFormatCO->currentText());
155 form_->extra_[format] = text;
160 void QExternalDialog::formatChanged(const QString& format)
162 extraED->setText(form_->extra_[fromqstr(format)]);
166 void QExternalDialog::getbbClicked()
172 void QExternalDialog::sizeChanged()
174 aspectratioCB->setEnabled(activateAspectratio());
179 void QExternalDialog::templateChanged()
181 form_->updateTemplate();
186 void QExternalDialog::widthUnitChanged()
188 bool useHeight = (widthUnitCO->currentItem() > 0);
191 widthED->setValidator(unsignedLengthValidator(widthED));
193 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
195 heightED->setEnabled(useHeight);
196 heightUnitCO->setEnabled(useHeight);
200 } // namespace frontend
203 #include "QExternalDialog_moc.cpp"