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.5 2008/01/15 11:05:08 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 format |
---|
53 | ,int aHeight |
---|
54 | ,int aWidth |
---|
55 | ) |
---|
56 | : QDialog( parent ), |
---|
57 | isChangingSize(false) |
---|
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 | globalVLayout->setMargin(10); |
---|
77 | globalVLayout->setSpacing(10); |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | // FIXME : L. Garnier 4/12/07 |
---|
82 | // Not implented. Should deal with alpha channel |
---|
83 | |
---|
84 | // if((format == "tif") || |
---|
85 | // (format == "tiff") || |
---|
86 | // (format == "jpg") || |
---|
87 | // (format == "jpeg") || |
---|
88 | // (format == "png") || |
---|
89 | // (format == "xpm")) { |
---|
90 | |
---|
91 | // QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this); |
---|
92 | // QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox); |
---|
93 | |
---|
94 | // boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox); |
---|
95 | // boxTransparency->setChecked( false ); |
---|
96 | |
---|
97 | // transparencyGroupBoxLayout->addWidget(boxTransparency); |
---|
98 | // #if QT_VERSION >= 0x040000 |
---|
99 | // transparencyGroupBox->setLayout(transparencyGroupBoxLayout); |
---|
100 | // #endif |
---|
101 | // globalVLayout->addWidget(transparencyGroupBox); |
---|
102 | |
---|
103 | // } |
---|
104 | |
---|
105 | // FIXME : L. Garnier 4/12/07 |
---|
106 | // This is not working for PS and PDF images, it does nothing. |
---|
107 | // Image is staying in color mode |
---|
108 | // if ((format == "ps") || (format == "pdf") || (format == "eps")) { |
---|
109 | |
---|
110 | |
---|
111 | // size box |
---|
112 | |
---|
113 | QWidget * sizeWidget = new QWidget(this); // widget containing group button |
---|
114 | QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget); |
---|
115 | sizeWidgetLayout->setMargin (10); |
---|
116 | |
---|
117 | // original and modify radiobuttons |
---|
118 | #if QT_VERSION < 0x040000 |
---|
119 | QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this); |
---|
120 | sizeButtonGroupBox->setInsideMargin (15); |
---|
121 | |
---|
122 | original = new QRadioButton("Original",sizeButtonGroupBox); |
---|
123 | modify = new QRadioButton("Modify",sizeButtonGroupBox); |
---|
124 | |
---|
125 | sizeButtonGroupBox->insert(original); |
---|
126 | sizeButtonGroupBox->insert(modify); |
---|
127 | sizeButtonGroupBox->setExclusive(true); |
---|
128 | sizeWidgetLayout->add(sizeButtonGroupBox); |
---|
129 | |
---|
130 | connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
131 | #else |
---|
132 | |
---|
133 | sizeGroupBox = new QGroupBox(tr("Size")); |
---|
134 | QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox); |
---|
135 | QButtonGroup * sizeButtonGroupBox = new QButtonGroup(); |
---|
136 | sizeGroupBoxLayout->setMargin (15); |
---|
137 | |
---|
138 | original = new QRadioButton("Original"); |
---|
139 | modify = new QRadioButton("Modify"); |
---|
140 | |
---|
141 | sizeButtonGroupBox->addButton(original); |
---|
142 | sizeButtonGroupBox->addButton(modify); |
---|
143 | sizeButtonGroupBox->setExclusive(true); |
---|
144 | |
---|
145 | sizeGroupBoxLayout->addWidget(original); |
---|
146 | sizeGroupBoxLayout->addWidget(modify); |
---|
147 | |
---|
148 | sizeGroupBox->setLayout(sizeGroupBoxLayout); |
---|
149 | sizeWidgetLayout->addWidget(sizeGroupBox); |
---|
150 | |
---|
151 | connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) ); |
---|
152 | #endif |
---|
153 | original->setChecked( true ); |
---|
154 | |
---|
155 | |
---|
156 | // height |
---|
157 | heightWidget = new QWidget(this); |
---|
158 | |
---|
159 | QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget); |
---|
160 | |
---|
161 | QString tmp; |
---|
162 | |
---|
163 | heightLineLayout->addWidget(new QLabel("Height",heightWidget)); |
---|
164 | height = new QLineEdit(tmp.setNum(originalHeight),heightWidget); |
---|
165 | height->setMaxLength(5); |
---|
166 | #if QT_VERSION < 0x040000 |
---|
167 | heightLineLayout->add(height); |
---|
168 | #else |
---|
169 | heightLineLayout->addWidget(height); |
---|
170 | #endif |
---|
171 | |
---|
172 | #if QT_VERSION >= 0x040000 |
---|
173 | heightWidget->setLayout(heightLineLayout); |
---|
174 | #endif |
---|
175 | |
---|
176 | #if QT_VERSION < 0x040000 |
---|
177 | sizeWidgetLayout->add(heightWidget); |
---|
178 | #else |
---|
179 | sizeWidgetLayout->addWidget(heightWidget); |
---|
180 | #endif |
---|
181 | connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) ); |
---|
182 | |
---|
183 | |
---|
184 | // width |
---|
185 | widthWidget = new QWidget(this); |
---|
186 | |
---|
187 | QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget); |
---|
188 | |
---|
189 | #if QT_VERSION < 0x040000 |
---|
190 | widthLineLayout->add(new QLabel("Width ",widthWidget)); |
---|
191 | #else |
---|
192 | widthLineLayout->addWidget(new QLabel("Width ",widthWidget)); |
---|
193 | #endif |
---|
194 | width = new QLineEdit(tmp.setNum(originalWidth),widthWidget); |
---|
195 | width->setMaxLength(5); |
---|
196 | #if QT_VERSION < 0x040000 |
---|
197 | widthLineLayout->add(width); |
---|
198 | #else |
---|
199 | widthLineLayout->addWidget(width); |
---|
200 | #endif |
---|
201 | #if QT_VERSION >= 0x040000 |
---|
202 | widthWidget->setLayout(widthLineLayout); |
---|
203 | #endif |
---|
204 | #if QT_VERSION < 0x040000 |
---|
205 | sizeWidgetLayout->add(widthWidget); |
---|
206 | #else |
---|
207 | sizeWidgetLayout->addWidget(widthWidget); |
---|
208 | #endif |
---|
209 | connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) ); |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | // ratio check box |
---|
214 | |
---|
215 | ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget); |
---|
216 | ratioCheckBox->setChecked( true ); |
---|
217 | |
---|
218 | #if QT_VERSION < 0x040000 |
---|
219 | sizeWidgetLayout->add(ratioCheckBox); |
---|
220 | #else |
---|
221 | sizeWidgetLayout->addWidget(ratioCheckBox); |
---|
222 | #endif |
---|
223 | |
---|
224 | #if QT_VERSION < 0x040000 |
---|
225 | ratioCheckBox->setEnabled ( false ); |
---|
226 | heightWidget->setEnabled ( false ); |
---|
227 | widthWidget->setEnabled ( false ); |
---|
228 | #else |
---|
229 | ratioCheckBox->hide(); |
---|
230 | heightWidget->hide(); |
---|
231 | widthWidget->hide(); |
---|
232 | #endif |
---|
233 | |
---|
234 | #if QT_VERSION >= 0x040000 |
---|
235 | sizeWidget->setLayout(sizeWidgetLayout); |
---|
236 | #endif |
---|
237 | globalVLayout->addWidget(sizeWidget); |
---|
238 | |
---|
239 | if (format == "eps") { |
---|
240 | |
---|
241 | QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button |
---|
242 | |
---|
243 | |
---|
244 | #if QT_VERSION < 0x040000 |
---|
245 | |
---|
246 | EPSWidgetGroupBox->setInsideMargin (15); |
---|
247 | |
---|
248 | // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this); |
---|
249 | // EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox); |
---|
250 | // colorButton = new QRadioButton("Color",EPSColorButtonGroupBox); |
---|
251 | // BWButton = new QRadioButton("Grayscale",EPSColorButtonGroupBox); |
---|
252 | // EPSColorButtonGroupBox->setInsideMargin (15); |
---|
253 | // EPSColorButtonGroupBox->insert(colorButton); |
---|
254 | // EPSColorButtonGroupBox->insert(BWButton); |
---|
255 | // EPSColorButtonGroupBox->setExclusive(true); |
---|
256 | // EPSWidgetGroupBox->add(EPSColorButtonGroupBox); |
---|
257 | |
---|
258 | vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox); |
---|
259 | |
---|
260 | #else |
---|
261 | QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox); |
---|
262 | EPSGroupBoxLayout->setMargin (15); |
---|
263 | |
---|
264 | // colorButton = new QRadioButton("Color",EPSWidgetGroupBox); |
---|
265 | // BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox); |
---|
266 | |
---|
267 | // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup(); |
---|
268 | // EPSColorButtonGroupBox->addButton(colorButton); |
---|
269 | // EPSColorButtonGroupBox->addButton(BWButton); |
---|
270 | // EPSColorButtonGroupBox->setExclusive(true); |
---|
271 | |
---|
272 | // EPSGroupBoxLayout->addWidget(colorButton); |
---|
273 | // EPSGroupBoxLayout->addWidget(BWButton); |
---|
274 | |
---|
275 | vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox); |
---|
276 | EPSGroupBoxLayout->addWidget(vectorEPSCheckBox); |
---|
277 | |
---|
278 | EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout); |
---|
279 | #endif |
---|
280 | // colorButton->setChecked( true ); |
---|
281 | vectorEPSCheckBox->setChecked( true ); |
---|
282 | |
---|
283 | globalVLayout->addWidget(EPSWidgetGroupBox); |
---|
284 | connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) ); |
---|
285 | |
---|
286 | } |
---|
287 | |
---|
288 | if ((format == "jpg") || |
---|
289 | (format == "jpeg")) { |
---|
290 | |
---|
291 | QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this); |
---|
292 | QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox); |
---|
293 | hSliderLayout->setMargin (15); |
---|
294 | |
---|
295 | qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox); |
---|
296 | #if QT_VERSION < 0x040000 |
---|
297 | qualitySlider->setMinValue(0); |
---|
298 | qualitySlider->setMaxValue(100); |
---|
299 | qualitySlider->setTickmarks(QSlider::Below); |
---|
300 | #else |
---|
301 | qualitySlider->setMinimum(0); |
---|
302 | qualitySlider->setMaximum(100); |
---|
303 | qualitySlider->setTickPosition(QSlider::TicksBelow); |
---|
304 | #endif |
---|
305 | qualitySlider->setValue(60); |
---|
306 | hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox)); |
---|
307 | hSliderLayout->addWidget(qualitySlider); |
---|
308 | hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox)); |
---|
309 | |
---|
310 | #if QT_VERSION >= 0x040000 |
---|
311 | imageGroupBox->setLayout(hSliderLayout); |
---|
312 | #endif |
---|
313 | |
---|
314 | #if QT_VERSION >= 0x040000 |
---|
315 | imageGroupBox->setLayout(hSliderLayout); |
---|
316 | #endif |
---|
317 | |
---|
318 | globalVLayout->addWidget(imageGroupBox); |
---|
319 | } |
---|
320 | |
---|
321 | |
---|
322 | // button ok/cancel box |
---|
323 | |
---|
324 | QWidget *buttonBox = new QWidget(this); |
---|
325 | |
---|
326 | QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox); |
---|
327 | |
---|
328 | buttonOk = new QPushButton( tr( "&OK" ),buttonBox ); |
---|
329 | buttonOk->setAutoDefault( TRUE ); |
---|
330 | buttonOk->setDefault( TRUE ); |
---|
331 | buttonBoxLayout->addWidget(buttonOk); |
---|
332 | |
---|
333 | buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox ); |
---|
334 | buttonCancel->setAutoDefault( TRUE ); |
---|
335 | buttonBoxLayout->addWidget(buttonCancel); |
---|
336 | |
---|
337 | #if QT_VERSION >= 0x040000 |
---|
338 | buttonBox->setLayout(buttonBoxLayout); |
---|
339 | #endif |
---|
340 | globalVLayout->addWidget(buttonBox); |
---|
341 | |
---|
342 | |
---|
343 | |
---|
344 | #if QT_VERSION >= 0x040000 |
---|
345 | setLayout(globalVLayout); |
---|
346 | #endif |
---|
347 | |
---|
348 | // signals and slots connections |
---|
349 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
---|
350 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
351 | } |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | int G4OpenGLQtExportDialog::getSliderValue() |
---|
356 | { |
---|
357 | if (!qualitySlider) return -1; |
---|
358 | return qualitySlider->value(); |
---|
359 | } |
---|
360 | |
---|
361 | int G4OpenGLQtExportDialog::getHeight() |
---|
362 | { |
---|
363 | if (!height) return originalHeight; |
---|
364 | return height->text().toInt(); |
---|
365 | } |
---|
366 | |
---|
367 | int G4OpenGLQtExportDialog::getWidth() |
---|
368 | { |
---|
369 | if (!width) return originalWidth; |
---|
370 | return width->text().toInt(); |
---|
371 | } |
---|
372 | |
---|
373 | bool G4OpenGLQtExportDialog::getTransparency() |
---|
374 | { |
---|
375 | if (!boxTransparency) return -1; |
---|
376 | return boxTransparency->isChecked(); |
---|
377 | } |
---|
378 | |
---|
379 | int G4OpenGLQtExportDialog::getNbColor() |
---|
380 | { |
---|
381 | if (!colorButton) return -1; |
---|
382 | // Black and white |
---|
383 | if (!colorButton->isChecked()) |
---|
384 | return 1; |
---|
385 | // rgb color |
---|
386 | return 3; |
---|
387 | } |
---|
388 | |
---|
389 | bool G4OpenGLQtExportDialog::getVectorEPS() |
---|
390 | { |
---|
391 | if (!vectorEPSCheckBox) return 0; |
---|
392 | return vectorEPSCheckBox->isChecked(); |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | void G4OpenGLQtExportDialog::changeVectorEPS() |
---|
397 | { |
---|
398 | if (!vectorEPSCheckBox) return; |
---|
399 | if (vectorEPSCheckBox->isChecked()) { |
---|
400 | #if QT_VERSION < 0x040000 |
---|
401 | original->setEnabled ( true ); |
---|
402 | modify->setEnabled ( true ); |
---|
403 | #else |
---|
404 | sizeGroupBox->show(); |
---|
405 | original->show(); |
---|
406 | modify->show(); |
---|
407 | #endif |
---|
408 | changeSizeBox(); |
---|
409 | } else { |
---|
410 | #if QT_VERSION < 0x040000 |
---|
411 | original->setEnabled ( false ); |
---|
412 | modify->setEnabled ( false ); |
---|
413 | ratioCheckBox->setEnabled ( false ); |
---|
414 | heightWidget->setEnabled ( false ); |
---|
415 | widthWidget->setEnabled ( false ); |
---|
416 | #else |
---|
417 | sizeGroupBox->hide(); |
---|
418 | original->hide(); |
---|
419 | modify->hide(); |
---|
420 | ratioCheckBox->hide(); |
---|
421 | heightWidget->hide(); |
---|
422 | widthWidget->hide(); |
---|
423 | #endif |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | |
---|
428 | void G4OpenGLQtExportDialog::changeSizeBox() |
---|
429 | { |
---|
430 | if (!original) return; |
---|
431 | if (!heightWidget) return; |
---|
432 | if (!widthWidget) return; |
---|
433 | if (!ratioCheckBox) return; |
---|
434 | |
---|
435 | if ( original->isChecked()) { |
---|
436 | #if QT_VERSION < 0x040000 |
---|
437 | ratioCheckBox->setEnabled ( false ); |
---|
438 | heightWidget->setEnabled ( false ); |
---|
439 | widthWidget->setEnabled ( false ); |
---|
440 | #else |
---|
441 | ratioCheckBox->hide(); |
---|
442 | heightWidget->hide(); |
---|
443 | widthWidget->hide(); |
---|
444 | #endif |
---|
445 | } else { |
---|
446 | #if QT_VERSION < 0x040000 |
---|
447 | ratioCheckBox->setEnabled ( true ); |
---|
448 | heightWidget->setEnabled ( true ); |
---|
449 | widthWidget->setEnabled ( true ); |
---|
450 | #else |
---|
451 | heightWidget->show(); |
---|
452 | widthWidget->show(); |
---|
453 | ratioCheckBox->show(); |
---|
454 | #endif |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | |
---|
459 | void G4OpenGLQtExportDialog::textWidthChanged( |
---|
460 | const QString & s |
---|
461 | ) |
---|
462 | { |
---|
463 | if (!ratioCheckBox) return; |
---|
464 | if (!width) return; |
---|
465 | if (isChangingSize == true) return; // exclusive slot |
---|
466 | |
---|
467 | if (ratioCheckBox->isChecked()){ |
---|
468 | isChangingSize = true; |
---|
469 | QString tmp; |
---|
470 | height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth)))); |
---|
471 | isChangingSize = false; |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | void G4OpenGLQtExportDialog:: textHeightChanged( |
---|
476 | const QString & s |
---|
477 | ) |
---|
478 | { |
---|
479 | if (!ratioCheckBox) return; |
---|
480 | if (!width) return; |
---|
481 | if (isChangingSize == true) return; // exclusive slot |
---|
482 | |
---|
483 | if (ratioCheckBox->isChecked()){ |
---|
484 | isChangingSize = true; |
---|
485 | QString tmp; |
---|
486 | width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight)); |
---|
487 | isChangingSize = false; |
---|
488 | } |
---|
489 | } |
---|
490 | |
---|
491 | G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog() |
---|
492 | { |
---|
493 | } |
---|
494 | |
---|
495 | |
---|
496 | #endif |
---|