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

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

modif pour les formats d export

  • Property svn:mime-type set to text/cpp
File size: 11.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 ,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(".jepg")) {
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(".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(".png") ||
160     nomFich.endsWith(".xpm")) {
161
162    QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
163    QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
164
165    boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
166    boxTransparency->setChecked( false );
167    //    boxTransparency->setEnabled(false);
168
169    transparencyGroupBoxLayout->addWidget(boxTransparency);   
170#if QT_VERSION >= 0x040000
171    transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
172#endif
173    globalVLayout->addWidget(transparencyGroupBox);
174
175  }
176
177  // size box
178  QWidget* modifyAndRatioWidget = new QWidget();
179
180  QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget);
181
182  QWidget * sizeWidgetGroupBox; // widget containing group button
183  QButtonGroup * sizeButtonGroupBox; // group button
184  QLayout *sizeGroupBoxLayout;
185#if QT_VERSION < 0x040000
186  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  sizeWidgetGroupBox = sizeButtonGroupBox;
195  sizeGroupBoxLayout = sizeWidgetGroupBox->layout();
196
197#else
198 
199  sizeWidgetGroupBox = new QGroupBox(tr("Size"));
200  sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox);
201  sizeButtonGroupBox = new QButtonGroup();
202
203  original = new QRadioButton("Original");
204  modify = new QRadioButton("Modify");
205
206  sizeButtonGroupBox->addButton(modify);
207  sizeButtonGroupBox->addButton(original);
208  sizeButtonGroupBox->setExclusive(true);
209
210  sizeGroupBoxLayout->addWidget(modify);   
211  sizeGroupBoxLayout->addWidget(original);   
212 
213  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
214#endif
215  original->setChecked( true );
216
217
218  ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget);
219  ratioCheckBox->setChecked( true );
220
221  modifyAndRatioLayout->addWidget(modify);
222  modifyAndRatioLayout->addWidget(ratioCheckBox);
223#if QT_VERSION >= 0x040000
224  modifyAndRatioWidget->setLayout(modifyAndRatioLayout);
225#endif
226#if QT_VERSION < 0x040000
227  sizeGroupBoxLayout->add(modifyAndRatioWidget);
228#else
229  sizeGroupBoxLayout->addWidget(modifyAndRatioWidget);
230#endif
231  if (modify->isChecked()) {
232    ratioCheckBox->show();
233  } else {
234    ratioCheckBox->hide();
235  }
236
237#if QT_VERSION < 0x040000
238  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
239#else
240  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
241#endif
242
243  // height
244  heightWidget = new QWidget();
245
246  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
247
248  QString tmp;
249 
250  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
251  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
252  height->setMaxLength(5);
253#if QT_VERSION < 0x040000
254  heightLineLayout->add(height);
255#else
256  heightLineLayout->addWidget(height);
257#endif
258#if QT_VERSION >= 0x040000
259  heightWidget->setLayout(heightLineLayout);
260#endif
261#if QT_VERSION < 0x040000
262  sizeGroupBoxLayout->add(heightWidget);
263#else
264  sizeGroupBoxLayout->addWidget(heightWidget);
265#endif
266  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
267
268
269  // width
270  widthWidget = new QWidget();
271
272  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
273
274#if QT_VERSION < 0x040000
275  widthLineLayout->add(new QLabel("Width ",widthWidget));
276#else
277  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
278#endif
279  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
280  width->setMaxLength(5);
281#if QT_VERSION < 0x040000
282  widthLineLayout->add(width);
283#else
284  widthLineLayout->addWidget(width);
285#endif
286#if QT_VERSION >= 0x040000
287  widthWidget->setLayout(widthLineLayout);
288#endif
289#if QT_VERSION < 0x040000
290  sizeGroupBoxLayout->add(widthWidget);
291#else
292  sizeGroupBoxLayout->addWidget(widthWidget);
293#endif
294  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
295
296#if QT_VERSION >= 0x040000
297  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
298#endif
299  globalVLayout->addWidget(sizeWidgetGroupBox);
300
301  heightWidget->hide();
302  widthWidget->hide();
303
304  // button ok/cancel box
305
306  QGroupBox *buttonGroupBox = new QGroupBox(this);
307
308  QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox);
309
310  buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox );
311  buttonOk->setAutoDefault( TRUE );
312  buttonOk->setDefault( TRUE );
313  buttonGroupBoxLayout->addWidget(buttonOk);
314
315  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox );
316  buttonCancel->setAutoDefault( TRUE );
317  buttonGroupBoxLayout->addWidget(buttonCancel);
318
319#if QT_VERSION >= 0x040000
320  buttonGroupBox->setLayout(buttonGroupBoxLayout);
321#endif
322  globalVLayout->addWidget(buttonGroupBox);
323
324
325#if QT_VERSION >= 0x040000
326  setLayout(globalVLayout);
327#endif
328
329  // signals and slots connections
330  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
331  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
332}
333
334
335
336int G4OpenGLQtExportDialog::getSliderValue()
337{
338  if (!qualitySlider) return -1;
339  return qualitySlider->value();
340}
341
342int G4OpenGLQtExportDialog::getHeight()
343{
344  if (!height) return -1;
345  return height->text().toInt();
346}
347
348int G4OpenGLQtExportDialog::getWidth()
349{
350  if (!width) return -1;
351  return width->text().toInt();
352}
353
354bool G4OpenGLQtExportDialog::getTransparency()
355{
356  if (!boxTransparency) return -1;
357  return boxTransparency->isChecked();
358}
359
360int G4OpenGLQtExportDialog::getNbColor()
361{
362  // Black and white
363  if (!colorButton->isChecked())
364    return 1;
365  // rgb color
366  return 3;
367}
368
369
370void G4OpenGLQtExportDialog::changeSizeBox()
371{
372  if ( original->isChecked()) {
373    heightWidget->hide();
374    widthWidget->hide();
375    ratioCheckBox->hide();
376  } else {
377    heightWidget->show();
378    widthWidget->show();
379    ratioCheckBox->show();
380  }
381}
382
383void G4OpenGLQtExportDialog::textWidthChanged(
384 const QString & s
385 )
386{
387  if (ratioCheckBox->isChecked()){
388    QString tmp;
389    width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
390  }
391}
392
393void G4OpenGLQtExportDialog::  textHeightChanged(
394 const QString & s
395)
396{
397  if (ratioCheckBox->isChecked()){
398    QString tmp;
399    width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
400  }
401}
402
403G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
404{
405}
406
407
408#endif
Note: See TracBrowser for help on using the repository browser.