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 <QCloseEvent>
29 #include "lengthcombo.h"
30 #include "validators.h"
31 #include "qt_helpers.h"
32 #include "QExternal.h"
34 #include <qcheckbox.h>
35 #include <qpushbutton.h>
36 #include <q3filedialog.h>
37 #include <q3textview.h>
38 #include <qlineedit.h>
41 using lyx::support::float_equal;
42 using lyx::support::isStrDbl;
48 QExternalDialog::QExternalDialog(QExternal * form)
52 connect(okPB, SIGNAL(clicked()),
53 form, SLOT(slotOK()));
54 connect(applyPB, SIGNAL(clicked()),
55 form, SLOT(slotApply()));
56 connect(closePB, SIGNAL(clicked()),
57 form, SLOT(slotClose()));
59 connect( displayCB, SIGNAL( toggled(bool) ), showCO, SLOT( setEnabled(bool) ) );
60 connect( displayCB, SIGNAL( toggled(bool) ), displayscaleED, SLOT( setEnabled(bool) ) );
61 connect( showCO, SIGNAL( activated(const QString&) ), this, SLOT( change_adaptor() ) );
62 connect( originCO, SIGNAL( activated(int) ), this, SLOT( change_adaptor() ) );
63 connect( aspectratioCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
64 connect( browsePB, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
65 connect( editPB, SIGNAL( clicked() ), this, SLOT( editClicked() ) );
66 connect( externalCO, SIGNAL( activated(const QString&) ), this, SLOT( templateChanged() ) );
67 connect( extraED, SIGNAL( textChanged(const QString&) ), this, SLOT( extraChanged(const QString&) ) );
68 connect( extraFormatCO, SIGNAL( activated(const QString&) ), this, SLOT( formatChanged(const QString&) ) );
69 connect( widthUnitCO, SIGNAL( activated(int) ), this, SLOT( widthUnitChanged() ) );
70 connect( heightUnitCO, SIGNAL( selectionChanged(LyXLength::UNIT) ), this, SLOT( change_adaptor() ) );
71 connect( displayCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
72 connect( displayscaleED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
73 connect( angleED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
74 connect( widthED, SIGNAL( textChanged(const QString&) ), this, SLOT( sizeChanged() ) );
75 connect( heightED, SIGNAL( textChanged(const QString&) ), this, SLOT( sizeChanged() ) );
76 connect( fileED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
77 connect( clipCB, SIGNAL( stateChanged(int) ), this, SLOT( change_adaptor() ) );
78 connect( getbbPB, SIGNAL( clicked() ), this, SLOT( getbbClicked() ) );
79 connect( xrED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
80 connect( ytED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
81 connect( xlED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
82 connect( ybED, SIGNAL( textChanged(const QString&) ), this, SLOT( bbChanged() ) );
83 connect( draftCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
85 QIntValidator * validator = new QIntValidator(displayscaleED);
86 validator->setBottom(1);
87 displayscaleED->setValidator(validator);
89 angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
91 xlED->setValidator(new QIntValidator(xlED));
92 ybED->setValidator(new QIntValidator(ybED));
93 xrED->setValidator(new QIntValidator(xrED));
94 ytED->setValidator(new QIntValidator(ytED));
96 widthED->setValidator(unsignedLengthValidator(widthED));
97 heightED->setValidator(unsignedLengthValidator(heightED));
99 fileED->setValidator(new PathValidator(true, fileED));
103 void QExternalDialog::show()
111 bool QExternalDialog::activateAspectratio() const
113 if (widthUnitCO->currentItem() == 0)
116 string const wstr = fromqstr(widthED->text());
119 bool const wIsDbl = isStrDbl(wstr);
120 if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
123 if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
126 string const hstr = fromqstr(heightED->text());
129 bool const hIsDbl = isStrDbl(hstr);
130 if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
132 if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
139 void QExternalDialog::bbChanged()
141 form_->controller().bbChanged(true);
146 void QExternalDialog::browseClicked()
148 int const choice = externalCO->currentItem();
149 string const template_name =
150 form_->controller().getTemplate(choice).lyxName;
152 form_->controller().browse(fromqstr(fileED->text()),
154 fileED->setText(toqstr(str));
159 void QExternalDialog::change_adaptor()
165 void QExternalDialog::closeEvent(QCloseEvent * e)
172 void QExternalDialog::editClicked()
174 form_->controller().editExternal();
179 void QExternalDialog::extraChanged(const QString& text)
181 std::string const format = fromqstr(extraFormatCO->currentText());
182 form_->extra_[format] = text;
187 void QExternalDialog::formatChanged(const QString& format)
189 extraED->setText(form_->extra_[fromqstr(format)]);
193 void QExternalDialog::getbbClicked()
199 void QExternalDialog::sizeChanged()
201 aspectratioCB->setEnabled(activateAspectratio());
206 void QExternalDialog::templateChanged()
208 form_->updateTemplate();
213 void QExternalDialog::widthUnitChanged()
215 bool useHeight = (widthUnitCO->currentItem() > 0);
218 widthED->setValidator(unsignedLengthValidator(widthED));
220 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
222 heightED->setEnabled(useHeight);
223 heightUnitCO->setEnabled(useHeight);
227 } // namespace frontend