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

Last change on this file since 754 was 754, checked in by garnier, 16 years ago

corrections pour Qt3 mises sous cvs

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