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

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

deuxieme version de la correction du ticket #99

  • Property svn:mime-type set to text/cpp
File size: 12.1 KB
Line 
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//
27// $Id: G4OpenGLQtExportDialog.cc,v 1.4 2007/11/13 17:48:51 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31
32#define GEANT4_QT_DEBUG
33#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
34
35#include "G4OpenGLQtExportDialog.hh"
36
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>
48#include <qbuttongroup.h>
49
50G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
51 QWidget* parent
52,QString nomFich
53,QString format
54 ,int aHeight
55 ,int aWidth
56)
57 : QDialog( parent )
58{
59#if QT_VERSION < 0x040000
60 setCaption( tr( " Export options" ));
61#else
62 setWindowTitle( tr( " Export options" ));
63#endif
64 originalWidth = aWidth;
65 originalHeight = aHeight;
66
67 // Initializations
68 qualitySlider = NULL;
69 width = NULL;
70 height = NULL;
71 colorButton = NULL;
72 BWButton = NULL;
73
74 // global layout
75 QVBoxLayout* globalVLayout = new QVBoxLayout(this);
76 globalVLayout->setMargin(10);
77 globalVLayout->setSpacing(10);
78
79
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
83 // if ((format == "ps") || (format == "pdf") || (format == "eps")) {
84
85 if (format == "eps") {
86
87 QWidget * EPSWidgetGroupBox; // widget containing group button
88 QButtonGroup * EPSButtonGroupBox; // group button
89
90
91#if QT_VERSION < 0x040000
92
93 colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
94 BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
95 EPSButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
96 EPSButtonGroupBox->setInsideMargin (15);
97 EPSButtonGroupBox->insert(colorButton);
98 EPSButtonGroupBox->insert(BWButton);
99 EPSButtonGroupBox->setExclusive(true);
100 EPSWidgetGroupBox = EPSButtonGroupBox;
101
102#else
103 EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
104 QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
105 EPSGroupBoxLayout->setMargin (15);
106
107 colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
108 BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
109
110 EPSButtonGroupBox = new QButtonGroup();
111 EPSButtonGroupBox->addButton(colorButton);
112 EPSButtonGroupBox->addButton(BWButton);
113 EPSButtonGroupBox->setExclusive(true);
114
115 EPSGroupBoxLayout->addWidget(colorButton);
116 EPSGroupBoxLayout->addWidget(BWButton);
117 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
118
119#endif
120 colorButton->setChecked( true );
121
122 globalVLayout->addWidget(EPSWidgetGroupBox);
123
124 }
125
126 // FIXME : L. Garnier 4/12/07
127 // Not implented. Should deal with alpha channel
128
129// if((format == "tif") ||
130// (format == "tiff") ||
131// (format == "jpg") ||
132// (format == "jpeg") ||
133// (format == "png") ||
134// (format == "xpm")) {
135
136// QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
137// QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
138
139// boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
140// boxTransparency->setChecked( false );
141
142// transparencyGroupBoxLayout->addWidget(boxTransparency);
143// #if QT_VERSION >= 0x040000
144// transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
145// #endif
146// globalVLayout->addWidget(transparencyGroupBox);
147
148// }
149
150 // size box
151
152 QWidget * sizeWidget = new QWidget(this); // widget containing group button
153 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
154 sizeWidgetLayout->setMargin (10);
155
156 // original and modify radiobuttons
157#if QT_VERSION < 0x040000
158 QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
159 sizeButtonGroupBox->setInsideMargin (15);
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);
167 sizeWidgetLayout->add(sizeButtonGroupBox);
168
169 connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
170#else
171
172 QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
173 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
174 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
175 sizeGroupBoxLayout->setMargin (15);
176
177 original = new QRadioButton("Original");
178 modify = new QRadioButton("Modify");
179
180 sizeButtonGroupBox->addButton(original);
181 sizeButtonGroupBox->addButton(modify);
182 sizeButtonGroupBox->setExclusive(true);
183
184 sizeGroupBoxLayout->addWidget(original);
185 sizeGroupBoxLayout->addWidget(modify);
186
187 sizeGroupBox->setLayout(sizeGroupBoxLayout);
188 sizeWidgetLayout->addWidget(sizeGroupBox);
189
190 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
191#endif
192 original->setChecked( true );
193
194
195 // height
196 heightWidget = new QWidget(this);
197
198 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
199
200 QString tmp;
201
202 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
203 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
204 height->setMaxLength(5);
205#if QT_VERSION < 0x040000
206 heightLineLayout->add(height);
207#else
208 heightLineLayout->addWidget(height);
209#endif
210
211#if QT_VERSION >= 0x040000
212 heightWidget->setLayout(heightLineLayout);
213#endif
214
215#if QT_VERSION < 0x040000
216 sizeWidgetLayout->add(heightWidget);
217#else
218 sizeWidgetLayout->addWidget(heightWidget);
219#endif
220 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
221
222
223 // width
224 widthWidget = new QWidget(this);
225
226 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
227
228#if QT_VERSION < 0x040000
229 widthLineLayout->add(new QLabel("Width ",widthWidget));
230#else
231 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
232#endif
233 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
234 width->setMaxLength(5);
235#if QT_VERSION < 0x040000
236 widthLineLayout->add(width);
237#else
238 widthLineLayout->addWidget(width);
239#endif
240#if QT_VERSION >= 0x040000
241 widthWidget->setLayout(widthLineLayout);
242#endif
243#if QT_VERSION < 0x040000
244 sizeWidgetLayout->add(widthWidget);
245#else
246 sizeWidgetLayout->addWidget(widthWidget);
247#endif
248 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
249
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);
261#endif
262
263#if QT_VERSION < 0x040000
264 ratioCheckBox->setEnabled ( false );
265 heightWidget->setEnabled ( false );
266 widthWidget->setEnabled ( false );
267#else
268 ratioCheckBox->hide();
269 heightWidget->hide();
270 widthWidget->hide();
271#endif
272
273#if QT_VERSION >= 0x040000
274 sizeWidget->setLayout(sizeWidgetLayout);
275#endif
276 globalVLayout->addWidget(sizeWidget);
277
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);
284
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
303
304#if QT_VERSION >= 0x040000
305 imageGroupBox->setLayout(hSliderLayout);
306#endif
307
308 globalVLayout->addWidget(imageGroupBox);
309 }
310
311
312
313
314 // button ok/cancel box
315
316 QWidget *buttonBox = new QWidget(this);
317
318 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
319
320 buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
321 buttonOk->setAutoDefault( TRUE );
322 buttonOk->setDefault( TRUE );
323 buttonBoxLayout->addWidget(buttonOk);
324
325 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
326 buttonCancel->setAutoDefault( TRUE );
327 buttonBoxLayout->addWidget(buttonCancel);
328
329#if QT_VERSION >= 0x040000
330 buttonBox->setLayout(buttonBoxLayout);
331#endif
332 globalVLayout->addWidget(buttonBox);
333
334
335
336#if QT_VERSION >= 0x040000
337 setLayout(globalVLayout);
338#endif
339
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
347int G4OpenGLQtExportDialog::getSliderValue()
348{
349 if (!qualitySlider) return -1;
350 return qualitySlider->value();
351}
352
353int G4OpenGLQtExportDialog::getHeight()
354{
355 if (!height) return -1;
356 return height->text().toInt();
357}
358
359int G4OpenGLQtExportDialog::getWidth()
360{
361 if (!width) return -1;
362 return width->text().toInt();
363}
364
365bool G4OpenGLQtExportDialog::getTransparency()
366{
367 if (!boxTransparency) return -1;
368 return boxTransparency->isChecked();
369}
370
371int G4OpenGLQtExportDialog::getNbColor()
372{
373 if (!colorButton) return -1;
374 // Black and white
375 if (!colorButton->isChecked())
376 return 1;
377 // rgb color
378 return 3;
379}
380
381
382void G4OpenGLQtExportDialog::changeSizeBox()
383{
384 if (!original) return;
385 if (!heightWidget) return;
386 if (!widthWidget) return;
387 if (!ratioCheckBox) return;
388
389 if ( original->isChecked()) {
390#if QT_VERSION < 0x040000
391 ratioCheckBox->setEnabled ( false );
392 heightWidget->setEnabled ( false );
393 widthWidget->setEnabled ( false );
394#else
395 ratioCheckBox->hide();
396 heightWidget->hide();
397 widthWidget->hide();
398#endif
399 } else {
400#if QT_VERSION < 0x040000
401 ratioCheckBox->setEnabled ( true );
402 heightWidget->setEnabled ( true );
403 widthWidget->setEnabled ( true );
404#else
405 heightWidget->show();
406 widthWidget->show();
407 ratioCheckBox->show();
408#endif
409 }
410}
411
412void G4OpenGLQtExportDialog::textWidthChanged(
413 const QString & s
414 )
415{
416 if (!ratioCheckBox) return;
417 if (!width) return;
418
419 if (ratioCheckBox->isChecked()){
420 QString tmp;
421 width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
422 }
423}
424
425void G4OpenGLQtExportDialog:: textHeightChanged(
426 const QString & s
427)
428{
429 if (!ratioCheckBox) return;
430 if (!width) return;
431
432 if (ratioCheckBox->isChecked()){
433 QString tmp;
434 width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
435 }
436}
437
438G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
439{
440}
441
442
443#endif
Note: See TracBrowser for help on using the repository browser.