]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QExternalDialog.C
fix math fonts with LyX/Mac
[lyx.git] / src / frontends / qt2 / 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/lstrings.h"
22 #include "support/lyxlib.h"
23
24 #include "QExternalDialog.h"
25
26 #include "lengthcombo.h"
27 #include "lengthvalidator.h"
28 #include "qt_helpers.h"
29 #include "QExternal.h"
30
31 #include <qcheckbox.h>
32 #include <qcombobox.h>
33 #include <qpushbutton.h>
34 #include <qfiledialog.h>
35 #include <qtextview.h>
36 #include <qlineedit.h>
37 #include <qvalidator.h>
38
39 using lyx::support::float_equal;
40 using lyx::support::isStrDbl;
41 using lyx::support::strToDbl;
42 using std::string;
43
44 namespace lyx {
45 namespace frontend {
46
47 namespace {
48
49 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
50 {
51         LengthValidator * v = new LengthValidator(ed);
52         v->setBottom(LyXLength());
53         return v;
54 }
55
56 } // namespace anon
57
58
59 QExternalDialog::QExternalDialog(QExternal * form)
60         : QExternalDialogBase(0, 0, false, 0),
61           form_(form)
62 {
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()));
69
70         QIntValidator * validator = new QIntValidator(displayscaleED);
71         validator->setBottom(1);
72         displayscaleED->setValidator(validator);
73
74         angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
75
76         xlED->setValidator(new QIntValidator(xlED));
77         ybED->setValidator(new QIntValidator(ybED));
78         xrED->setValidator(new QIntValidator(xrED));
79         ytED->setValidator(new QIntValidator(ytED));
80
81         // The width is initially set to 'scale' and so should accept
82         // a pure number only.
83         widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
84         heightED->setValidator(unsignedLengthValidator(heightED));
85 }
86
87
88 void QExternalDialog::show()
89 {
90         QExternalDialogBase::show();
91         fileED->setFocus();
92 }
93
94
95
96 bool QExternalDialog::activateAspectratio() const
97 {
98         if (widthUnitCO->currentItem() == 0)
99                 return false;
100
101         string const wstr = fromqstr(widthED->text());
102         if (wstr.empty())
103                 return false;
104         bool const wIsDbl = isStrDbl(wstr);
105         if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
106                 return false;
107         LyXLength l;
108         if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
109                 return false;
110
111         string const hstr = fromqstr(heightED->text());
112         if (hstr.empty())
113                 return false;
114         bool const hIsDbl = isStrDbl(hstr);
115         if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
116                 return false;
117         if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
118                 return false;
119
120         return true;
121 }
122
123
124 void QExternalDialog::bbChanged()
125 {
126         form_->controller().bbChanged(true);
127         form_->changed();
128 }
129
130
131 void QExternalDialog::browseClicked()
132 {
133         int const choice =  externalCO->currentItem();
134         string const template_name =
135                 form_->controller().getTemplate(choice).lyxName;
136         string const str =
137                 form_->controller().browse(fromqstr(fileED->text()),
138                                            template_name);
139         fileED->setText(toqstr(str));
140         form_->changed();
141 }
142
143
144 void QExternalDialog::change_adaptor()
145 {
146         form_->changed();
147 }
148
149
150 void QExternalDialog::closeEvent(QCloseEvent * e)
151 {
152         form_->slotWMHide();
153         e->accept();
154 }
155
156
157 void QExternalDialog::editClicked()
158 {
159         form_->controller().editExternal();
160 }
161
162
163
164 void QExternalDialog::extraChanged(const QString& text)
165 {
166         std::string const format = fromqstr(extraFormatCO->currentText());
167         form_->extra_[format] = text;
168         form_->changed();
169 }
170
171
172 void QExternalDialog::formatChanged(const QString& format)
173 {
174         extraED->setText(form_->extra_[fromqstr(format)]);
175 }
176
177
178 void QExternalDialog::getbbClicked()
179 {
180         form_->getBB();
181 }
182
183
184 void QExternalDialog::sizeChanged()
185 {
186         aspectratioCB->setEnabled(activateAspectratio());
187         form_->changed();
188 }
189
190
191 void QExternalDialog::templateChanged()
192 {
193         form_->updateTemplate();
194         form_->changed();
195 }
196
197
198 void QExternalDialog::widthUnitChanged()
199 {
200         bool useHeight = (widthUnitCO->currentItem() > 0);
201
202         if (useHeight)
203                 widthED->setValidator(unsignedLengthValidator(widthED));
204         else
205                 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
206
207         heightED->setEnabled(useHeight);
208         heightUnitCO->setEnabled(useHeight);
209         form_->changed();
210 }
211
212 } // namespace frontend
213 } // namespace lyx