2 * \file QGraphicsDialog.C
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 "validators.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::LyXLength::UNIT) ),
67 this, SLOT( change_adaptor() ) );
68 connect(widthUnit, SIGNAL( selectionChanged(lyx::LyXLength::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()));
179 filename->setText(toqstr(str));
184 void QGraphicsDialog::on_getPB_clicked()
190 void QGraphicsDialog::on_editPB_clicked()
192 form_->controller().editGraphics();
196 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
198 editPB->setDisabled(filename.isEmpty());
202 void QGraphicsDialog::setAutoText() {
203 if (scaleCB->isChecked()) return;
204 if (!Scale->isEnabled() && Scale->text() != "100")
205 Scale->setText(QString("auto"));
207 setAutoTextCB(WidthCB, Width, widthUnit);
208 setAutoTextCB(HeightCB, Height, heightUnit);
212 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
214 Scale->setEnabled(setScale);
216 Scale->setText("100");
217 Scale->setFocus(Qt::OtherFocusReason);
220 WidthCB->setDisabled(setScale);
221 WidthCB->blockSignals(true);
222 WidthCB->setChecked(false);
223 WidthCB->blockSignals(false);
224 Width->setEnabled(false);
225 widthUnit->setEnabled(false);
227 HeightCB->setDisabled(setScale);
228 HeightCB->blockSignals(true);
229 HeightCB->setChecked(false);
230 HeightCB->blockSignals(false);
231 Height->setEnabled(false);
232 heightUnit->setEnabled(false);
234 aspectratio->setDisabled(true);
235 aspectratio->setChecked(true);
240 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
242 Width->setEnabled(setWidth);
243 widthUnit->setEnabled(setWidth);
245 Width->setFocus(Qt::OtherFocusReason);
247 bool const setHeight = HeightCB->isChecked();
248 aspectratio->setEnabled(setWidth && setHeight);
249 aspectratio->blockSignals(true);
250 aspectratio->setChecked(!(setWidth && setHeight));
251 aspectratio->blockSignals(false);
253 scaleCB->setEnabled(!setWidth && !setHeight);
254 //already will be unchecked, so don't need to do that
255 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
256 && scaleCB->isChecked()); //should be false, but let's check
261 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
263 Height->setEnabled(setHeight);
264 heightUnit->setEnabled(setHeight);
266 Height->setFocus(Qt::OtherFocusReason);
268 bool const setWidth = WidthCB->isChecked();
269 aspectratio->setEnabled(setWidth && setHeight);
270 aspectratio->blockSignals(true);
271 aspectratio->setChecked(!(setWidth && setHeight));
272 aspectratio->blockSignals(false);
274 scaleCB->setEnabled(!setWidth && !setHeight);
276 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
277 && scaleCB->isChecked()); //should be false
283 } // namespace frontend
286 #include "QGraphicsDialog_moc.cpp"