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