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

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

correction du ticket #66 : export size ok. Qaulite ok, reste EPS et espaces sur les bords

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