]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QGraphicsDialog.C
Fix unreported bug related to 3246 by Richard Heck:
[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  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "QGraphicsDialog.h"
16 #include "QGraphics.h"
17
18 #include "lengthcombo.h"
19 #include "validators.h"
20 #include "qt_helpers.h"
21
22 #include "debug.h"
23
24 #include "controllers/ControlGraphics.h"
25
26 #include "insets/insetgraphicsParams.h"
27
28 #include <QCloseEvent>
29 #include <QPushButton>
30 #include <QLineEdit>
31 #include <QValidator>
32
33
34 using std::string;
35
36 namespace lyx {
37 namespace frontend {
38
39
40 QGraphicsDialog::QGraphicsDialog(QGraphics * form)
41         : form_(form)
42 {
43         setupUi(this);
44         connect(okPB, SIGNAL( clicked() ),
45                 form, SLOT( slotOK() ) );
46         connect(applyPB, SIGNAL( clicked() ),
47                 form, SLOT( slotApply() ) );
48         connect(closePB, SIGNAL( clicked() ),
49                 form, SLOT( slotClose() ) );
50         connect(restorePB, SIGNAL( clicked() ),
51                 form, SLOT( slotRestore() ) );
52         connect(filename, SIGNAL( textChanged(const QString&) ),
53                 this, SLOT( change_adaptor() ) );
54         connect(subcaption, SIGNAL( textChanged(const QString&) ),
55                 this, SLOT( change_adaptor() ) );
56
57         // FIXME: we should connect to clicked() when we move to Qt 4.2 because
58         // the toggled(bool) signal is also trigged when we update the widgets
59         connect(subfigure, SIGNAL( toggled(bool) ),
60                 this, SLOT( change_adaptor() ) );
61         connect(displayGB, SIGNAL( toggled(bool) ),
62                 this, SLOT( change_adaptor() ) );
63
64         connect(latexoptions, SIGNAL( textChanged(const QString&) ),
65                 this, SLOT( change_adaptor() ) );
66         connect(clip, SIGNAL( stateChanged(int) ),
67                 this, SLOT( change_adaptor() ) );
68         connect(showCB, SIGNAL( currentIndexChanged(int) ),
69                 this, SLOT( change_adaptor() ) );
70         connect(displayscale, SIGNAL( textChanged(const QString&) ),
71                 this, SLOT( change_adaptor() ) );
72         connect(Width, SIGNAL( textChanged(const QString&) ),
73                 this, SLOT( change_adaptor() ) );
74         connect(aspectratio, SIGNAL( stateChanged(int) ),
75                 this, SLOT( change_adaptor() ) );
76         connect(draftCB, SIGNAL( stateChanged(int) ),
77                 this, SLOT( change_adaptor() ) );
78         connect(unzipCB, SIGNAL( stateChanged(int) ),
79                 this, SLOT( change_adaptor() ) );
80         connect(Height, SIGNAL( textChanged(const QString&) ),
81                 this, SLOT( change_adaptor() ) );
82         connect(heightUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
83                 this, SLOT( change_adaptor() ) );
84         connect(widthUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
85                 this, SLOT( change_adaptor() ) );
86         connect(angle, SIGNAL( textChanged(const QString&) ),
87                 this, SLOT( change_adaptor() ) );
88         connect(origin, SIGNAL( activated(int) ),
89                 this, SLOT( change_adaptor() ) );
90         connect(getPB, SIGNAL( clicked() ),
91                 this, SLOT( change_adaptor() ) );
92         connect(scaleCB, SIGNAL( clicked() ),
93                 this, SLOT(change_adaptor()) );
94         connect(Scale, SIGNAL( textChanged(const QString&) ),
95                 this, SLOT( change_adaptor() ) );
96
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
106         connect(lbX, SIGNAL( textChanged(const QString&) ),
107                 this, SLOT( change_bb() ) );
108         connect(lbXunit, SIGNAL( activated(int) ),
109                 this, SLOT( change_bb() ) );
110         connect(rtX, SIGNAL( textChanged(const QString&) ),
111                 this, SLOT( change_bb() ) );
112         connect(rtXunit, SIGNAL( activated(int) ),
113                 this, SLOT( change_bb() ) );
114
115         angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
116
117         lbX->setValidator(new QDoubleValidator(lbX));
118         lbY->setValidator(new QDoubleValidator(lbY));
119         rtX->setValidator(new QDoubleValidator(rtX));
120         rtY->setValidator(new QDoubleValidator(rtY));
121
122         displayscale->setValidator(new QIntValidator(displayscale));
123         Height->setValidator(unsignedLengthValidator(Height));
124         Width->setValidator(unsignedLengthValidator(Width));
125
126         filename->setValidator(new PathValidator(true, filename));
127 }
128
129
130 void QGraphicsDialog::show()
131 {
132         QDialog::show();
133         if (form_->controller().params().filename.empty())
134                 filename->setFocus();
135 }
136
137
138 void QGraphicsDialog::change_adaptor()
139 {
140         form_->changed();
141 }
142
143
144 void QGraphicsDialog::change_bb()
145 {
146         form_->controller().bbChanged = true;
147         lyxerr[Debug::GRAPHICS]
148                 << "[controller().bb_Changed set to true]\n";
149         form_->changed();
150 }
151
152
153 void QGraphicsDialog::closeEvent(QCloseEvent * e)
154 {
155         form_->slotWMHide();
156         e->accept();
157 }
158
159
160 void QGraphicsDialog::on_browsePB_clicked()
161 {
162         docstring const str =
163                 form_->controller().browse(qstring_to_ucs4(filename->text()));
164         filename->setText(toqstr(str));
165         form_->changed();
166 }
167
168
169 void QGraphicsDialog::on_getPB_clicked()
170 {
171         form_->getBB();
172 }
173
174
175 void QGraphicsDialog::on_editPB_clicked()
176 {
177         form_->controller().editGraphics();
178 }
179
180
181 void QGraphicsDialog::on_filename_textChanged(const QString & filename)
182 {
183         editPB->setDisabled(filename.isEmpty());
184 }
185
186
187 void QGraphicsDialog::on_scaleCB_toggled(bool setscale)
188 {
189         Scale->setEnabled(setscale);
190         widthL->setDisabled(setscale);
191         Width->setDisabled(setscale);
192         widthUnit->setDisabled(setscale);
193         aspectratio->setDisabled(setscale);
194         bool noheight = setscale || aspectratio->checkState()==Qt::Checked;
195         heightL->setDisabled(noheight);
196         Height->setDisabled(noheight);
197         heightUnit->setDisabled(noheight);
198 }
199
200 } // namespace frontend
201 } // namespace lyx
202
203 #include "QGraphicsDialog_moc.cpp"