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()));
81 filename->setValidator(new PathValidator(true, filename));
82 setFocusProxy(filename);
84 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
85 scaleValidator->setBottom(0);
86 scaleValidator->setDecimals(256); //I guess that will do
87 Scale->setValidator(scaleValidator);
88 Height->setValidator(unsignedLengthAutoValidator(Height));
89 Width->setValidator(unsignedLengthAutoValidator(Width));
90 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
93 connect(clip, SIGNAL(stateChanged(int)),
94 this, SLOT(change_adaptor()));
95 connect(lbY, SIGNAL(textChanged(const QString&)),
96 this, SLOT(change_bb()));
97 connect(lbYunit, SIGNAL(activated(int)),
98 this, SLOT(change_bb()));
99 connect(rtY, SIGNAL(textChanged(const QString&)),
100 this, SLOT(change_bb()));
101 connect(rtYunit, SIGNAL(activated(int)),
102 this, SLOT(change_bb()));
103 connect(lbX, SIGNAL(textChanged(const QString&)),
104 this, SLOT(change_bb()));
105 connect(lbXunit, SIGNAL(activated(int)),
106 this, SLOT(change_bb()));
107 connect(rtX, SIGNAL(textChanged(const QString&)),
108 this, SLOT(change_bb()));
109 connect(rtXunit, SIGNAL(activated(int)),
110 this, SLOT(change_bb()));
111 connect(getPB, SIGNAL(clicked()),
112 this, SLOT(change_adaptor()));
114 lbX->setValidator(new QDoubleValidator(lbX));
115 lbY->setValidator(new QDoubleValidator(lbY));
116 rtX->setValidator(new QDoubleValidator(rtX));
117 rtY->setValidator(new QDoubleValidator(rtY));
120 connect(latexoptions, SIGNAL(textChanged(const QString&)),
121 this, SLOT(change_adaptor()));
122 connect(draftCB, SIGNAL(stateChanged(int)),
123 this, SLOT(change_adaptor()));
124 connect(unzipCB, SIGNAL(stateChanged(int)),
125 this, SLOT(change_adaptor()));
126 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
127 // the toggled(bool) signal is also trigged when we update the widgets
128 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
129 // using blockSignals() to keep from triggering that signal when we call
130 // setChecked(). Note, too, that clicked() would get called whenever it
131 // is clicked, even right clicked (I think), not just whenever it is
133 connect(subfigure, SIGNAL(toggled(bool)),
134 this, SLOT(change_adaptor()));
135 connect(subcaption, SIGNAL(textChanged(const QString&)),
136 this, SLOT(change_adaptor()));
137 connect(displayGB, SIGNAL(toggled(bool)),
138 this, SLOT(change_adaptor()));
139 connect(showCB, SIGNAL(currentIndexChanged(int)),
140 this, SLOT(change_adaptor()));
141 connect(displayscale, SIGNAL(textChanged(const QString&)),
142 this, SLOT(change_adaptor()));
143 displayscale->setValidator(new QIntValidator(displayscale));
147 void QGraphicsDialog::show()
153 void QGraphicsDialog::change_adaptor()
159 void QGraphicsDialog::change_bb()
161 form_->controller().bbChanged = true;
162 LYXERR(Debug::GRAPHICS)
163 << "[controller().bb_Changed set to true]\n";
168 void QGraphicsDialog::closeEvent(QCloseEvent * e)
175 void QGraphicsDialog::on_browsePB_clicked()
177 docstring const str =
178 form_->controller().browse(qstring_to_ucs4(filename->text()));
180 filename->setText(toqstr(str));
186 void QGraphicsDialog::on_getPB_clicked()
192 void QGraphicsDialog::on_editPB_clicked()
194 form_->controller().editGraphics();
198 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
200 editPB->setDisabled(filename.isEmpty());
204 void QGraphicsDialog::setAutoText() {
205 if (scaleCB->isChecked()) return;
206 if (!Scale->isEnabled() && Scale->text() != "100")
207 Scale->setText(QString("auto"));
209 setAutoTextCB(WidthCB, Width, widthUnit);
210 setAutoTextCB(HeightCB, Height, heightUnit);
214 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
216 Scale->setEnabled(setScale);
218 Scale->setText("100");
219 Scale->setFocus(Qt::OtherFocusReason);
222 WidthCB->setDisabled(setScale);
223 WidthCB->blockSignals(true);
224 WidthCB->setChecked(false);
225 WidthCB->blockSignals(false);
226 Width->setEnabled(false);
227 widthUnit->setEnabled(false);
229 HeightCB->setDisabled(setScale);
230 HeightCB->blockSignals(true);
231 HeightCB->setChecked(false);
232 HeightCB->blockSignals(false);
233 Height->setEnabled(false);
234 heightUnit->setEnabled(false);
236 aspectratio->setDisabled(true);
237 aspectratio->setChecked(true);
242 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
244 Width->setEnabled(setWidth);
245 widthUnit->setEnabled(setWidth);
247 Width->setFocus(Qt::OtherFocusReason);
249 bool const setHeight = HeightCB->isChecked();
250 aspectratio->setEnabled(setWidth && setHeight);
251 aspectratio->blockSignals(true);
252 aspectratio->setChecked(!(setWidth && setHeight));
253 aspectratio->blockSignals(false);
255 scaleCB->setEnabled(!setWidth && !setHeight);
256 //already will be unchecked, so don't need to do that
257 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
258 && scaleCB->isChecked()); //should be false, but let's check
263 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
265 Height->setEnabled(setHeight);
266 heightUnit->setEnabled(setHeight);
268 Height->setFocus(Qt::OtherFocusReason);
270 bool const setWidth = WidthCB->isChecked();
271 aspectratio->setEnabled(setWidth && setHeight);
272 aspectratio->blockSignals(true);
273 aspectratio->setChecked(!(setWidth && setHeight));
274 aspectratio->blockSignals(false);
276 scaleCB->setEnabled(!setWidth && !setHeight);
278 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
279 && scaleCB->isChecked()); //should be false
285 } // namespace frontend
288 #include "QGraphicsDialog_moc.cpp"