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

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

ajout du EPS vectoriel ticket #100

  • Property svn:mime-type set to text/cpp
File size: 12.7 KB
RevLine 
[648]1//
[581]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//
[606]27// $Id: G4OpenGLQtExportDialog.cc,v 1.4 2007/11/13 17:48:51 lgarnier Exp $
[593]28// GEANT4 tag $Name:  $
[581]29//
30//
31
[633]32#define GEANT4_QT_DEBUG
[581]33#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
34
35#include "G4OpenGLQtExportDialog.hh"
36
[595]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>
[633]48#include <qbuttongroup.h>
[581]49
50G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
51 QWidget* parent
[583]52,QString nomFich
[639]53,QString format
[583]54 ,int aHeight
55 ,int aWidth
56)
[581]57  : QDialog( parent )
58{
[599]59#if QT_VERSION < 0x040000
60  setCaption( tr( " Export options" ));
61#else
[582]62  setWindowTitle( tr( " Export options" ));
[599]63#endif
[583]64  originalWidth = aWidth;
65  originalHeight = aHeight;
66
[593]67  // Initializations
68  qualitySlider = NULL;
69  width = NULL;
70  height = NULL;
71  colorButton = NULL;
72  BWButton = NULL;
73
[583]74  // global layout
[599]75  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
[642]76  globalVLayout->setMargin(10);
77  globalVLayout->setSpacing(10);
[581]78 
[583]79
[599]80
[638]81  // FIXME : L. Garnier 4/12/07
82  // Not implented. Should deal with alpha channel
[583]83
[639]84//   if((format == "tif") ||
85//      (format == "tiff") ||
86//      (format == "jpg") ||
87//      (format == "jpeg") ||
88//      (format == "png") ||
89//      (format == "xpm")) {
[583]90
[638]91//     QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
92//     QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
[583]93
[638]94//     boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
95//     boxTransparency->setChecked( false );
[583]96
[638]97//     transparencyGroupBoxLayout->addWidget(boxTransparency);   
98// #if QT_VERSION >= 0x040000
99//     transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
100// #endif
101//     globalVLayout->addWidget(transparencyGroupBox);
[581]102
[638]103//   }
104
[584]105  // size box
106
[640]107  QWidget * sizeWidget = new QWidget(this); // widget containing group button
[641]108  QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
[642]109  sizeWidgetLayout->setMargin (10);
[599]110
[640]111  // original and modify radiobuttons
[633]112#if QT_VERSION < 0x040000
[640]113  QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
[642]114  sizeButtonGroupBox->setInsideMargin (15);
[633]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);
[640]122  sizeWidgetLayout->add(sizeButtonGroupBox);
[584]123
[640]124  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
[633]125#else
126 
[640]127  QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
[641]128  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
[640]129  QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
[642]130  sizeGroupBoxLayout->setMargin (15);
[584]131
[633]132  original = new QRadioButton("Original");
133  modify = new QRadioButton("Modify");
134
[640]135  sizeButtonGroupBox->addButton(original);
[633]136  sizeButtonGroupBox->addButton(modify);
137  sizeButtonGroupBox->setExclusive(true);
138
[640]139  sizeGroupBoxLayout->addWidget(original);   
[633]140  sizeGroupBoxLayout->addWidget(modify);   
[640]141
142  sizeGroupBox->setLayout(sizeGroupBoxLayout);
143  sizeWidgetLayout->addWidget(sizeGroupBox);
[633]144 
[640]145  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
[633]146#endif
[635]147  original->setChecked( true );
[633]148
149
[584]150  // height
[640]151  heightWidget = new QWidget(this);
[599]152
153  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
154
[583]155  QString tmp;
156 
[635]157  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
158  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
[583]159  height->setMaxLength(5);
[633]160#if QT_VERSION < 0x040000
161  heightLineLayout->add(height);
162#else
[583]163  heightLineLayout->addWidget(height);
[633]164#endif
[640]165
[599]166#if QT_VERSION >= 0x040000
[583]167  heightWidget->setLayout(heightLineLayout);
[599]168#endif
[640]169
[633]170#if QT_VERSION < 0x040000
[640]171  sizeWidgetLayout->add(heightWidget);
[633]172#else
[640]173  sizeWidgetLayout->addWidget(heightWidget);
[633]174#endif
[584]175  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
[581]176
[584]177
178  // width
[640]179  widthWidget = new QWidget(this);
[583]180
[633]181  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
182
[599]183#if QT_VERSION < 0x040000
[633]184  widthLineLayout->add(new QLabel("Width ",widthWidget));
[599]185#else
[633]186  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
[599]187#endif
[635]188  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
[583]189  width->setMaxLength(5);
[633]190#if QT_VERSION < 0x040000
191  widthLineLayout->add(width);
192#else
[583]193  widthLineLayout->addWidget(width);
[633]194#endif
[599]195#if QT_VERSION >= 0x040000
[583]196  widthWidget->setLayout(widthLineLayout);
[599]197#endif
[633]198#if QT_VERSION < 0x040000
[640]199  sizeWidgetLayout->add(widthWidget);
[633]200#else
[640]201  sizeWidgetLayout->addWidget(widthWidget);
[633]202#endif
[584]203  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
[583]204
[640]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);
[599]216#endif
[583]217
[640]218#if QT_VERSION < 0x040000
219  ratioCheckBox->setEnabled ( false );
220  heightWidget->setEnabled ( false );
221  widthWidget->setEnabled ( false );
222#else
223  ratioCheckBox->hide();
[599]224  heightWidget->hide();
225  widthWidget->hide();
[640]226#endif
[583]227
[640]228#if QT_VERSION >= 0x040000
229  sizeWidget->setLayout(sizeWidgetLayout);
230#endif
231  globalVLayout->addWidget(sizeWidget);
232
[642]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);
[640]239
[642]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
[640]258
[642]259#if QT_VERSION >= 0x040000
260    imageGroupBox->setLayout(hSliderLayout);
261#endif
[640]262
[642]263    globalVLayout->addWidget(imageGroupBox);
264  }
265
266
[651]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")) {
[642]271
[651]272 if (format == "eps") {
[642]273
[651]274    QWidget * EPSWidgetGroupBox; // widget containing group button
275    QVBoxLayout *EPSGroupBoxLayout;
276
277#if QT_VERSION < 0x040000
278
[652]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);
[651]288
[652]289    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
290    vectorEPSCheckBox->setChecked( true );
291    EPSWidgetGroupBox->add(vectorEPSCheckBox);
292
[651]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
[652]301    QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
302    EPSColorButtonGroupBox->addButton(colorButton);
303    EPSColorButtonGroupBox->addButton(BWButton);
304    EPSColorButtonGroupBox->setExclusive(true);
[651]305
306    EPSGroupBoxLayout->addWidget(colorButton);   
307    EPSGroupBoxLayout->addWidget(BWButton);   
[652]308
309    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
310    vectorEPSCheckBox->setChecked( true );
311    EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
312
[651]313    EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
314#endif
315    colorButton->setChecked( true );
316   
317    globalVLayout->addWidget(EPSWidgetGroupBox);
318
319  }
320
321
[584]322  // button ok/cancel box
[583]323
[641]324  QWidget *buttonBox = new QWidget(this);
[599]325
[641]326  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
[583]327
[641]328  buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
[581]329  buttonOk->setAutoDefault( TRUE );
330  buttonOk->setDefault( TRUE );
[641]331  buttonBoxLayout->addWidget(buttonOk);
[581]332
[641]333  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
[581]334  buttonCancel->setAutoDefault( TRUE );
[641]335  buttonBoxLayout->addWidget(buttonCancel);
[581]336
[599]337#if QT_VERSION >= 0x040000
[641]338  buttonBox->setLayout(buttonBoxLayout);
[599]339#endif
[641]340  globalVLayout->addWidget(buttonBox);
[581]341
342
[641]343
[599]344#if QT_VERSION >= 0x040000
[583]345  setLayout(globalVLayout);
[599]346#endif
[583]347
[581]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
[582]355int G4OpenGLQtExportDialog::getSliderValue()
356{
[593]357  if (!qualitySlider) return -1;
[582]358  return qualitySlider->value();
359}
360
[585]361int G4OpenGLQtExportDialog::getHeight()
362{
[652]363  if (!height) return originalHeight;
[585]364  return height->text().toInt();
365}
366
367int G4OpenGLQtExportDialog::getWidth()
368{
[652]369  if (!width) return originalWidth;
[585]370  return width->text().toInt();
371}
372
[593]373bool G4OpenGLQtExportDialog::getTransparency()
[586]374{
[593]375  if (!boxTransparency) return -1;
[586]376  return boxTransparency->isChecked();
377}
[585]378
[587]379int G4OpenGLQtExportDialog::getNbColor()
[581]380{
[637]381  if (!colorButton) return -1;
[587]382  // Black and white
[593]383  if (!colorButton->isChecked())
[586]384    return 1;
[587]385  // rgb color
[586]386  return 3;
[583]387}
[581]388
[652]389bool G4OpenGLQtExportDialog::getVectorEPS()
390{
391  if (!vectorEPSCheckBox) return 0;
392  return vectorEPSCheckBox->isChecked();
393}
[586]394
[652]395
[633]396void G4OpenGLQtExportDialog::changeSizeBox()
[586]397{
[637]398  if (!original) return;
399  if (!heightWidget) return;
400  if (!widthWidget) return;
401  if (!ratioCheckBox) return;
402
[586]403  if ( original->isChecked()) {
[640]404#if QT_VERSION < 0x040000
405    ratioCheckBox->setEnabled ( false );
406    heightWidget->setEnabled ( false );
407    widthWidget->setEnabled ( false );
408#else
409    ratioCheckBox->hide();
[599]410    heightWidget->hide();
411    widthWidget->hide();
[640]412#endif
[586]413  } else {
[640]414#if QT_VERSION < 0x040000
415    ratioCheckBox->setEnabled ( true );
416    heightWidget->setEnabled ( true );
417    widthWidget->setEnabled ( true );
418#else
[599]419    heightWidget->show();
420    widthWidget->show();
421    ratioCheckBox->show();
[640]422#endif
[586]423  }
424}
425
[584]426void G4OpenGLQtExportDialog::textWidthChanged(
427 const QString & s
428 )
[583]429{
[637]430  if (!ratioCheckBox) return;
431  if (!width) return;
432
[584]433  if (ratioCheckBox->isChecked()){
434    QString tmp;
435    width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
436  }
[581]437}
438
[584]439void G4OpenGLQtExportDialog::  textHeightChanged(
440 const QString & s
441)
442{
[637]443  if (!ratioCheckBox) return;
444  if (!width) return;
445
[584]446  if (ratioCheckBox->isChecked()){
447    QString tmp;
448    width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
449  }
450}
[581]451
452G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
453{
454}
455
456
457#endif
Note: See TracBrowser for help on using the repository browser.