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
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
81 // FIXME : L. Garnier 4/12/07
82 // Not implented. Should deal with alpha channel
83
84// if((format == "tif") ||
85// (format == "tiff") ||
86// (format == "jpg") ||
87// (format == "jpeg") ||
88// (format == "png") ||
89// (format == "xpm")) {
90
91// QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
92// QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
93
94// boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
95// boxTransparency->setChecked( false );
96
97// transparencyGroupBoxLayout->addWidget(boxTransparency);
98// #if QT_VERSION >= 0x040000
99// transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
100// #endif
101// globalVLayout->addWidget(transparencyGroupBox);
102
103// }
104
105 // size box
106
107 QWidget * sizeWidget = new QWidget(this); // widget containing group button
108 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
109 sizeWidgetLayout->setMargin (10);
110
111 // original and modify radiobuttons
112#if QT_VERSION < 0x040000
113 QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
114 sizeButtonGroupBox->setInsideMargin (15);
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);
122 sizeWidgetLayout->add(sizeButtonGroupBox);
123
124 connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
125#else
126
127 QGroupBox * sizeGroupBox = new QGroupBox(tr("Size"));
128 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
129 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
130 sizeGroupBoxLayout->setMargin (15);
131
132 original = new QRadioButton("Original");
133 modify = new QRadioButton("Modify");
134
135 sizeButtonGroupBox->addButton(original);
136 sizeButtonGroupBox->addButton(modify);
137 sizeButtonGroupBox->setExclusive(true);
138
139 sizeGroupBoxLayout->addWidget(original);
140 sizeGroupBoxLayout->addWidget(modify);
141
142 sizeGroupBox->setLayout(sizeGroupBoxLayout);
143 sizeWidgetLayout->addWidget(sizeGroupBox);
144
145 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
146#endif
147 original->setChecked( true );
148
149
150 // height
151 heightWidget = new QWidget(this);
152
153 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
154
155 QString tmp;
156
157 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
158 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
159 height->setMaxLength(5);
160#if QT_VERSION < 0x040000
161 heightLineLayout->add(height);
162#else
163 heightLineLayout->addWidget(height);
164#endif
165
166#if QT_VERSION >= 0x040000
167 heightWidget->setLayout(heightLineLayout);
168#endif
169
170#if QT_VERSION < 0x040000
171 sizeWidgetLayout->add(heightWidget);
172#else
173 sizeWidgetLayout->addWidget(heightWidget);
174#endif
175 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
176
177
178 // width
179 widthWidget = new QWidget(this);
180
181 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
182
183#if QT_VERSION < 0x040000
184 widthLineLayout->add(new QLabel("Width ",widthWidget));
185#else
186 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
187#endif
188 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
189 width->setMaxLength(5);
190#if QT_VERSION < 0x040000
191 widthLineLayout->add(width);
192#else
193 widthLineLayout->addWidget(width);
194#endif
195#if QT_VERSION >= 0x040000
196 widthWidget->setLayout(widthLineLayout);
197#endif
198#if QT_VERSION < 0x040000
199 sizeWidgetLayout->add(widthWidget);
200#else
201 sizeWidgetLayout->addWidget(widthWidget);
202#endif
203 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
204
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);
216#endif
217
218#if QT_VERSION < 0x040000
219 ratioCheckBox->setEnabled ( false );
220 heightWidget->setEnabled ( false );
221 widthWidget->setEnabled ( false );
222#else
223 ratioCheckBox->hide();
224 heightWidget->hide();
225 widthWidget->hide();
226#endif
227
228#if QT_VERSION >= 0x040000
229 sizeWidget->setLayout(sizeWidgetLayout);
230#endif
231 globalVLayout->addWidget(sizeWidget);
232
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);
239
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
258
259#if QT_VERSION >= 0x040000
260 imageGroupBox->setLayout(hSliderLayout);
261#endif
262
263 globalVLayout->addWidget(imageGroupBox);
264 }
265
266
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")) {
271
272 if (format == "eps") {
273
274 QWidget * EPSWidgetGroupBox; // widget containing group button
275 QVBoxLayout *EPSGroupBoxLayout;
276
277#if QT_VERSION < 0x040000
278
279 // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
280 // EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox);
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);
288
289 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
290 EPSWidgetGroupBox->add(vectorEPSCheckBox);
291
292#else
293 EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
294// EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
295// EPSGroupBoxLayout->setMargin (15);
296
297// colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
298// BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
299
300// QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
301// EPSColorButtonGroupBox->addButton(colorButton);
302// EPSColorButtonGroupBox->addButton(BWButton);
303// EPSColorButtonGroupBox->setExclusive(true);
304
305// EPSGroupBoxLayout->addWidget(colorButton);
306// EPSGroupBoxLayout->addWidget(BWButton);
307
308 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
309 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
310
311 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
312#endif
313 // colorButton->setChecked( true );
314 vectorEPSCheckBox->setChecked( true );
315
316 globalVLayout->addWidget(EPSWidgetGroupBox);
317
318 }
319
320
321 // button ok/cancel box
322
323 QWidget *buttonBox = new QWidget(this);
324
325 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
326
327 buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
328 buttonOk->setAutoDefault( TRUE );
329 buttonOk->setDefault( TRUE );
330 buttonBoxLayout->addWidget(buttonOk);
331
332 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
333 buttonCancel->setAutoDefault( TRUE );
334 buttonBoxLayout->addWidget(buttonCancel);
335
336#if QT_VERSION >= 0x040000
337 buttonBox->setLayout(buttonBoxLayout);
338#endif
339 globalVLayout->addWidget(buttonBox);
340
341
342
343#if QT_VERSION >= 0x040000
344 setLayout(globalVLayout);
345#endif
346
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
354int G4OpenGLQtExportDialog::getSliderValue()
355{
356 if (!qualitySlider) return -1;
357 return qualitySlider->value();
358}
359
360int G4OpenGLQtExportDialog::getHeight()
361{
362 if (!height) return originalHeight;
363 return height->text().toInt();
364}
365
366int G4OpenGLQtExportDialog::getWidth()
367{
368 if (!width) return originalWidth;
369 return width->text().toInt();
370}
371
372bool G4OpenGLQtExportDialog::getTransparency()
373{
374 if (!boxTransparency) return -1;
375 return boxTransparency->isChecked();
376}
377
378int G4OpenGLQtExportDialog::getNbColor()
379{
380 if (!colorButton) return -1;
381 // Black and white
382 if (!colorButton->isChecked())
383 return 1;
384 // rgb color
385 return 3;
386}
387
388bool G4OpenGLQtExportDialog::getVectorEPS()
389{
390 if (!vectorEPSCheckBox) return 0;
391 return vectorEPSCheckBox->isChecked();
392}
393
394
395void G4OpenGLQtExportDialog::changeSizeBox()
396{
397 if (!original) return;
398 if (!heightWidget) return;
399 if (!widthWidget) return;
400 if (!ratioCheckBox) return;
401
402 if ( original->isChecked()) {
403#if QT_VERSION < 0x040000
404 ratioCheckBox->setEnabled ( false );
405 heightWidget->setEnabled ( false );
406 widthWidget->setEnabled ( false );
407#else
408 ratioCheckBox->hide();
409 heightWidget->hide();
410 widthWidget->hide();
411#endif
412 } else {
413#if QT_VERSION < 0x040000
414 ratioCheckBox->setEnabled ( true );
415 heightWidget->setEnabled ( true );
416 widthWidget->setEnabled ( true );
417#else
418 heightWidget->show();
419 widthWidget->show();
420 ratioCheckBox->show();
421#endif
422 }
423}
424
425void G4OpenGLQtExportDialog::textWidthChanged(
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()*originalHeight/originalHeight));
435 }
436}
437
438void G4OpenGLQtExportDialog:: textHeightChanged(
439 const QString & s
440)
441{
442 if (!ratioCheckBox) return;
443 if (!width) return;
444
445 if (ratioCheckBox->isChecked()){
446 QString tmp;
447 width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
448 }
449}
450
451G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
452{
453}
454
455
456#endif
Note: See TracBrowser for help on using the repository browser.