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

Last change on this file since 636 was 636, checked in by garnier, 17 years ago

amelioration du ticket #66

  • Property svn:mime-type set to text/cpp
File size: 11.8 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 ,int aHeight
54 ,int aWidth
55)
56  : QDialog( parent )
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
76 
77  if (nomFich.endsWith(".jpg") ||
78      nomFich.endsWith(".jpeg")) {
79   
80    QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
81    QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout(imageGroupBox);
82    QWidget *sliderBox = new QWidget();
83
84    QHBoxLayout *hSliderLayout = new QHBoxLayout(sliderBox);
85
86    //    qualityLabel =  new QLabel( tr( "Image quality" ) );
87    //    imageGroupBoxLayout->addWidget(qualityLabel);
88    qualitySlider= new QSlider(Qt::Horizontal,sliderBox);
89#if QT_VERSION < 0x040000
90    qualitySlider->setMinValue(0);
91    qualitySlider->setMaxValue(100);
92    qualitySlider->setTickmarks(QSlider::Below);
93#else
94    qualitySlider->setMinimum(0);
95    qualitySlider->setMaximum(100);
96    qualitySlider->setTickPosition(QSlider::TicksBelow);
97#endif
98    qualitySlider->setValue(60);
99    hSliderLayout->addWidget(new QLabel("low",sliderBox));
100    hSliderLayout->addWidget(qualitySlider);
101    hSliderLayout->addWidget(new QLabel("Maximum",sliderBox));
102#if QT_VERSION >= 0x040000
103    sliderBox->setLayout(hSliderLayout);
104#endif
105    imageGroupBoxLayout->addWidget(sliderBox);
106
107#if QT_VERSION >= 0x040000
108    imageGroupBox->setLayout(imageGroupBoxLayout);
109#endif
110    globalVLayout->addWidget(imageGroupBox);
111  }
112 
113  if ((nomFich.endsWith(".ps")) || (nomFich.endsWith(".pdf")) || (nomFich.endsWith(".eps"))) {
114
115    //    transparencyEPS = new QCheckBox( "transparencyEPS" );
116    //    transparencyEPS->setText( "save background" );
117    //    transparencyEPS->setChecked( true );
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    //    EPSGroupBoxLayout->addWidget(transparencyEPS);   
152    globalVLayout->addWidget(EPSWidgetGroupBox);
153
154  }
155
156  if(nomFich.endsWith(".tif") ||
157     nomFich.endsWith(".tiff") ||
158     nomFich.endsWith(".jpg") ||
159     nomFich.endsWith(".jpeg") ||
160     nomFich.endsWith(".png") ||
161     nomFich.endsWith(".xpm")) {
162
163    QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
164    QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
165
166    boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
167    boxTransparency->setChecked( false );
168    //    boxTransparency->setEnabled(false);
169
170    transparencyGroupBoxLayout->addWidget(boxTransparency);   
171#if QT_VERSION >= 0x040000
172    transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
173#endif
174    globalVLayout->addWidget(transparencyGroupBox);
175
176  }
177
178  // size box
179  QWidget* modifyAndRatioWidget = new QWidget();
180
181  QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget);
182
183  QWidget * sizeWidgetGroupBox; // widget containing group button
184  QButtonGroup * sizeButtonGroupBox; // group button
185  QLayout *sizeGroupBoxLayout;
186#if QT_VERSION < 0x040000
187  sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
188
189  original = new QRadioButton("Original",sizeButtonGroupBox);
190  modify = new QRadioButton("Modify",sizeButtonGroupBox);
191
192  sizeButtonGroupBox->insert(original);
193  sizeButtonGroupBox->insert(modify);
194  sizeButtonGroupBox->setExclusive(true);
195  sizeWidgetGroupBox = sizeButtonGroupBox;
196  sizeGroupBoxLayout = sizeWidgetGroupBox->layout();
197
198#else
199 
200  sizeWidgetGroupBox = new QGroupBox(tr("Size"));
201  sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox);
202  sizeButtonGroupBox = new QButtonGroup();
203
204  original = new QRadioButton("Original");
205  modify = new QRadioButton("Modify");
206
207  sizeButtonGroupBox->addButton(modify);
208  sizeButtonGroupBox->addButton(original);
209  sizeButtonGroupBox->setExclusive(true);
210
211  sizeGroupBoxLayout->addWidget(modify);   
212  sizeGroupBoxLayout->addWidget(original);   
213 
214  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
215#endif
216  original->setChecked( true );
217
218
219  ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget);
220  ratioCheckBox->setChecked( true );
221
222  modifyAndRatioLayout->addWidget(modify);
223  modifyAndRatioLayout->addWidget(ratioCheckBox);
224#if QT_VERSION >= 0x040000
225  modifyAndRatioWidget->setLayout(modifyAndRatioLayout);
226#endif
227#if QT_VERSION < 0x040000
228  sizeGroupBoxLayout->add(modifyAndRatioWidget);
229#else
230  sizeGroupBoxLayout->addWidget(modifyAndRatioWidget);
231#endif
232  if (modify->isChecked()) {
233    ratioCheckBox->show();
234  } else {
235    ratioCheckBox->hide();
236  }
237
238#if QT_VERSION < 0x040000
239  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
240#else
241  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
242#endif
243
244  // height
245  heightWidget = new QWidget();
246
247  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
248
249  QString tmp;
250 
251  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
252  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
253  height->setMaxLength(5);
254#if QT_VERSION < 0x040000
255  heightLineLayout->add(height);
256#else
257  heightLineLayout->addWidget(height);
258#endif
259#if QT_VERSION >= 0x040000
260  heightWidget->setLayout(heightLineLayout);
261#endif
262#if QT_VERSION < 0x040000
263  sizeGroupBoxLayout->add(heightWidget);
264#else
265  sizeGroupBoxLayout->addWidget(heightWidget);
266#endif
267  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
268
269
270  // width
271  widthWidget = new QWidget();
272
273  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
274
275#if QT_VERSION < 0x040000
276  widthLineLayout->add(new QLabel("Width ",widthWidget));
277#else
278  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
279#endif
280  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
281  width->setMaxLength(5);
282#if QT_VERSION < 0x040000
283  widthLineLayout->add(width);
284#else
285  widthLineLayout->addWidget(width);
286#endif
287#if QT_VERSION >= 0x040000
288  widthWidget->setLayout(widthLineLayout);
289#endif
290#if QT_VERSION < 0x040000
291  sizeGroupBoxLayout->add(widthWidget);
292#else
293  sizeGroupBoxLayout->addWidget(widthWidget);
294#endif
295  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
296
297#if QT_VERSION >= 0x040000
298  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
299#endif
300  globalVLayout->addWidget(sizeWidgetGroupBox);
301
302  heightWidget->hide();
303  widthWidget->hide();
304
305  // button ok/cancel box
306
307  QGroupBox *buttonGroupBox = new QGroupBox(this);
308
309  QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox);
310
311  buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox );
312  buttonOk->setAutoDefault( TRUE );
313  buttonOk->setDefault( TRUE );
314  buttonGroupBoxLayout->addWidget(buttonOk);
315
316  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox );
317  buttonCancel->setAutoDefault( TRUE );
318  buttonGroupBoxLayout->addWidget(buttonCancel);
319
320#if QT_VERSION >= 0x040000
321  buttonGroupBox->setLayout(buttonGroupBoxLayout);
322#endif
323  globalVLayout->addWidget(buttonGroupBox);
324
325
326#if QT_VERSION >= 0x040000
327  setLayout(globalVLayout);
328#endif
329
330  // signals and slots connections
331  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
332  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
333}
334
335
336
337int G4OpenGLQtExportDialog::getSliderValue()
338{
339  if (!qualitySlider) return -1;
340  return qualitySlider->value();
341}
342
343int G4OpenGLQtExportDialog::getHeight()
344{
345  if (!height) return -1;
346  return height->text().toInt();
347}
348
349int G4OpenGLQtExportDialog::getWidth()
350{
351  if (!width) return -1;
352  return width->text().toInt();
353}
354
355bool G4OpenGLQtExportDialog::getTransparency()
356{
357  if (!boxTransparency) return -1;
358  return boxTransparency->isChecked();
359}
360
361int G4OpenGLQtExportDialog::getNbColor()
362{
363  // Black and white
364  if (!colorButton->isChecked())
365    return 1;
366  // rgb color
367  return 3;
368}
369
370
371void G4OpenGLQtExportDialog::changeSizeBox()
372{
373  if ( original->isChecked()) {
374    heightWidget->hide();
375    widthWidget->hide();
376    ratioCheckBox->hide();
377  } else {
378    heightWidget->show();
379    widthWidget->show();
380    ratioCheckBox->show();
381  }
382}
383
384void G4OpenGLQtExportDialog::textWidthChanged(
385 const QString & s
386 )
387{
388  if (ratioCheckBox->isChecked()){
389    QString tmp;
390    width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
391  }
392}
393
394void G4OpenGLQtExportDialog::  textHeightChanged(
395 const QString & s
396)
397{
398  if (ratioCheckBox->isChecked()){
399    QString tmp;
400    width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
401  }
402}
403
404G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
405{
406}
407
408
409#endif
Note: See TracBrowser for help on using the repository browser.