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

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

debut de correction du ticket #98

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