]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QExternalDialog.C
Extracted from r14281
[lyx.git] / src / frontends / qt3 / QExternalDialog.C
1 /**
2  * \file QExternalDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
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"
17
18 #include "controllers/ButtonController.h"
19 #include "controllers/ControlExternal.h"
20
21 #include "support/convert.h"
22 #include "support/lstrings.h"
23 #include "support/lyxlib.h"
24
25 #include "QExternalDialog.h"
26
27 #include "lengthcombo.h"
28 #include "validators.h"
29 #include "qt_helpers.h"
30 #include "QExternal.h"
31
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
39
40 using lyx::support::float_equal;
41 using lyx::support::isStrDbl;
42 using std::string;
43
44 namespace lyx {
45 namespace frontend {
46
47 QExternalDialog::QExternalDialog(QExternal * form)
48         : QExternalDialogBase(0, 0, false, 0),
49           form_(form)
50 {
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()));
57
58         QIntValidator * validator = new QIntValidator(displayscaleED);
59         validator->setBottom(1);
60         displayscaleED->setValidator(validator);
61
62         angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
63
64         xlED->setValidator(new QIntValidator(xlED));
65         ybED->setValidator(new QIntValidator(ybED));
66         xrED->setValidator(new QIntValidator(xrED));
67         ytED->setValidator(new QIntValidator(ytED));
68
69         widthED->setValidator(unsignedLengthValidator(widthED));
70         heightED->setValidator(unsignedLengthValidator(heightED));
71
72         fileED->setValidator(new PathValidator(true, fileED));
73 }
74
75
76 void QExternalDialog::show()
77 {
78         QExternalDialogBase::show();
79         fileED->setFocus();
80 }
81
82
83
84 bool QExternalDialog::activateAspectratio() const
85 {
86         if (widthUnitCO->currentItem() == 0)
87                 return false;
88
89         string const wstr = fromqstr(widthED->text());
90         if (wstr.empty())
91                 return false;
92         bool const wIsDbl = isStrDbl(wstr);
93         if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
94                 return false;
95         LyXLength l;
96         if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
97                 return false;
98
99         string const hstr = fromqstr(heightED->text());
100         if (hstr.empty())
101                 return false;
102         bool const hIsDbl = isStrDbl(hstr);
103         if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
104                 return false;
105         if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
106                 return false;
107
108         return true;
109 }
110
111
112 void QExternalDialog::bbChanged()
113 {
114         form_->controller().bbChanged(true);
115         form_->changed();
116 }
117
118
119 void QExternalDialog::browseClicked()
120 {
121         int const choice =  externalCO->currentItem();
122         string const template_name =
123                 form_->controller().getTemplate(choice).lyxName;
124         string const str =
125                 form_->controller().browse(fromqstr(fileED->text()),
126                                            template_name);
127         fileED->setText(toqstr(str));
128         form_->changed();
129 }
130
131
132 void QExternalDialog::change_adaptor()
133 {
134         form_->changed();
135 }
136
137
138 void QExternalDialog::closeEvent(QCloseEvent * e)
139 {
140         form_->slotWMHide();
141         e->accept();
142 }
143
144
145 void QExternalDialog::editClicked()
146 {
147         form_->controller().editExternal();
148 }
149
150
151
152 void QExternalDialog::extraChanged(const QString& text)
153 {
154         std::string const format = fromqstr(extraFormatCO->currentText());
155         form_->extra_[format] = text;
156         form_->changed();
157 }
158
159
160 void QExternalDialog::formatChanged(const QString& format)
161 {
162         extraED->setText(form_->extra_[fromqstr(format)]);
163 }
164
165
166 void QExternalDialog::getbbClicked()
167 {
168         form_->getBB();
169 }
170
171
172 void QExternalDialog::sizeChanged()
173 {
174         aspectratioCB->setEnabled(activateAspectratio());
175         form_->changed();
176 }
177
178
179 void QExternalDialog::templateChanged()
180 {
181         form_->updateTemplate();
182         form_->changed();
183 }
184
185
186 void QExternalDialog::widthUnitChanged()
187 {
188         bool useHeight = (widthUnitCO->currentItem() > 0);
189
190         if (useHeight)
191                 widthED->setValidator(unsignedLengthValidator(widthED));
192         else
193                 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
194
195         heightED->setEnabled(useHeight);
196         heightUnitCO->setEnabled(useHeight);
197         form_->changed();
198 }
199
200 } // namespace frontend
201 } // namespace lyx