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

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

tickets #101 corrige

  • Property svn:mime-type set to text/cpp
File size: 13.4 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
[639]52,QString format
[583]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);
[642]75  globalVLayout->setMargin(10);
76  globalVLayout->setSpacing(10);
[581]77 
[583]78
[599]79
[638]80  // FIXME : L. Garnier 4/12/07
81  // Not implented. Should deal with alpha channel
[583]82
[639]83//   if((format == "tif") ||
84//      (format == "tiff") ||
85//      (format == "jpg") ||
86//      (format == "jpeg") ||
87//      (format == "png") ||
88//      (format == "xpm")) {
[583]89
[638]90//     QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
91//     QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
[583]92
[638]93//     boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
94//     boxTransparency->setChecked( false );
[583]95
[638]96//     transparencyGroupBoxLayout->addWidget(boxTransparency);   
97// #if QT_VERSION >= 0x040000
98//     transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
99// #endif
100//     globalVLayout->addWidget(transparencyGroupBox);
[581]101
[638]102//   }
103
[656]104  // FIXME : L. Garnier 4/12/07
105  // This is not working for PS and PDF images, it does nothing.
106  // Image is staying in color mode
107  //  if ((format == "ps") || (format == "pdf") || (format == "eps")) {
108
109
[584]110  // size box
111
[640]112  QWidget * sizeWidget = new QWidget(this); // widget containing group button
[641]113  QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
[642]114  sizeWidgetLayout->setMargin (10);
[599]115
[640]116  // original and modify radiobuttons
[633]117#if QT_VERSION < 0x040000
[640]118  QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
[642]119  sizeButtonGroupBox->setInsideMargin (15);
[633]120
121  original = new QRadioButton("Original",sizeButtonGroupBox);
122  modify = new QRadioButton("Modify",sizeButtonGroupBox);
123
124  sizeButtonGroupBox->insert(original);
125  sizeButtonGroupBox->insert(modify);
126  sizeButtonGroupBox->setExclusive(true);
[640]127  sizeWidgetLayout->add(sizeButtonGroupBox);
[584]128
[640]129  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
[633]130#else
131 
[640]132  QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
[641]133  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
[640]134  QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
[642]135  sizeGroupBoxLayout->setMargin (15);
[584]136
[633]137  original = new QRadioButton("Original");
138  modify = new QRadioButton("Modify");
139
[640]140  sizeButtonGroupBox->addButton(original);
[633]141  sizeButtonGroupBox->addButton(modify);
142  sizeButtonGroupBox->setExclusive(true);
143
[640]144  sizeGroupBoxLayout->addWidget(original);   
[633]145  sizeGroupBoxLayout->addWidget(modify);   
[640]146
147  sizeGroupBox->setLayout(sizeGroupBoxLayout);
148  sizeWidgetLayout->addWidget(sizeGroupBox);
[633]149 
[640]150  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
[633]151#endif
[635]152  original->setChecked( true );
[633]153
154
[584]155  // height
[640]156  heightWidget = new QWidget(this);
[599]157
158  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
159
[583]160  QString tmp;
161 
[635]162  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
163  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
[583]164  height->setMaxLength(5);
[633]165#if QT_VERSION < 0x040000
166  heightLineLayout->add(height);
167#else
[583]168  heightLineLayout->addWidget(height);
[633]169#endif
[640]170
[599]171#if QT_VERSION >= 0x040000
[583]172  heightWidget->setLayout(heightLineLayout);
[599]173#endif
[640]174
[633]175#if QT_VERSION < 0x040000
[640]176  sizeWidgetLayout->add(heightWidget);
[633]177#else
[640]178  sizeWidgetLayout->addWidget(heightWidget);
[633]179#endif
[584]180  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
[581]181
[584]182
183  // width
[640]184  widthWidget = new QWidget(this);
[583]185
[633]186  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
187
[599]188#if QT_VERSION < 0x040000
[633]189  widthLineLayout->add(new QLabel("Width ",widthWidget));
[599]190#else
[633]191  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
[599]192#endif
[635]193  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
[583]194  width->setMaxLength(5);
[633]195#if QT_VERSION < 0x040000
196  widthLineLayout->add(width);
197#else
[583]198  widthLineLayout->addWidget(width);
[633]199#endif
[599]200#if QT_VERSION >= 0x040000
[583]201  widthWidget->setLayout(widthLineLayout);
[599]202#endif
[633]203#if QT_VERSION < 0x040000
[640]204  sizeWidgetLayout->add(widthWidget);
[633]205#else
[640]206  sizeWidgetLayout->addWidget(widthWidget);
[633]207#endif
[584]208  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
[583]209
[640]210
211
212  // ratio check box
213
214  ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
215  ratioCheckBox->setChecked( true );
216
217#if QT_VERSION < 0x040000
218  sizeWidgetLayout->add(ratioCheckBox);
219#else
220  sizeWidgetLayout->addWidget(ratioCheckBox);
[599]221#endif
[583]222
[640]223#if QT_VERSION < 0x040000
224  ratioCheckBox->setEnabled ( false );
225  heightWidget->setEnabled ( false );
226  widthWidget->setEnabled ( false );
227#else
228  ratioCheckBox->hide();
[599]229  heightWidget->hide();
230  widthWidget->hide();
[640]231#endif
[583]232
[640]233#if QT_VERSION >= 0x040000
234  sizeWidget->setLayout(sizeWidgetLayout);
235#endif
236  globalVLayout->addWidget(sizeWidget);
237
[656]238 if (format == "eps") {
[640]239
[656]240   QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
[640]241
242
[656]243#if QT_VERSION < 0x040000
[642]244
[656]245    EPSWidgetGroupBox->setInsideMargin (15);
[642]246
[655]247    //    QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
[652]248    //    EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox);
[655]249    //     colorButton = new QRadioButton("Color",EPSColorButtonGroupBox);
250    //     BWButton = new QRadioButton("Grayscale",EPSColorButtonGroupBox);
251    //     EPSColorButtonGroupBox->setInsideMargin (15);
252    //     EPSColorButtonGroupBox->insert(colorButton);
253    //     EPSColorButtonGroupBox->insert(BWButton);
254    //     EPSColorButtonGroupBox->setExclusive(true);
255    //     EPSWidgetGroupBox->add(EPSColorButtonGroupBox);
[651]256
[652]257    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
258
[651]259#else
[656]260    QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
261     EPSGroupBoxLayout->setMargin (15);
[651]262
[655]263//     colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
264//     BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
[651]265
[655]266//     QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
267//     EPSColorButtonGroupBox->addButton(colorButton);
268//     EPSColorButtonGroupBox->addButton(BWButton);
269//     EPSColorButtonGroupBox->setExclusive(true);
[651]270
[655]271//     EPSGroupBoxLayout->addWidget(colorButton);   
272//     EPSGroupBoxLayout->addWidget(BWButton);   
[652]273
274    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
275    EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
276
[651]277    EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
278#endif
[655]279    //    colorButton->setChecked( true );
280    vectorEPSCheckBox->setChecked( true );
[651]281   
282    globalVLayout->addWidget(EPSWidgetGroupBox);
[656]283    connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
[651]284
285  }
286
[656]287  if ((format == "jpg") ||
288      (format == "jpeg")) {
289   
290    QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
291    QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
292    hSliderLayout->setMargin (15);
[651]293
[656]294    qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
295#if QT_VERSION < 0x040000
296    qualitySlider->setMinValue(0);
297    qualitySlider->setMaxValue(100);
298    qualitySlider->setTickmarks(QSlider::Below);
299#else
300    qualitySlider->setMinimum(0);
301    qualitySlider->setMaximum(100);
302    qualitySlider->setTickPosition(QSlider::TicksBelow);
303#endif
304    qualitySlider->setValue(60);
305    hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
306    hSliderLayout->addWidget(qualitySlider);
307    hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
308   
309#if QT_VERSION >= 0x040000
310    imageGroupBox->setLayout(hSliderLayout);
311#endif
312
313#if QT_VERSION >= 0x040000
314    imageGroupBox->setLayout(hSliderLayout);
315#endif
316
317    globalVLayout->addWidget(imageGroupBox);
318  }
319
320
[584]321  // button ok/cancel box
[583]322
[641]323  QWidget *buttonBox = new QWidget(this);
[599]324
[641]325  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
[583]326
[641]327  buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
[581]328  buttonOk->setAutoDefault( TRUE );
329  buttonOk->setDefault( TRUE );
[641]330  buttonBoxLayout->addWidget(buttonOk);
[581]331
[641]332  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
[581]333  buttonCancel->setAutoDefault( TRUE );
[641]334  buttonBoxLayout->addWidget(buttonCancel);
[581]335
[599]336#if QT_VERSION >= 0x040000
[641]337  buttonBox->setLayout(buttonBoxLayout);
[599]338#endif
[641]339  globalVLayout->addWidget(buttonBox);
[581]340
341
[641]342
[599]343#if QT_VERSION >= 0x040000
[583]344  setLayout(globalVLayout);
[599]345#endif
[583]346
[581]347  // signals and slots connections
348  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
349  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
350}
351
352
353
[582]354int G4OpenGLQtExportDialog::getSliderValue()
355{
[593]356  if (!qualitySlider) return -1;
[582]357  return qualitySlider->value();
358}
359
[585]360int G4OpenGLQtExportDialog::getHeight()
361{
[652]362  if (!height) return originalHeight;
[585]363  return height->text().toInt();
364}
365
366int G4OpenGLQtExportDialog::getWidth()
367{
[652]368  if (!width) return originalWidth;
[585]369  return width->text().toInt();
370}
371
[593]372bool G4OpenGLQtExportDialog::getTransparency()
[586]373{
[593]374  if (!boxTransparency) return -1;
[586]375  return boxTransparency->isChecked();
376}
[585]377
[587]378int G4OpenGLQtExportDialog::getNbColor()
[581]379{
[637]380  if (!colorButton) return -1;
[587]381  // Black and white
[593]382  if (!colorButton->isChecked())
[586]383    return 1;
[587]384  // rgb color
[586]385  return 3;
[583]386}
[581]387
[652]388bool G4OpenGLQtExportDialog::getVectorEPS()
389{
390  if (!vectorEPSCheckBox) return 0;
391  return vectorEPSCheckBox->isChecked();
392}
[586]393
[652]394
[656]395void G4OpenGLQtExportDialog::changeVectorEPS()
396{
397  if (!vectorEPSCheckBox) return;
398  if (vectorEPSCheckBox->isChecked()) {
399#if QT_VERSION < 0x040000
400    original->setEnabled ( true );
401    modify->setEnabled ( true );
402#else
403    original->show();
404    modify->show();
405#endif
406    changeSizeBox();
407  } else {
408#if QT_VERSION < 0x040000
409    original->setEnabled ( false );
410    modify->setEnabled ( false );
411    ratioCheckBox->setEnabled ( false );
412    heightWidget->setEnabled ( false );
413    widthWidget->setEnabled ( false );
414#else
415    original->hide();
416    modify->hide();
417    ratioCheckBox->hide();
418    heightWidget->hide();
419    widthWidget->hide();
420#endif
421  }
422}
423
424
[633]425void G4OpenGLQtExportDialog::changeSizeBox()
[586]426{
[637]427  if (!original) return;
428  if (!heightWidget) return;
429  if (!widthWidget) return;
430  if (!ratioCheckBox) return;
431
[586]432  if ( original->isChecked()) {
[640]433#if QT_VERSION < 0x040000
434    ratioCheckBox->setEnabled ( false );
435    heightWidget->setEnabled ( false );
436    widthWidget->setEnabled ( false );
437#else
438    ratioCheckBox->hide();
[599]439    heightWidget->hide();
440    widthWidget->hide();
[640]441#endif
[586]442  } else {
[640]443#if QT_VERSION < 0x040000
444    ratioCheckBox->setEnabled ( true );
445    heightWidget->setEnabled ( true );
446    widthWidget->setEnabled ( true );
447#else
[599]448    heightWidget->show();
449    widthWidget->show();
450    ratioCheckBox->show();
[640]451#endif
[586]452  }
453}
454
[584]455void G4OpenGLQtExportDialog::textWidthChanged(
456 const QString & s
457 )
[583]458{
[637]459  if (!ratioCheckBox) return;
460  if (!width) return;
461
[584]462  if (ratioCheckBox->isChecked()){
463    QString tmp;
[656]464    height->setText(tmp.setNum(s.toInt()*originalHeight/originalWidth));
[584]465  }
[581]466}
467
[584]468void G4OpenGLQtExportDialog::  textHeightChanged(
469 const QString & s
470)
471{
[637]472  if (!ratioCheckBox) return;
473  if (!width) return;
474
[584]475  if (ratioCheckBox->isChecked()){
476    QString tmp;
[656]477    width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
[584]478  }
479}
[581]480
481G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
482{
483}
484
485
486#endif
Note: See TracBrowser for help on using the repository browser.