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

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

amelioration du ticket #66

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