]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QGraphicsDialog.cpp
* src/frontends/qt4/ui/TextLayoutUi.ui:
[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
81         filename->setValidator(new PathValidator(true, filename));
82         setFocusProxy(filename);
83
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));
91
92         //clipping pane
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()));
113
114         lbX->setValidator(new QDoubleValidator(lbX));
115         lbY->setValidator(new QDoubleValidator(lbY));
116         rtX->setValidator(new QDoubleValidator(rtX));
117         rtY->setValidator(new QDoubleValidator(rtY));
118
119         //extra options pane
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
132         // toggled.
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));
144 }
145
146
147 void QGraphicsDialog::show()
148 {
149         QDialog::show();
150 }
151
152
153 void QGraphicsDialog::change_adaptor()
154 {
155         form_->changed();
156 }
157
158
159 void QGraphicsDialog::change_bb()
160 {
161         form_->controller().bbChanged = true;
162         LYXERR(Debug::GRAPHICS)
163                 << "[controller().bb_Changed set to true]\n";
164         form_->changed();
165 }
166
167
168 void QGraphicsDialog::closeEvent(QCloseEvent * e)
169 {
170         form_->slotWMHide();
171         e->accept();
172 }
173
174
175 void QGraphicsDialog::on_browsePB_clicked()
176 {
177         docstring const str =
178                 form_->controller().browse(qstring_to_ucs4(filename->text()));
179         if(!str.empty()){
180                 filename->setText(toqstr(str));
181                 form_->changed();
182         }
183 }
184
185
186 void QGraphicsDialog::on_getPB_clicked()
187 {
188         form_->getBB();
189 }
190
191
192 void QGraphicsDialog::on_editPB_clicked()
193 {
194         form_->controller().editGraphics();
195 }
196
197
198 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
199 {
200         editPB->setDisabled(filename.isEmpty());
201 }
202
203
204 void QGraphicsDialog::setAutoText() {
205         if (scaleCB->isChecked()) return;
206         if (!Scale->isEnabled() && Scale->text() != "100")
207                 Scale->setText(QString("auto"));
208
209         setAutoTextCB(WidthCB, Width, widthUnit);
210         setAutoTextCB(HeightCB, Height, heightUnit);
211 }
212
213
214 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
215 {
216         Scale->setEnabled(setScale);
217         if (setScale) {
218                 Scale->setText("100");
219                 Scale->setFocus(Qt::OtherFocusReason);
220         }
221
222         WidthCB->setDisabled(setScale);
223         WidthCB->blockSignals(true);
224         WidthCB->setChecked(false);
225         WidthCB->blockSignals(false);
226         Width->setEnabled(false);
227         widthUnit->setEnabled(false);
228
229         HeightCB->setDisabled(setScale);
230         HeightCB->blockSignals(true);
231         HeightCB->setChecked(false);
232         HeightCB->blockSignals(false);
233         Height->setEnabled(false);
234         heightUnit->setEnabled(false);
235
236         aspectratio->setDisabled(true);
237         aspectratio->setChecked(true);
238
239         setAutoText();
240 }
241
242 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
243 {
244         Width->setEnabled(setWidth);
245         widthUnit->setEnabled(setWidth);
246         if (setWidth)
247                 Width->setFocus(Qt::OtherFocusReason);
248
249         bool const setHeight = HeightCB->isChecked();
250         aspectratio->setEnabled(setWidth && setHeight);
251         aspectratio->blockSignals(true);
252         aspectratio->setChecked(!(setWidth && setHeight));
253         aspectratio->blockSignals(false);
254
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
259
260         setAutoText();
261 }
262
263 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
264 {
265         Height->setEnabled(setHeight);
266         heightUnit->setEnabled(setHeight);
267         if (setHeight)
268                 Height->setFocus(Qt::OtherFocusReason);
269
270         bool const setWidth = WidthCB->isChecked();
271         aspectratio->setEnabled(setWidth && setHeight);
272         aspectratio->blockSignals(true);
273         aspectratio->setChecked(!(setWidth && setHeight));
274         aspectratio->blockSignals(false);
275
276         scaleCB->setEnabled(!setWidth && !setHeight);
277         //already unchecked
278         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
279                 && scaleCB->isChecked()); //should be false
280
281         setAutoText();
282 }
283
284
285 } // namespace frontend
286 } // namespace lyx
287
288 #include "QGraphicsDialog_moc.cpp"