source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc@ 652

Last change on this file since 652 was 652, checked in by garnier, 18 years ago

ajout du EPS vectoriel ticket #100

  • Property svn:mime-type set to text/cpp
File size: 12.7 KB
Line 
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
50G4OpenGLQtExportDialog::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 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 // size box
106
107 QWidget * sizeWidget = new QWidget(this); // widget containing group button
108 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
109 sizeWidgetLayout->setMargin (10);
110
111 // original and modify radiobuttons
112#if QT_VERSION < 0x040000
113 QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
114 sizeButtonGroupBox->setInsideMargin (15);
115
116 original = new QRadioButton("Original",sizeButtonGroupBox);
117 modify = new QRadioButton("Modify",sizeButtonGroupBox);
118
119 sizeButtonGroupBox->insert(original);
120 sizeButtonGroupBox->insert(modify);
121 sizeButtonGroupBox->setExclusive(true);
122 sizeWidgetLayout->add(sizeButtonGroupBox);
123
124 connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
125#else
126
127 QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
128 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
129 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
130 sizeGroupBoxLayout->setMargin (15);
131
132 original = new QRadioButton("Original");
133 modify = new QRadioButton("Modify");
134
135 sizeButtonGroupBox->addButton(original);
136 sizeButtonGroupBox->addButton(modify);
137 sizeButtonGroupBox->setExclusive(true);
138
139 sizeGroupBoxLayout->addWidget(original);
140 sizeGroupBoxLayout->addWidget(modify);
141
142 sizeGroupBox->setLayout(sizeGroupBoxLayout);
143 sizeWidgetLayout->addWidget(sizeGroupBox);
144
145 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
146#endif
147 original->setChecked( true );
148
149
150 // height
151 heightWidget = new QWidget(this);
152
153 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
154
155 QString tmp;
156
157 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
158 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
159 height->setMaxLength(5);
160#if QT_VERSION < 0x040000
161 heightLineLayout->add(height);
162#else
163 heightLineLayout->addWidget(height);
164#endif
165
166#if QT_VERSION >= 0x040000
167 heightWidget->setLayout(heightLineLayout);
168#endif
169
170#if QT_VERSION < 0x040000
171 sizeWidgetLayout->add(heightWidget);
172#else
173 sizeWidgetLayout->addWidget(heightWidget);
174#endif
175 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
176
177
178 // width
179 widthWidget = new QWidget(this);
180
181 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
182
183#if QT_VERSION < 0x040000
184 widthLineLayout->add(new QLabel("Width ",widthWidget));
185#else
186 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
187#endif
188 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
189 width->setMaxLength(5);
190#if QT_VERSION < 0x040000
191 widthLineLayout->add(width);
192#else
193 widthLineLayout->addWidget(width);
194#endif
195#if QT_VERSION >= 0x040000
196 widthWidget->setLayout(widthLineLayout);
197#endif
198#if QT_VERSION < 0x040000
199 sizeWidgetLayout->add(widthWidget);
200#else
201 sizeWidgetLayout->addWidget(widthWidget);
202#endif
203 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
204
205
206
207 // ratio check box
208
209 ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
210 ratioCheckBox->setChecked( true );
211
212#if QT_VERSION < 0x040000
213 sizeWidgetLayout->add(ratioCheckBox);
214#else
215 sizeWidgetLayout->addWidget(ratioCheckBox);
216#endif
217
218#if QT_VERSION < 0x040000
219 ratioCheckBox->setEnabled ( false );
220 heightWidget->setEnabled ( false );
221 widthWidget->setEnabled ( false );
222#else
223 ratioCheckBox->hide();
224 heightWidget->hide();
225 widthWidget->hide();
226#endif
227
228#if QT_VERSION >= 0x040000
229 sizeWidget->setLayout(sizeWidgetLayout);
230#endif
231 globalVLayout->addWidget(sizeWidget);
232
233 if ((format == "jpg") ||
234 (format == "jpeg")) {
235
236 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
237 QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
238 hSliderLayout->setMargin (15);
239
240 qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
241#if QT_VERSION < 0x040000
242 qualitySlider->setMinValue(0);
243 qualitySlider->setMaxValue(100);
244 qualitySlider->setTickmarks(QSlider::Below);
245#else
246 qualitySlider->setMinimum(0);
247 qualitySlider->setMaximum(100);
248 qualitySlider->setTickPosition(QSlider::TicksBelow);
249#endif
250 qualitySlider->setValue(60);
251 hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
252 hSliderLayout->addWidget(qualitySlider);
253 hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
254
255#if QT_VERSION >= 0x040000
256 imageGroupBox->setLayout(hSliderLayout);
257#endif
258
259#if QT_VERSION >= 0x040000
260 imageGroupBox->setLayout(hSliderLayout);
261#endif
262
263 globalVLayout->addWidget(imageGroupBox);
264 }
265
266
267 // FIXME : L. Garnier 4/12/07
268 // This is not working for PS and PDF images, it does nothing.
269 // Image is staying in color mode
270 // if ((format == "ps") || (format == "pdf") || (format == "eps")) {
271
272 if (format == "eps") {
273
274 QWidget * EPSWidgetGroupBox; // widget containing group button
275 QVBoxLayout *EPSGroupBoxLayout;
276
277#if QT_VERSION < 0x040000
278
279 QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
280 // EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox);
281 colorButton = new QRadioButton("Color",EPSColorButtonGroupBox);
282 BWButton = new QRadioButton("Grayscale",EPSColorButtonGroupBox);
283 EPSColorButtonGroupBox->setInsideMargin (15);
284 EPSColorButtonGroupBox->insert(colorButton);
285 EPSColorButtonGroupBox->insert(BWButton);
286 EPSColorButtonGroupBox->setExclusive(true);
287 EPSWidgetGroupBox->add(EPSColorButtonGroupBox);
288
289 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
290 vectorEPSCheckBox->setChecked( true );
291 EPSWidgetGroupBox->add(vectorEPSCheckBox);
292
293#else
294 EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
295 EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
296 EPSGroupBoxLayout->setMargin (15);
297
298 colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
299 BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
300
301 QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
302 EPSColorButtonGroupBox->addButton(colorButton);
303 EPSColorButtonGroupBox->addButton(BWButton);
304 EPSColorButtonGroupBox->setExclusive(true);
305
306 EPSGroupBoxLayout->addWidget(colorButton);
307 EPSGroupBoxLayout->addWidget(BWButton);
308
309 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
310 vectorEPSCheckBox->setChecked( true );
311 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
312
313 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
314#endif
315 colorButton->setChecked( true );
316
317 globalVLayout->addWidget(EPSWidgetGroupBox);
318
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
355int G4OpenGLQtExportDialog::getSliderValue()
356{
357 if (!qualitySlider) return -1;
358 return qualitySlider->value();
359}
360
361int G4OpenGLQtExportDialog::getHeight()
362{
363 if (!height) return originalHeight;
364 return height->text().toInt();
365}
366
367int G4OpenGLQtExportDialog::getWidth()
368{
369 if (!width) return originalWidth;
370 return width->text().toInt();
371}
372
373bool G4OpenGLQtExportDialog::getTransparency()
374{
375 if (!boxTransparency) return -1;
376 return boxTransparency->isChecked();
377}
378
379int 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
389bool G4OpenGLQtExportDialog::getVectorEPS()
390{
391 if (!vectorEPSCheckBox) return 0;
392 return vectorEPSCheckBox->isChecked();
393}
394
395
396void G4OpenGLQtExportDialog::changeSizeBox()
397{
398 if (!original) return;
399 if (!heightWidget) return;
400 if (!widthWidget) return;
401 if (!ratioCheckBox) return;
402
403 if ( original->isChecked()) {
404#if QT_VERSION < 0x040000
405 ratioCheckBox->setEnabled ( false );
406 heightWidget->setEnabled ( false );
407 widthWidget->setEnabled ( false );
408#else
409 ratioCheckBox->hide();
410 heightWidget->hide();
411 widthWidget->hide();
412#endif
413 } else {
414#if QT_VERSION < 0x040000
415 ratioCheckBox->setEnabled ( true );
416 heightWidget->setEnabled ( true );
417 widthWidget->setEnabled ( true );
418#else
419 heightWidget->show();
420 widthWidget->show();
421 ratioCheckBox->show();
422#endif
423 }
424}
425
426void G4OpenGLQtExportDialog::textWidthChanged(
427 const QString & s
428 )
429{
430 if (!ratioCheckBox) return;
431 if (!width) return;
432
433 if (ratioCheckBox->isChecked()){
434 QString tmp;
435 width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
436 }
437}
438
439void G4OpenGLQtExportDialog:: textHeightChanged(
440 const QString & s
441)
442{
443 if (!ratioCheckBox) return;
444 if (!width) return;
445
446 if (ratioCheckBox->isChecked()){
447 QString tmp;
448 width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
449 }
450}
451
452G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
453{
454}
455
456
457#endif
Note: See TracBrowser for help on using the repository browser.