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

Last change on this file since 655 was 655, checked in by garnier, 18 years ago

tickets #102 et #103 corriges

  • Property svn:mime-type set to text/cpp
File size: 12.8 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
[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
[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
[584]105 // size box
106
[640]107 QWidget * sizeWidget = new QWidget(this); // widget containing group button
[641]108 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
[642]109 sizeWidgetLayout->setMargin (10);
[599]110
[640]111 // original and modify radiobuttons
[633]112#if QT_VERSION < 0x040000
[640]113 QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
[642]114 sizeButtonGroupBox->setInsideMargin (15);
[633]115
116 original = new QRadioButton("Original",sizeButtonGroupBox);
117 modify = new QRadioButton("Modify",sizeButtonGroupBox);
118
119 sizeButtonGroupBox->insert(original);
120 sizeButtonGroupBox->insert(modify);
121 sizeButtonGroupBox->setExclusive(true);
[640]122 sizeWidgetLayout->add(sizeButtonGroupBox);
[584]123
[640]124 connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
[633]125#else
126
[640]127 QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
[641]128 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
[640]129 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
[642]130 sizeGroupBoxLayout->setMargin (15);
[584]131
[633]132 original = new QRadioButton("Original");
133 modify = new QRadioButton("Modify");
134
[640]135 sizeButtonGroupBox->addButton(original);
[633]136 sizeButtonGroupBox->addButton(modify);
137 sizeButtonGroupBox->setExclusive(true);
138
[640]139 sizeGroupBoxLayout->addWidget(original);
[633]140 sizeGroupBoxLayout->addWidget(modify);
[640]141
142 sizeGroupBox->setLayout(sizeGroupBoxLayout);
143 sizeWidgetLayout->addWidget(sizeGroupBox);
[633]144
[640]145 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
[633]146#endif
[635]147 original->setChecked( true );
[633]148
149
[584]150 // height
[640]151 heightWidget = new QWidget(this);
[599]152
153 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
154
[583]155 QString tmp;
156
[635]157 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
158 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
[583]159 height->setMaxLength(5);
[633]160#if QT_VERSION < 0x040000
161 heightLineLayout->add(height);
162#else
[583]163 heightLineLayout->addWidget(height);
[633]164#endif
[640]165
[599]166#if QT_VERSION >= 0x040000
[583]167 heightWidget->setLayout(heightLineLayout);
[599]168#endif
[640]169
[633]170#if QT_VERSION < 0x040000
[640]171 sizeWidgetLayout->add(heightWidget);
[633]172#else
[640]173 sizeWidgetLayout->addWidget(heightWidget);
[633]174#endif
[584]175 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
[581]176
[584]177
178 // width
[640]179 widthWidget = new QWidget(this);
[583]180
[633]181 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
182
[599]183#if QT_VERSION < 0x040000
[633]184 widthLineLayout->add(new QLabel("Width ",widthWidget));
[599]185#else
[633]186 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
[599]187#endif
[635]188 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
[583]189 width->setMaxLength(5);
[633]190#if QT_VERSION < 0x040000
191 widthLineLayout->add(width);
192#else
[583]193 widthLineLayout->addWidget(width);
[633]194#endif
[599]195#if QT_VERSION >= 0x040000
[583]196 widthWidget->setLayout(widthLineLayout);
[599]197#endif
[633]198#if QT_VERSION < 0x040000
[640]199 sizeWidgetLayout->add(widthWidget);
[633]200#else
[640]201 sizeWidgetLayout->addWidget(widthWidget);
[633]202#endif
[584]203 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
[583]204
[640]205
206
207 // ratio check box
208
209 ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
210 ratioCheckBox->setChecked( true );
211
212#if QT_VERSION < 0x040000
213 sizeWidgetLayout->add(ratioCheckBox);
214#else
215 sizeWidgetLayout->addWidget(ratioCheckBox);
[599]216#endif
[583]217
[640]218#if QT_VERSION < 0x040000
219 ratioCheckBox->setEnabled ( false );
220 heightWidget->setEnabled ( false );
221 widthWidget->setEnabled ( false );
222#else
223 ratioCheckBox->hide();
[599]224 heightWidget->hide();
225 widthWidget->hide();
[640]226#endif
[583]227
[640]228#if QT_VERSION >= 0x040000
229 sizeWidget->setLayout(sizeWidgetLayout);
230#endif
231 globalVLayout->addWidget(sizeWidget);
232
[642]233 if ((format == "jpg") ||
234 (format == "jpeg")) {
235
236 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
237 QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
238 hSliderLayout->setMargin (15);
[640]239
[642]240 qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
241#if QT_VERSION < 0x040000
242 qualitySlider->setMinValue(0);
243 qualitySlider->setMaxValue(100);
244 qualitySlider->setTickmarks(QSlider::Below);
245#else
246 qualitySlider->setMinimum(0);
247 qualitySlider->setMaximum(100);
248 qualitySlider->setTickPosition(QSlider::TicksBelow);
249#endif
250 qualitySlider->setValue(60);
251 hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
252 hSliderLayout->addWidget(qualitySlider);
253 hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
254
255#if QT_VERSION >= 0x040000
256 imageGroupBox->setLayout(hSliderLayout);
257#endif
[640]258
[642]259#if QT_VERSION >= 0x040000
260 imageGroupBox->setLayout(hSliderLayout);
261#endif
[640]262
[642]263 globalVLayout->addWidget(imageGroupBox);
264 }
265
266
[651]267 // FIXME : L. Garnier 4/12/07
268 // This is not working for PS and PDF images, it does nothing.
269 // Image is staying in color mode
270 // if ((format == "ps") || (format == "pdf") || (format == "eps")) {
[642]271
[651]272 if (format == "eps") {
[642]273
[651]274 QWidget * EPSWidgetGroupBox; // widget containing group button
275 QVBoxLayout *EPSGroupBoxLayout;
276
277#if QT_VERSION < 0x040000
278
[655]279 // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
[652]280 // EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox);
[655]281 // colorButton = new QRadioButton("Color",EPSColorButtonGroupBox);
282 // BWButton = new QRadioButton("Grayscale",EPSColorButtonGroupBox);
283 // EPSColorButtonGroupBox->setInsideMargin (15);
284 // EPSColorButtonGroupBox->insert(colorButton);
285 // EPSColorButtonGroupBox->insert(BWButton);
286 // EPSColorButtonGroupBox->setExclusive(true);
287 // EPSWidgetGroupBox->add(EPSColorButtonGroupBox);
[651]288
[652]289 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
290 EPSWidgetGroupBox->add(vectorEPSCheckBox);
291
[651]292#else
[655]293 EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
294// EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
295// EPSGroupBoxLayout->setMargin (15);
[651]296
[655]297// colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
298// BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
[651]299
[655]300// QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
301// EPSColorButtonGroupBox->addButton(colorButton);
302// EPSColorButtonGroupBox->addButton(BWButton);
303// EPSColorButtonGroupBox->setExclusive(true);
[651]304
[655]305// EPSGroupBoxLayout->addWidget(colorButton);
306// EPSGroupBoxLayout->addWidget(BWButton);
[652]307
308 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
309 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
310
[651]311 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
312#endif
[655]313 // colorButton->setChecked( true );
314 vectorEPSCheckBox->setChecked( true );
[651]315
316 globalVLayout->addWidget(EPSWidgetGroupBox);
317
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
[633]395void G4OpenGLQtExportDialog::changeSizeBox()
[586]396{
[637]397 if (!original) return;
398 if (!heightWidget) return;
399 if (!widthWidget) return;
400 if (!ratioCheckBox) return;
401
[586]402 if ( original->isChecked()) {
[640]403#if QT_VERSION < 0x040000
404 ratioCheckBox->setEnabled ( false );
405 heightWidget->setEnabled ( false );
406 widthWidget->setEnabled ( false );
407#else
408 ratioCheckBox->hide();
[599]409 heightWidget->hide();
410 widthWidget->hide();
[640]411#endif
[586]412 } else {
[640]413#if QT_VERSION < 0x040000
414 ratioCheckBox->setEnabled ( true );
415 heightWidget->setEnabled ( true );
416 widthWidget->setEnabled ( true );
417#else
[599]418 heightWidget->show();
419 widthWidget->show();
420 ratioCheckBox->show();
[640]421#endif
[586]422 }
423}
424
[584]425void G4OpenGLQtExportDialog::textWidthChanged(
426 const QString & s
427 )
[583]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()*originalHeight/originalHeight));
435 }
[581]436}
437
[584]438void G4OpenGLQtExportDialog:: textHeightChanged(
439 const QString & s
440)
441{
[637]442 if (!ratioCheckBox) return;
443 if (!width) return;
444
[584]445 if (ratioCheckBox->isChecked()){
446 QString tmp;
447 width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
448 }
449}
[581]450
451G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
452{
453}
454
455
456#endif
Note: See TracBrowser for help on using the repository browser.