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