]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QGraphicsDialog.C
Rename insets/insetxxx to insets/InsetXxx, part 1
[lyx.git] / src / frontends / qt4 / QGraphicsDialog.C
1 /**
2  * \file QGraphicsDialog.C
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 "validators.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::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() ) );
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         filename->setText(toqstr(str));
180         form_->changed();
181 }
182
183
184 void QGraphicsDialog::on_getPB_clicked()
185 {
186         form_->getBB();
187 }
188
189
190 void QGraphicsDialog::on_editPB_clicked()
191 {
192         form_->controller().editGraphics();
193 }
194
195
196 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
197 {
198         editPB->setDisabled(filename.isEmpty());
199 }
200
201
202 void QGraphicsDialog::setAutoText() {
203         if (scaleCB->isChecked()) return;
204         if (!Scale->isEnabled() && Scale->text() != "100") 
205                 Scale->setText(QString("auto"));
206
207         setAutoTextCB(WidthCB, Width, widthUnit);
208         setAutoTextCB(HeightCB, Height, heightUnit);
209 }
210
211
212 void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
213 {
214         Scale->setEnabled(setScale);
215         if (setScale) {
216                 Scale->setText("100");
217                 Scale->setFocus(Qt::OtherFocusReason);
218         }
219         
220         WidthCB->setDisabled(setScale);
221         WidthCB->blockSignals(true);
222         WidthCB->setChecked(false);
223         WidthCB->blockSignals(false);
224         Width->setEnabled(false);
225         widthUnit->setEnabled(false);
226         
227         HeightCB->setDisabled(setScale);
228         HeightCB->blockSignals(true);
229         HeightCB->setChecked(false);
230         HeightCB->blockSignals(false);
231         Height->setEnabled(false);
232         heightUnit->setEnabled(false);
233         
234         aspectratio->setDisabled(true);
235         aspectratio->setChecked(true);
236         
237         setAutoText();
238 }
239
240 void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
241 {
242         Width->setEnabled(setWidth);
243         widthUnit->setEnabled(setWidth);
244         if (setWidth)
245                 Width->setFocus(Qt::OtherFocusReason);
246         
247         bool const setHeight = HeightCB->isChecked();
248         aspectratio->setEnabled(setWidth && setHeight);
249         aspectratio->blockSignals(true);
250         aspectratio->setChecked(!(setWidth && setHeight));
251         aspectratio->blockSignals(false);
252         
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
257         
258         setAutoText();
259 }
260
261 void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
262 {
263         Height->setEnabled(setHeight);
264         heightUnit->setEnabled(setHeight);
265         if (setHeight)
266                 Height->setFocus(Qt::OtherFocusReason);
267         
268         bool const setWidth = WidthCB->isChecked();
269         aspectratio->setEnabled(setWidth && setHeight);
270         aspectratio->blockSignals(true);
271         aspectratio->setChecked(!(setWidth && setHeight));
272         aspectratio->blockSignals(false);
273         
274         scaleCB->setEnabled(!setWidth && !setHeight);
275         //already unchecked
276         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() 
277                 && scaleCB->isChecked()); //should be false
278         
279         setAutoText();
280 }
281
282
283 } // namespace frontend
284 } // namespace lyx
285
286 #include "QGraphicsDialog_moc.cpp"