2 * \file QGraphicsDialog.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
16 #include "QGraphicsDialog.h"
17 #include "QGraphics.h"
19 #include "LengthCombo.h"
20 #include "Validator.h"
21 #include "qt_helpers.h"
25 #include "controllers/ControlGraphics.h"
27 #include "insets/InsetGraphicsParams.h"
29 #include <QCloseEvent>
30 #include <QPushButton>
41 QGraphicsDialog::QGraphicsDialog(QGraphics * form)
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()));
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()));
83 filename->setValidator(new PathValidator(true, filename));
84 setFocusProxy(filename);
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));
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()));
116 lbX->setValidator(new QDoubleValidator(lbX));
117 lbY->setValidator(new QDoubleValidator(lbY));
118 rtX->setValidator(new QDoubleValidator(rtX));
119 rtY->setValidator(new QDoubleValidator(rtY));
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
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));
149 void QGraphicsDialog::show()
155 void QGraphicsDialog::change_adaptor()
161 void QGraphicsDialog::change_bb()
163 form_->controller().bbChanged = true;
164 LYXERR(Debug::GRAPHICS)
165 << "[controller().bb_Changed set to true]\n";
170 void QGraphicsDialog::closeEvent(QCloseEvent * e)
177 void QGraphicsDialog::on_browsePB_clicked()
179 docstring const str =
180 form_->controller().browse(qstring_to_ucs4(filename->text()));
182 filename->setText(toqstr(str));
188 void QGraphicsDialog::on_getPB_clicked()
194 void QGraphicsDialog::on_editPB_clicked()
196 form_->controller().editGraphics();
200 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
202 editPB->setDisabled(filename.isEmpty());
206 void QGraphicsDialog::setAutoText()
208 if (scaleCB->isChecked()) return;
209 if (!Scale->isEnabled() && Scale->text() != "100")
210 Scale->setText(QString("auto"));
212 setAutoTextCB(WidthCB, Width, widthUnit);
213 setAutoTextCB(HeightCB, Height, heightUnit);
217 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
219 Scale->setEnabled(setScale);
221 Scale->setText("100");
222 Scale->setFocus(Qt::OtherFocusReason);
225 WidthCB->setDisabled(setScale);
226 WidthCB->blockSignals(true);
227 WidthCB->setChecked(false);
228 WidthCB->blockSignals(false);
229 Width->setEnabled(false);
230 widthUnit->setEnabled(false);
232 HeightCB->setDisabled(setScale);
233 HeightCB->blockSignals(true);
234 HeightCB->setChecked(false);
235 HeightCB->blockSignals(false);
236 Height->setEnabled(false);
237 heightUnit->setEnabled(false);
239 aspectratio->setDisabled(true);
240 aspectratio->setChecked(true);
242 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
243 HeightCB->isChecked() ||
244 scaleCB->isChecked()) &&
245 (angle->text() != "0"));
250 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
252 Width->setEnabled(setWidth);
253 widthUnit->setEnabled(setWidth);
255 Width->setFocus(Qt::OtherFocusReason);
257 bool const setHeight = HeightCB->isChecked();
258 aspectratio->setEnabled(setWidth && setHeight);
259 aspectratio->blockSignals(true);
260 aspectratio->setChecked(!(setWidth && setHeight));
261 aspectratio->blockSignals(false);
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"));
274 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
276 Height->setEnabled(setHeight);
277 heightUnit->setEnabled(setHeight);
279 Height->setFocus(Qt::OtherFocusReason);
281 bool const setWidth = WidthCB->isChecked();
282 aspectratio->setEnabled(setWidth && setHeight);
283 aspectratio->blockSignals(true);
284 aspectratio->setChecked(!(setWidth && setHeight));
285 aspectratio->blockSignals(false);
287 scaleCB->setEnabled(!setWidth && !setHeight);
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"));
299 void QGraphicsDialog::on_angle_textChanged(const QString & filename)
301 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
302 HeightCB->isChecked() ||
303 scaleCB->isChecked()) &&
308 } // namespace frontend
311 #include "QGraphicsDialog_moc.cpp"