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 <QCloseEvent>
34 #include <QPushButton>
35 #include <QTextBrowser>
39 using lyx::support::float_equal;
40 using lyx::support::isStrDbl;
46 QExternalDialog::QExternalDialog(QExternal * form)
50 connect(okPB, SIGNAL(clicked()),
51 form, SLOT(slotOK()));
52 connect(applyPB, SIGNAL(clicked()),
53 form, SLOT(slotApply()));
54 connect(closePB, SIGNAL(clicked()),
55 form, SLOT(slotClose()));
57 connect( displayCB, SIGNAL( toggled(bool) ), showCO, SLOT( setEnabled(bool) ) );
58 connect( displayCB, SIGNAL( toggled(bool) ), displayscaleED, SLOT( setEnabled(bool) ) );
59 connect( showCO, SIGNAL( activated(const QString&) ), this, SLOT( change_adaptor() ) );
60 connect( originCO, SIGNAL( activated(int) ), this, SLOT( change_adaptor() ) );
61 connect( aspectratioCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
62 connect( browsePB, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
63 connect( editPB, SIGNAL( clicked() ), this, SLOT( editClicked() ) );
64 connect( externalCO, SIGNAL( activated(const QString&) ), this, SLOT( templateChanged() ) );
65 connect( extraED, SIGNAL( textChanged(const QString&) ), this, SLOT( extraChanged(const QString&) ) );
66 connect( extraFormatCO, SIGNAL( activated(const QString&) ), this, SLOT( formatChanged(const QString&) ) );
67 connect( widthUnitCO, SIGNAL( activated(int) ), this, SLOT( widthUnitChanged() ) );
68 connect( heightUnitCO, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ), this, SLOT( change_adaptor() ) );
69 connect( displayCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
70 connect( displayscaleED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
71 connect( angleED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
72 connect( widthED, SIGNAL( textChanged(const QString&) ), this, SLOT( sizeChanged() ) );
73 connect( heightED, SIGNAL( textChanged(const QString&) ), this, SLOT( sizeChanged() ) );
74 connect( fileED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
75 connect( clipCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
76 connect( getbbPB, SIGNAL( clicked() ), this, SLOT( getbbClicked() ) );
77 connect( xrED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
78 connect( ytED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
79 connect( xlED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
80 connect( ybED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
81 connect( draftCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
83 QIntValidator * validator = new QIntValidator(displayscaleED);
84 validator->setBottom(1);
85 displayscaleED->setValidator(validator);
87 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
89 xlED->setValidator(new QIntValidator(xlED));
90 ybED->setValidator(new QIntValidator(ybED));
91 xrED->setValidator(new QIntValidator(xrED));
92 ytED->setValidator(new QIntValidator(ytED));
94 widthED->setValidator(unsignedLengthValidator(widthED));
95 heightED->setValidator(unsignedLengthValidator(heightED));
97 fileED->setValidator(new PathValidator(true, fileED));
101 void QExternalDialog::show()
109 bool QExternalDialog::activateAspectratio() const
111 if (widthUnitCO->currentIndex() == 0)
114 string const wstr = fromqstr(widthED->text());
117 bool const wIsDbl = isStrDbl(wstr);
118 if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
121 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
124 string const hstr = fromqstr(heightED->text());
127 bool const hIsDbl = isStrDbl(hstr);
128 if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
130 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
137 void QExternalDialog::bbChanged()
139 form_->controller().bbChanged(true);
144 void QExternalDialog::browseClicked()
146 int const choice = externalCO->currentIndex();
147 docstring const template_name =
148 lyx::from_utf8(form_->controller().getTemplate(choice).lyxName);
149 docstring const str =
150 form_->controller().browse(qstring_to_ucs4(fileED->text()),
152 fileED->setText(toqstr(str));
157 void QExternalDialog::change_adaptor()
163 void QExternalDialog::closeEvent(QCloseEvent * e)
170 void QExternalDialog::editClicked()
172 form_->controller().editExternal();
177 void QExternalDialog::extraChanged(const QString& text)
179 std::string const format = fromqstr(extraFormatCO->currentText());
180 form_->extra_[format] = text;
185 void QExternalDialog::formatChanged(const QString& format)
187 extraED->setText(form_->extra_[fromqstr(format)]);
191 void QExternalDialog::getbbClicked()
197 void QExternalDialog::sizeChanged()
199 aspectratioCB->setEnabled(activateAspectratio());
204 void QExternalDialog::templateChanged()
206 form_->updateTemplate();
211 void QExternalDialog::widthUnitChanged()
213 bool useHeight = (widthUnitCO->currentIndex() > 0);
216 widthED->setValidator(unsignedLengthValidator(widthED));
218 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
220 heightED->setEnabled(useHeight);
221 heightUnitCO->setEnabled(useHeight);
225 } // namespace frontend
228 #include "QExternalDialog_moc.cpp"