]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QGraphicsDialog.cpp
delete unneeded Menubar virtual interface.
[lyx.git] / src / frontends / qt4 / QGraphicsDialog.cpp
1 /**
2  * \file QGraphicsDialog.cpp
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 Herbert Voß
8  * \author Abdelrazak Younes
9  * \author Richard Heck
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "QGraphicsDialog.h"
17 #include "QGraphics.h"
18
19 #include "LengthCombo.h"
20 #include "Validator.h"
21 #include "qt_helpers.h"
22
23 #include "debug.h"
24
25 #include "controllers/ControlGraphics.h"
26
27 #include "insets/InsetGraphicsParams.h"
28
29 #include <QCloseEvent>
30 #include <QPushButton>
31 #include <QLineEdit>
32 #include <QValidator>
33
34
35 using std::string;
36
37 namespace lyx {
38 namespace frontend {
39
40
41 QGraphicsDialog::QGraphicsDialog(QGraphics * form)
42         : form_(form)
43 {
44         setupUi(this);
45         //main buttons
46         connect(okPB, SIGNAL(clicked()),
47                 form, SLOT(slotOK()));
48         connect(applyPB, SIGNAL(clicked()),
49                 form, SLOT(slotApply()));
50         connect(closePB, SIGNAL(clicked()),
51                 form, SLOT(slotClose()));
52         connect(restorePB, SIGNAL(clicked()),
53                 form, SLOT(slotRestore()));
54
55         //graphics pane
56         connect(filename, SIGNAL(textChanged(const QString &)),
57                 this, SLOT(change_adaptor()));
58         connect(WidthCB, SIGNAL( clicked()),
59                 this, SLOT(change_adaptor()));
60         connect(HeightCB, SIGNAL( clicked()),
61                 this, SLOT(change_adaptor()));
62         connect(Width, SIGNAL(textChanged(const QString &)),
63                 this, SLOT(change_adaptor()));
64         connect(Height, SIGNAL(textChanged(const QString &)),
65                 this, SLOT(change_adaptor()));
66         connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
67                 this, SLOT(change_adaptor()));
68         connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
69                 this, SLOT(change_adaptor()));
70         connect(aspectratio, SIGNAL(stateChanged(int)),
71                 this, SLOT(change_adaptor()));
72         connect(angle, SIGNAL(textChanged(const QString &)),
73                 this, SLOT(change_adaptor()));
74         connect(origin, SIGNAL(activated(int)),
75                 this, SLOT(change_adaptor()));
76         connect(scaleCB, SIGNAL(clicked()),
77                 this, SLOT(change_adaptor()));
78         connect(Scale, SIGNAL(textChanged(const QString &)),
79                 this, SLOT(change_adaptor()));
80         connect(rotateOrderCB, SIGNAL(clicked()),
81                 this, SLOT(change_adaptor()));
82
83         filename->setValidator(new PathValidator(true, filename));
84         setFocusProxy(filename);
85
86         QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
87         scaleValidator->setBottom(0);
88         scaleValidator->setDecimals(256); //I guess that will do
89         Scale->setValidator(scaleValidator);
90         Height->setValidator(unsignedLengthAutoValidator(Height));
91         Width->setValidator(unsignedLengthAutoValidator(Width));
92         angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
93
94         //clipping pane
95         connect(clip, SIGNAL(stateChanged(int)),
96                 this, SLOT(change_adaptor()));
97         connect(lbY, SIGNAL(textChanged(const QString&)),
98                 this, SLOT(change_bb()));
99         connect(lbYunit, SIGNAL(activated(int)),
100                 this, SLOT(change_bb()));
101         connect(rtY, SIGNAL(textChanged(const QString&)),
102                 this, SLOT(change_bb()));
103         connect(rtYunit, SIGNAL(activated(int)),
104                 this, SLOT(change_bb()));
105         connect(lbX, SIGNAL(textChanged(const QString&)),
106                 this, SLOT(change_bb()));
107         connect(lbXunit, SIGNAL(activated(int)),
108                 this, SLOT(change_bb()));
109         connect(rtX, SIGNAL(textChanged(const QString&)),
110                 this, SLOT(change_bb()));
111         connect(rtXunit, SIGNAL(activated(int)),
112                 this, SLOT(change_bb()));
113         connect(getPB, SIGNAL(clicked()),
114                 this, SLOT(change_adaptor()));
115
116         lbX->setValidator(new QDoubleValidator(lbX));
117         lbY->setValidator(new QDoubleValidator(lbY));
118         rtX->setValidator(new QDoubleValidator(rtX));
119         rtY->setValidator(new QDoubleValidator(rtY));
120
121         //extra options pane
122         connect(latexoptions, SIGNAL(textChanged(const QString&)),
123                 this, SLOT(change_adaptor()));
124         connect(draftCB, SIGNAL(stateChanged(int)),
125                 this, SLOT(change_adaptor()));
126         connect(unzipCB, SIGNAL(stateChanged(int)),
127                 this, SLOT(change_adaptor()));
128         // FIXME: we should connect to clicked() when we move to Qt 4.2 because
129         // the toggled(bool) signal is also trigged when we update the widgets
130         // (rgh-4/07) this isn't as much or a problem as it was, because we're now
131         // using blockSignals() to keep from triggering that signal when we call
132         // setChecked(). Note, too, that clicked() would get called whenever it
133         // is clicked, even right clicked (I think), not just whenever it is
134         // toggled.
135         connect(subfigure, SIGNAL(toggled(bool)),
136                 this, SLOT(change_adaptor()));
137         connect(subcaption, SIGNAL(textChanged(const QString&)),
138                 this, SLOT(change_adaptor()));
139         connect(displayGB, SIGNAL(toggled(bool)),
140                 this, SLOT(change_adaptor()));
141         connect(showCB, SIGNAL(currentIndexChanged(int)),
142                 this, SLOT(change_adaptor()));
143         connect(displayscale, SIGNAL(textChanged(const QString&)),
144                 this, SLOT(change_adaptor()));
145         displayscale->setValidator(new QIntValidator(displayscale));
146 }
147
148
149 void QGraphicsDialog::show()
150 {
151         QDialog::show();
152 }
153
154
155 void QGraphicsDialog::change_adaptor()
156 {
157         form_->changed();
158 }
159
160
161 void QGraphicsDialog::change_bb()
162 {
163         form_->controller().bbChanged = true;
164         LYXERR(Debug::GRAPHICS)
165                 << "[controller().bb_Changed set to true]\n";
166         form_->changed();
167 }
168
169
170 void QGraphicsDialog::closeEvent(QCloseEvent * e)
171 {
172         form_->slotWMHide();
173         e->accept();
174 }
175
176
177 void QGraphicsDialog::on_browsePB_clicked()
178 {
179         docstring const str =
180                 form_->controller().browse(qstring_to_ucs4(filename->text()));
181         if(!str.empty()){
182                 filename->setText(toqstr(str));
183                 form_->changed();
184         }
185 }
186
187
188 void QGraphicsDialog::on_getPB_clicked()
189 {
190         form_->getBB();
191 }
192
193
194 void QGraphicsDialog::on_editPB_clicked()
195 {
196         form_->controller().editGraphics();
197 }
198
199
200 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
201 {
202         editPB->setDisabled(filename.isEmpty());
203 }
204
205
206 void QGraphicsDialog::setAutoText()
207 {
208         if (scaleCB->isChecked()) return;
209         if (!Scale->isEnabled() && Scale->text() != "100")
210                 Scale->setText(QString("auto"));
211
212         setAutoTextCB(WidthCB, Width, widthUnit);
213         setAutoTextCB(HeightCB, Height, heightUnit);
214 }
215
216
217 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
218 {
219         Scale->setEnabled(setScale);
220         if (setScale) {
221                 Scale->setText("100");
222                 Scale->setFocus(Qt::OtherFocusReason);
223         }
224
225         WidthCB->setDisabled(setScale);
226         WidthCB->blockSignals(true);
227         WidthCB->setChecked(false);
228         WidthCB->blockSignals(false);
229         Width->setEnabled(false);
230         widthUnit->setEnabled(false);
231
232         HeightCB->setDisabled(setScale);
233         HeightCB->blockSignals(true);
234         HeightCB->setChecked(false);
235         HeightCB->blockSignals(false);
236         Height->setEnabled(false);
237         heightUnit->setEnabled(false);
238
239         aspectratio->setDisabled(true);
240         aspectratio->setChecked(true);
241
242         rotateOrderCB->setEnabled((WidthCB->isChecked() ||
243                                  HeightCB->isChecked() ||
244                                  scaleCB->isChecked()) &&
245                                  (angle->text() != "0"));
246
247         setAutoText();
248 }
249
250 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
251 {
252         Width->setEnabled(setWidth);
253         widthUnit->setEnabled(setWidth);
254         if (setWidth)
255                 Width->setFocus(Qt::OtherFocusReason);
256
257         bool const setHeight = HeightCB->isChecked();
258         aspectratio->setEnabled(setWidth && setHeight);
259         aspectratio->blockSignals(true);
260         aspectratio->setChecked(!(setWidth && setHeight));
261         aspectratio->blockSignals(false);
262
263         scaleCB->setEnabled(!setWidth && !setHeight);
264         //already will be unchecked, so don't need to do that
265         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
266                         && scaleCB->isChecked()); //should be false, but let's check
267         rotateOrderCB->setEnabled((setWidth || setHeight ||
268                                  scaleCB->isChecked()) &&
269                                  (angle->text() != "0"));
270
271         setAutoText();
272 }
273
274 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
275 {
276         Height->setEnabled(setHeight);
277         heightUnit->setEnabled(setHeight);
278         if (setHeight)
279                 Height->setFocus(Qt::OtherFocusReason);
280
281         bool const setWidth = WidthCB->isChecked();
282         aspectratio->setEnabled(setWidth && setHeight);
283         aspectratio->blockSignals(true);
284         aspectratio->setChecked(!(setWidth && setHeight));
285         aspectratio->blockSignals(false);
286
287         scaleCB->setEnabled(!setWidth && !setHeight);
288         //already unchecked
289         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
290                 && scaleCB->isChecked()); //should be false
291         rotateOrderCB->setEnabled((setWidth || setHeight ||
292                                  scaleCB->isChecked()) &&
293                                  (angle->text() != "0"));
294
295         setAutoText();
296 }
297
298
299 void QGraphicsDialog::on_angle_textChanged(const QString & filename)
300 {
301         rotateOrderCB->setEnabled((WidthCB->isChecked() ||
302                                  HeightCB->isChecked() ||
303                                  scaleCB->isChecked()) &&
304                                  (filename != "0"));
305 }
306
307
308 } // namespace frontend
309 } // namespace lyx
310
311 #include "QGraphicsDialog_moc.cpp"