source: trunk/source/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

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