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

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

amelioration du ticket #66

  • Property svn:mime-type set to text/cpp
File size: 12.1 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
[583]119
[633]120    QWidget * EPSWidgetGroupBox; // widget containing group button
121    QButtonGroup * EPSButtonGroupBox; // group button
[635]122
123
[633]124#if QT_VERSION < 0x040000
[635]125    colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
126    BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
[633]127    EPSButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
128    EPSButtonGroupBox->insert(colorButton);
129    EPSButtonGroupBox->insert(BWButton);
130    EPSButtonGroupBox->setExclusive(true);
131    EPSWidgetGroupBox = EPSButtonGroupBox;
[583]132
[633]133#else
134    EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
135    QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
[635]136
137    colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
138    BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
139
[633]140    EPSButtonGroupBox = new QButtonGroup();
141    EPSButtonGroupBox->addButton(colorButton);
142    EPSButtonGroupBox->addButton(BWButton);
143    EPSButtonGroupBox->setExclusive(true);
[583]144
[593]145    EPSGroupBoxLayout->addWidget(colorButton);   
146    EPSGroupBoxLayout->addWidget(BWButton);   
[633]147    EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
148
[599]149#endif
[635]150    colorButton->setChecked( true );
[583]151
[633]152    globalVLayout->addWidget(EPSWidgetGroupBox);
153
[581]154  }
155
[638]156  // FIXME : L. Garnier 4/12/07
157  // Not implented. Should deal with alpha channel
[583]158
[638]159//   if(nomFich.endsWith(".tif") ||
160//      nomFich.endsWith(".tiff") ||
161//      nomFich.endsWith(".jpg") ||
162//      nomFich.endsWith(".jpeg") ||
163//      nomFich.endsWith(".png") ||
164//      nomFich.endsWith(".xpm")) {
[583]165
[638]166//     QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
167//     QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
[583]168
[638]169//     boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
170//     boxTransparency->setChecked( false );
[583]171
[638]172//     transparencyGroupBoxLayout->addWidget(boxTransparency);   
173// #if QT_VERSION >= 0x040000
174//     transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
175// #endif
176//     globalVLayout->addWidget(transparencyGroupBox);
[581]177
[638]178//   }
179
[584]180  // size box
[635]181  QWidget* modifyAndRatioWidget = new QWidget();
[584]182
[599]183  QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget);
184
[633]185  QWidget * sizeWidgetGroupBox; // widget containing group button
186  QButtonGroup * sizeButtonGroupBox; // group button
187  QLayout *sizeGroupBoxLayout;
188#if QT_VERSION < 0x040000
189  sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
190
191  original = new QRadioButton("Original",sizeButtonGroupBox);
192  modify = new QRadioButton("Modify",sizeButtonGroupBox);
193
194  sizeButtonGroupBox->insert(original);
195  sizeButtonGroupBox->insert(modify);
196  sizeButtonGroupBox->setExclusive(true);
197  sizeWidgetGroupBox = sizeButtonGroupBox;
198  sizeGroupBoxLayout = sizeWidgetGroupBox->layout();
[584]199
[633]200#else
201 
202  sizeWidgetGroupBox = new QGroupBox(tr("Size"));
203  sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox);
204  sizeButtonGroupBox = new QButtonGroup();
[584]205
[633]206  original = new QRadioButton("Original");
207  modify = new QRadioButton("Modify");
208
209  sizeButtonGroupBox->addButton(modify);
210  sizeButtonGroupBox->addButton(original);
211  sizeButtonGroupBox->setExclusive(true);
212
213  sizeGroupBoxLayout->addWidget(modify);   
214  sizeGroupBoxLayout->addWidget(original);   
215 
216  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
217#endif
[635]218  original->setChecked( true );
[633]219
220
221  ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget);
[584]222  ratioCheckBox->setChecked( true );
223
224  modifyAndRatioLayout->addWidget(modify);
225  modifyAndRatioLayout->addWidget(ratioCheckBox);
[599]226#if QT_VERSION >= 0x040000
[584]227  modifyAndRatioWidget->setLayout(modifyAndRatioLayout);
[599]228#endif
[633]229#if QT_VERSION < 0x040000
230  sizeGroupBoxLayout->add(modifyAndRatioWidget);
231#else
[584]232  sizeGroupBoxLayout->addWidget(modifyAndRatioWidget);
[633]233#endif
[599]234  if (modify->isChecked()) {
235    ratioCheckBox->show();
236  } else {
237    ratioCheckBox->hide();
238  }
[584]239
[633]240#if QT_VERSION < 0x040000
241  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
242#else
243  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
244#endif
[581]245
[584]246  // height
[635]247  heightWidget = new QWidget();
[599]248
249  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
250
[583]251  QString tmp;
252 
[635]253  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
254  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
[583]255  height->setMaxLength(5);
[633]256#if QT_VERSION < 0x040000
257  heightLineLayout->add(height);
258#else
[583]259  heightLineLayout->addWidget(height);
[633]260#endif
[599]261#if QT_VERSION >= 0x040000
[583]262  heightWidget->setLayout(heightLineLayout);
[599]263#endif
[633]264#if QT_VERSION < 0x040000
265  sizeGroupBoxLayout->add(heightWidget);
266#else
[583]267  sizeGroupBoxLayout->addWidget(heightWidget);
[633]268#endif
[584]269  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
[581]270
[584]271
272  // width
[635]273  widthWidget = new QWidget();
[583]274
[633]275  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
276
[599]277#if QT_VERSION < 0x040000
[633]278  widthLineLayout->add(new QLabel("Width ",widthWidget));
[599]279#else
[633]280  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
[599]281#endif
[635]282  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
[583]283  width->setMaxLength(5);
[633]284#if QT_VERSION < 0x040000
285  widthLineLayout->add(width);
286#else
[583]287  widthLineLayout->addWidget(width);
[633]288#endif
[599]289#if QT_VERSION >= 0x040000
[583]290  widthWidget->setLayout(widthLineLayout);
[599]291#endif
[633]292#if QT_VERSION < 0x040000
293  sizeGroupBoxLayout->add(widthWidget);
294#else
[583]295  sizeGroupBoxLayout->addWidget(widthWidget);
[633]296#endif
[584]297  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
[583]298
[599]299#if QT_VERSION >= 0x040000
[633]300  sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
[599]301#endif
[633]302  globalVLayout->addWidget(sizeWidgetGroupBox);
[583]303
[599]304  heightWidget->hide();
305  widthWidget->hide();
[583]306
[584]307  // button ok/cancel box
[583]308
[633]309  QGroupBox *buttonGroupBox = new QGroupBox(this);
[599]310
311  QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox);
[583]312
[633]313  buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox );
[581]314  buttonOk->setAutoDefault( TRUE );
315  buttonOk->setDefault( TRUE );
[583]316  buttonGroupBoxLayout->addWidget(buttonOk);
[581]317
[633]318  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox );
[581]319  buttonCancel->setAutoDefault( TRUE );
[583]320  buttonGroupBoxLayout->addWidget(buttonCancel);
[581]321
[599]322#if QT_VERSION >= 0x040000
[583]323  buttonGroupBox->setLayout(buttonGroupBoxLayout);
[599]324#endif
[583]325  globalVLayout->addWidget(buttonGroupBox);
[581]326
327
[599]328#if QT_VERSION >= 0x040000
[583]329  setLayout(globalVLayout);
[599]330#endif
[583]331
[581]332  // signals and slots connections
333  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
334  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
335}
336
337
338
[582]339int G4OpenGLQtExportDialog::getSliderValue()
340{
[593]341  if (!qualitySlider) return -1;
[582]342  return qualitySlider->value();
343}
344
[585]345int G4OpenGLQtExportDialog::getHeight()
346{
[593]347  if (!height) return -1;
[585]348  return height->text().toInt();
349}
350
351int G4OpenGLQtExportDialog::getWidth()
352{
[593]353  if (!width) return -1;
[585]354  return width->text().toInt();
355}
356
[593]357bool G4OpenGLQtExportDialog::getTransparency()
[586]358{
[593]359  if (!boxTransparency) return -1;
[586]360  return boxTransparency->isChecked();
361}
[585]362
[587]363int G4OpenGLQtExportDialog::getNbColor()
[581]364{
[637]365  if (!colorButton) return -1;
[587]366  // Black and white
[593]367  if (!colorButton->isChecked())
[586]368    return 1;
[587]369  // rgb color
[586]370  return 3;
[583]371}
[581]372
[586]373
[633]374void G4OpenGLQtExportDialog::changeSizeBox()
[586]375{
[637]376  if (!original) return;
377  if (!heightWidget) return;
378  if (!widthWidget) return;
379  if (!ratioCheckBox) return;
380
[586]381  if ( original->isChecked()) {
[599]382    heightWidget->hide();
383    widthWidget->hide();
384    ratioCheckBox->hide();
[586]385  } else {
[599]386    heightWidget->show();
387    widthWidget->show();
388    ratioCheckBox->show();
[586]389  }
390}
391
[584]392void G4OpenGLQtExportDialog::textWidthChanged(
393 const QString & s
394 )
[583]395{
[637]396  if (!ratioCheckBox) return;
397  if (!width) return;
398
[584]399  if (ratioCheckBox->isChecked()){
400    QString tmp;
401    width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
402  }
[581]403}
404
[584]405void G4OpenGLQtExportDialog::  textHeightChanged(
406 const QString & s
407)
408{
[637]409  if (!ratioCheckBox) return;
410  if (!width) return;
411
[584]412  if (ratioCheckBox->isChecked()){
413    QString tmp;
414    width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
415  }
416}
[581]417
418G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
419{
420}
421
422
423#endif
Note: See TracBrowser for help on using the repository browser.