1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4OpenGLQtExportDialog.cc,v 1.4 2007/11/13 17:48:51 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | |
---|
32 | #define GEANT4_QT_DEBUG |
---|
33 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER |
---|
34 | |
---|
35 | #include "G4OpenGLQtExportDialog.hh" |
---|
36 | |
---|
37 | #include <qvariant.h> |
---|
38 | #include <qpushbutton.h> |
---|
39 | #include <qcheckbox.h> |
---|
40 | #include <qlabel.h> |
---|
41 | #include <qcombobox.h> |
---|
42 | #include <qslider.h> |
---|
43 | #include <qlayout.h> |
---|
44 | #include <qgroupbox.h> |
---|
45 | #include <qradiobutton.h> |
---|
46 | #include <qimage.h> |
---|
47 | #include <qlineedit.h> |
---|
48 | #include <qbuttongroup.h> |
---|
49 | |
---|
50 | G4OpenGLQtExportDialog::G4OpenGLQtExportDialog( |
---|
51 | QWidget* parent |
---|
52 | ,QString nomFich |
---|
53 | ,QString format |
---|
54 | ,int aHeight |
---|
55 | ,int aWidth |
---|
56 | ) |
---|
57 | : QDialog( parent ) |
---|
58 | { |
---|
59 | #if QT_VERSION < 0x040000 |
---|
60 | setCaption( tr( " Export options" )); |
---|
61 | #else |
---|
62 | setWindowTitle( tr( " Export options" )); |
---|
63 | #endif |
---|
64 | originalWidth = aWidth; |
---|
65 | originalHeight = aHeight; |
---|
66 | |
---|
67 | // Initializations |
---|
68 | qualitySlider = NULL; |
---|
69 | width = NULL; |
---|
70 | height = NULL; |
---|
71 | colorButton = NULL; |
---|
72 | BWButton = NULL; |
---|
73 | |
---|
74 | // global layout |
---|
75 | QVBoxLayout* globalVLayout = new QVBoxLayout(this); |
---|
76 | |
---|
77 | |
---|
78 | if ((format == "jpg") || |
---|
79 | (format == "jpeg")) { |
---|
80 | |
---|
81 | QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this); |
---|
82 | QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout(imageGroupBox); |
---|
83 | QWidget *sliderBox = new QWidget(); |
---|
84 | |
---|
85 | QHBoxLayout *hSliderLayout = new QHBoxLayout(sliderBox); |
---|
86 | |
---|
87 | // qualityLabel = new QLabel( tr( "Image quality" ) ); |
---|
88 | // imageGroupBoxLayout->addWidget(qualityLabel); |
---|
89 | qualitySlider= new QSlider(Qt::Horizontal,sliderBox); |
---|
90 | #if QT_VERSION < 0x040000 |
---|
91 | qualitySlider->setMinValue(0); |
---|
92 | qualitySlider->setMaxValue(100); |
---|
93 | qualitySlider->setTickmarks(QSlider::Below); |
---|
94 | #else |
---|
95 | qualitySlider->setMinimum(0); |
---|
96 | qualitySlider->setMaximum(100); |
---|
97 | qualitySlider->setTickPosition(QSlider::TicksBelow); |
---|
98 | #endif |
---|
99 | qualitySlider->setValue(60); |
---|
100 | hSliderLayout->addWidget(new QLabel("low",sliderBox)); |
---|
101 | hSliderLayout->addWidget(qualitySlider); |
---|
102 | hSliderLayout->addWidget(new QLabel("Maximum",sliderBox)); |
---|
103 | #if QT_VERSION >= 0x040000 |
---|
104 | sliderBox->setLayout(hSliderLayout); |
---|
105 | #endif |
---|
106 | imageGroupBoxLayout->addWidget(sliderBox); |
---|
107 | |
---|
108 | #if QT_VERSION >= 0x040000 |
---|
109 | imageGroupBox->setLayout(imageGroupBoxLayout); |
---|
110 | #endif |
---|
111 | globalVLayout->addWidget(imageGroupBox); |
---|
112 | } |
---|
113 | |
---|
114 | // FIXME : L. Garnier 4/12/07 |
---|
115 | // This is not working for PS and PDF images, it does nothing. |
---|
116 | // Image is staying in color mode |
---|
117 | // if ((format == "ps") || (format == "pdf") || (format == "eps")) { |
---|
118 | |
---|
119 | if (format == ".eps") { |
---|
120 | |
---|
121 | QWidget * EPSWidgetGroupBox; // widget containing group button |
---|
122 | QButtonGroup * EPSButtonGroupBox; // group button |
---|
123 | |
---|
124 | |
---|
125 | #if QT_VERSION < 0x040000 |
---|
126 | colorButton = new QRadioButton("Color",EPSWidgetGroupBox); |
---|
127 | BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); |
---|
128 | EPSButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this); |
---|
129 | EPSButtonGroupBox->insert(colorButton); |
---|
130 | EPSButtonGroupBox->insert(BWButton); |
---|
131 | EPSButtonGroupBox->setExclusive(true); |
---|
132 | EPSWidgetGroupBox = EPSButtonGroupBox; |
---|
133 | |
---|
134 | #else |
---|
135 | EPSWidgetGroupBox = new QGroupBox(tr("EPS options")); |
---|
136 | QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox); |
---|
137 | |
---|
138 | colorButton = new QRadioButton("Color",EPSWidgetGroupBox); |
---|
139 | BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); |
---|
140 | |
---|
141 | EPSButtonGroupBox = new QButtonGroup(); |
---|
142 | EPSButtonGroupBox->addButton(colorButton); |
---|
143 | EPSButtonGroupBox->addButton(BWButton); |
---|
144 | EPSButtonGroupBox->setExclusive(true); |
---|
145 | |
---|
146 | EPSGroupBoxLayout->addWidget(colorButton); |
---|
147 | EPSGroupBoxLayout->addWidget(BWButton); |
---|
148 | EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout); |
---|
149 | |
---|
150 | #endif |
---|
151 | colorButton->setChecked( true ); |
---|
152 | |
---|
153 | globalVLayout->addWidget(EPSWidgetGroupBox); |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | // FIXME : L. Garnier 4/12/07 |
---|
158 | // Not implented. Should deal with alpha channel |
---|
159 | |
---|
160 | // if((format == "tif") || |
---|
161 | // (format == "tiff") || |
---|
162 | // (format == "jpg") || |
---|
163 | // (format == "jpeg") || |
---|
164 | // (format == "png") || |
---|
165 | // (format == "xpm")) { |
---|
166 | |
---|
167 | // QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this); |
---|
168 | // QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox); |
---|
169 | |
---|
170 | // boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox); |
---|
171 | // boxTransparency->setChecked( false ); |
---|
172 | |
---|
173 | // transparencyGroupBoxLayout->addWidget(boxTransparency); |
---|
174 | // #if QT_VERSION >= 0x040000 |
---|
175 | // transparencyGroupBox->setLayout(transparencyGroupBoxLayout); |
---|
176 | // #endif |
---|
177 | // globalVLayout->addWidget(transparencyGroupBox); |
---|
178 | |
---|
179 | // } |
---|
180 | |
---|
181 | // size box |
---|
182 | QWidget* modifyAndRatioWidget = new QWidget(); |
---|
183 | |
---|
184 | QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget); |
---|
185 | |
---|
186 | QWidget * sizeWidgetGroupBox; // widget containing group button |
---|
187 | QButtonGroup * sizeButtonGroupBox; // group button |
---|
188 | QLayout *sizeGroupBoxLayout; |
---|
189 | |
---|
190 | #if QT_VERSION < 0x040000 |
---|
191 | sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this); |
---|
192 | |
---|
193 | original = new QRadioButton("Original",sizeButtonGroupBox); |
---|
194 | modify = new QRadioButton("Modify",sizeButtonGroupBox); |
---|
195 | |
---|
196 | sizeButtonGroupBox->insert(original); |
---|
197 | sizeButtonGroupBox->insert(modify); |
---|
198 | sizeButtonGroupBox->setExclusive(true); |
---|
199 | sizeWidgetGroupBox = sizeButtonGroupBox; |
---|
200 | sizeGroupBoxLayout = sizeWidgetGroupBox->layout(); |
---|
201 | |
---|
202 | #else |
---|
203 | |
---|
204 | sizeWidgetGroupBox = new QGroupBox(tr("Size")); |
---|
205 | sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox); |
---|
206 | sizeButtonGroupBox = new QButtonGroup(); |
---|
207 | |
---|
208 | original = new QRadioButton("Original"); |
---|
209 | modify = new QRadioButton("Modify"); |
---|
210 | |
---|
211 | sizeButtonGroupBox->addButton(modify); |
---|
212 | sizeButtonGroupBox->addButton(original); |
---|
213 | sizeButtonGroupBox->setExclusive(true); |
---|
214 | |
---|
215 | sizeGroupBoxLayout->addWidget(modify); |
---|
216 | sizeGroupBoxLayout->addWidget(original); |
---|
217 | |
---|
218 | sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout); |
---|
219 | #endif |
---|
220 | original->setChecked( true ); |
---|
221 | |
---|
222 | |
---|
223 | ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget); |
---|
224 | ratioCheckBox->setChecked( true ); |
---|
225 | |
---|
226 | modifyAndRatioLayout->addWidget(modify); |
---|
227 | modifyAndRatioLayout->addWidget(ratioCheckBox); |
---|
228 | #if QT_VERSION >= 0x040000 |
---|
229 | modifyAndRatioWidget->setLayout(modifyAndRatioLayout); |
---|
230 | #endif |
---|
231 | #if QT_VERSION < 0x040000 |
---|
232 | sizeGroupBoxLayout->add(modifyAndRatioWidget); |
---|
233 | #else |
---|
234 | sizeGroupBoxLayout->addWidget(modifyAndRatioWidget); |
---|
235 | #endif |
---|
236 | if (modify->isChecked()) { |
---|
237 | ratioCheckBox->show(); |
---|
238 | } else { |
---|
239 | ratioCheckBox->hide(); |
---|
240 | } |
---|
241 | |
---|
242 | #if QT_VERSION < 0x040000 |
---|
243 | connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
244 | #else |
---|
245 | connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
246 | #endif |
---|
247 | |
---|
248 | // height |
---|
249 | heightWidget = new QWidget(); |
---|
250 | |
---|
251 | QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget); |
---|
252 | |
---|
253 | QString tmp; |
---|
254 | |
---|
255 | heightLineLayout->addWidget(new QLabel("Height",heightWidget)); |
---|
256 | height = new QLineEdit(tmp.setNum(originalHeight),heightWidget); |
---|
257 | height->setMaxLength(5); |
---|
258 | #if QT_VERSION < 0x040000 |
---|
259 | heightLineLayout->add(height); |
---|
260 | #else |
---|
261 | heightLineLayout->addWidget(height); |
---|
262 | #endif |
---|
263 | #if QT_VERSION >= 0x040000 |
---|
264 | heightWidget->setLayout(heightLineLayout); |
---|
265 | #endif |
---|
266 | #if QT_VERSION < 0x040000 |
---|
267 | sizeGroupBoxLayout->add(heightWidget); |
---|
268 | #else |
---|
269 | sizeGroupBoxLayout->addWidget(heightWidget); |
---|
270 | #endif |
---|
271 | connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) ); |
---|
272 | |
---|
273 | |
---|
274 | // width |
---|
275 | widthWidget = new QWidget(); |
---|
276 | |
---|
277 | QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget); |
---|
278 | |
---|
279 | #if QT_VERSION < 0x040000 |
---|
280 | widthLineLayout->add(new QLabel("Width ",widthWidget)); |
---|
281 | #else |
---|
282 | widthLineLayout->addWidget(new QLabel("Width ",widthWidget)); |
---|
283 | #endif |
---|
284 | width = new QLineEdit(tmp.setNum(originalWidth),widthWidget); |
---|
285 | width->setMaxLength(5); |
---|
286 | #if QT_VERSION < 0x040000 |
---|
287 | widthLineLayout->add(width); |
---|
288 | #else |
---|
289 | widthLineLayout->addWidget(width); |
---|
290 | #endif |
---|
291 | #if QT_VERSION >= 0x040000 |
---|
292 | widthWidget->setLayout(widthLineLayout); |
---|
293 | #endif |
---|
294 | #if QT_VERSION < 0x040000 |
---|
295 | sizeGroupBoxLayout->add(widthWidget); |
---|
296 | #else |
---|
297 | sizeGroupBoxLayout->addWidget(widthWidget); |
---|
298 | #endif |
---|
299 | connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) ); |
---|
300 | |
---|
301 | #if QT_VERSION >= 0x040000 |
---|
302 | sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout); |
---|
303 | #endif |
---|
304 | globalVLayout->addWidget(sizeWidgetGroupBox); |
---|
305 | |
---|
306 | heightWidget->hide(); |
---|
307 | widthWidget->hide(); |
---|
308 | |
---|
309 | // button ok/cancel box |
---|
310 | |
---|
311 | QGroupBox *buttonGroupBox = new QGroupBox(this); |
---|
312 | |
---|
313 | QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox); |
---|
314 | |
---|
315 | buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox ); |
---|
316 | buttonOk->setAutoDefault( TRUE ); |
---|
317 | buttonOk->setDefault( TRUE ); |
---|
318 | buttonGroupBoxLayout->addWidget(buttonOk); |
---|
319 | |
---|
320 | buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox ); |
---|
321 | buttonCancel->setAutoDefault( TRUE ); |
---|
322 | buttonGroupBoxLayout->addWidget(buttonCancel); |
---|
323 | |
---|
324 | #if QT_VERSION >= 0x040000 |
---|
325 | buttonGroupBox->setLayout(buttonGroupBoxLayout); |
---|
326 | #endif |
---|
327 | globalVLayout->addWidget(buttonGroupBox); |
---|
328 | |
---|
329 | |
---|
330 | #if QT_VERSION >= 0x040000 |
---|
331 | setLayout(globalVLayout); |
---|
332 | #endif |
---|
333 | |
---|
334 | // signals and slots connections |
---|
335 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
---|
336 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
337 | } |
---|
338 | |
---|
339 | |
---|
340 | |
---|
341 | int G4OpenGLQtExportDialog::getSliderValue() |
---|
342 | { |
---|
343 | if (!qualitySlider) return -1; |
---|
344 | return qualitySlider->value(); |
---|
345 | } |
---|
346 | |
---|
347 | int G4OpenGLQtExportDialog::getHeight() |
---|
348 | { |
---|
349 | if (!height) return -1; |
---|
350 | return height->text().toInt(); |
---|
351 | } |
---|
352 | |
---|
353 | int G4OpenGLQtExportDialog::getWidth() |
---|
354 | { |
---|
355 | if (!width) return -1; |
---|
356 | return width->text().toInt(); |
---|
357 | } |
---|
358 | |
---|
359 | bool G4OpenGLQtExportDialog::getTransparency() |
---|
360 | { |
---|
361 | if (!boxTransparency) return -1; |
---|
362 | return boxTransparency->isChecked(); |
---|
363 | } |
---|
364 | |
---|
365 | int G4OpenGLQtExportDialog::getNbColor() |
---|
366 | { |
---|
367 | if (!colorButton) return -1; |
---|
368 | // Black and white |
---|
369 | if (!colorButton->isChecked()) |
---|
370 | return 1; |
---|
371 | // rgb color |
---|
372 | return 3; |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | void G4OpenGLQtExportDialog::changeSizeBox() |
---|
377 | { |
---|
378 | if (!original) return; |
---|
379 | if (!heightWidget) return; |
---|
380 | if (!widthWidget) return; |
---|
381 | if (!ratioCheckBox) return; |
---|
382 | |
---|
383 | if ( original->isChecked()) { |
---|
384 | heightWidget->hide(); |
---|
385 | widthWidget->hide(); |
---|
386 | ratioCheckBox->hide(); |
---|
387 | } else { |
---|
388 | heightWidget->show(); |
---|
389 | widthWidget->show(); |
---|
390 | ratioCheckBox->show(); |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | void G4OpenGLQtExportDialog::textWidthChanged( |
---|
395 | const QString & s |
---|
396 | ) |
---|
397 | { |
---|
398 | if (!ratioCheckBox) return; |
---|
399 | if (!width) return; |
---|
400 | |
---|
401 | if (ratioCheckBox->isChecked()){ |
---|
402 | QString tmp; |
---|
403 | width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight)); |
---|
404 | } |
---|
405 | } |
---|
406 | |
---|
407 | void G4OpenGLQtExportDialog:: textHeightChanged( |
---|
408 | const QString & s |
---|
409 | ) |
---|
410 | { |
---|
411 | if (!ratioCheckBox) return; |
---|
412 | if (!width) return; |
---|
413 | |
---|
414 | if (ratioCheckBox->isChecked()){ |
---|
415 | QString tmp; |
---|
416 | width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth)); |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog() |
---|
421 | { |
---|
422 | } |
---|
423 | |
---|
424 | |
---|
425 | #endif |
---|