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

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

correction du ticket #110

  • Property svn:mime-type set to text/cpp
File size: 13.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.5 2008/01/15 11:05:08 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#define GEANT4_QT_DEBUG
38
39#include <qvariant.h>
40#include <qpushbutton.h>
41#include <qcheckbox.h>
42#include <qlabel.h>
43#include <qcombobox.h>
44#include <qslider.h>
45#include <qlayout.h>
46#include <qgroupbox.h>
47#include <qradiobutton.h>
48#include <qimage.h>
49#include <qlineedit.h>
50#include <qbuttongroup.h>
51
52G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
53 QWidget* parent
54,QString format
55 ,int aHeight
56 ,int aWidth
57)
58  : QDialog( parent ),
59    isChangingSize(false)
60{
61#if QT_VERSION < 0x040000
62  setCaption( tr( " Export options" ));
63#else
64  setWindowTitle( tr( " Export options" ));
65#endif
66  originalWidth = aWidth;
67  originalHeight = aHeight;
68
69  // Initializations
70  qualitySlider = NULL;
71  width = NULL;
72  height = NULL;
73  colorButton = NULL;
74  BWButton = NULL;
75
76  // global layout
77  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
78  globalVLayout->setMargin(10);
79  globalVLayout->setSpacing(10);
80 
81
82
83  // FIXME : L. Garnier 4/12/07
84  // Not implented. Should deal with alpha channel
85
86//   if((format == "tif") ||
87//      (format == "tiff") ||
88//      (format == "jpg") ||
89//      (format == "jpeg") ||
90//      (format == "png") ||
91//      (format == "xpm")) {
92
93//     QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
94//     QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
95
96//     boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
97//     boxTransparency->setChecked( false );
98
99//     transparencyGroupBoxLayout->addWidget(boxTransparency);   
100// #if QT_VERSION >= 0x040000
101//     transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
102// #endif
103//     globalVLayout->addWidget(transparencyGroupBox);
104
105//   }
106
107  // FIXME : L. Garnier 4/12/07
108  // This is not working for PS and PDF images, it does nothing.
109  // Image is staying in color mode
110  //  if ((format == "ps") || (format == "pdf") || (format == "eps")) {
111
112
113  // size box
114
115  QWidget * sizeWidget = new QWidget(this); // widget containing group button
116  QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
117  sizeWidgetLayout->setMargin (10);
118
119  // original and modify radiobuttons
120#if QT_VERSION < 0x040000
121  QButtonGroup * sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
122  sizeButtonGroupBox->setInsideMargin (15);
123
124  original = new QRadioButton("Original",sizeButtonGroupBox);
125  modify = new QRadioButton("Modify",sizeButtonGroupBox);
126
127  sizeButtonGroupBox->insert(original);
128  sizeButtonGroupBox->insert(modify);
129  sizeButtonGroupBox->setExclusive(true);
130  sizeWidgetLayout->add(sizeButtonGroupBox);
131
132  connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
133#else
134 
135  sizeGroupBox = new QGroupBox(tr("Size"));
136  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
137  QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
138  sizeGroupBoxLayout->setMargin (15);
139
140  original = new QRadioButton("Original");
141  modify = new QRadioButton("Modify");
142
143  sizeButtonGroupBox->addButton(original);
144  sizeButtonGroupBox->addButton(modify);
145  sizeButtonGroupBox->setExclusive(true);
146
147  sizeGroupBoxLayout->addWidget(original);   
148  sizeGroupBoxLayout->addWidget(modify);   
149
150  sizeGroupBox->setLayout(sizeGroupBoxLayout);
151  sizeWidgetLayout->addWidget(sizeGroupBox);
152 
153  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) );
154#endif
155  original->setChecked( true );
156
157
158  // height
159  heightWidget = new QWidget(sizeWidget);
160
161  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
162
163  QString tmp;
164 
165  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
166  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
167  height->setMaxLength(5);
168#if QT_VERSION < 0x040000
169  heightLineLayout->add(height);
170#else
171  heightLineLayout->addWidget(height);
172#endif
173
174#if QT_VERSION >= 0x040000
175  heightWidget->setLayout(heightLineLayout);
176#endif
177
178#if QT_VERSION < 0x040000
179  sizeWidgetLayout->add(heightWidget);
180#else
181  sizeWidgetLayout->addWidget(heightWidget);
182#endif
183  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
184
185
186  // width
187  widthWidget = new QWidget(sizeWidget);
188
189  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
190
191#if QT_VERSION < 0x040000
192  widthLineLayout->add(new QLabel("Width ",widthWidget));
193#else
194  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
195#endif
196  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
197  width->setMaxLength(5);
198#if QT_VERSION < 0x040000
199  widthLineLayout->add(width);
200#else
201  widthLineLayout->addWidget(width);
202#endif
203#if QT_VERSION >= 0x040000
204  widthWidget->setLayout(widthLineLayout);
205#endif
206#if QT_VERSION < 0x040000
207  sizeWidgetLayout->add(widthWidget);
208#else
209  sizeWidgetLayout->addWidget(widthWidget);
210#endif
211  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
212
213
214
215  // ratio check box
216
217  ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
218  ratioCheckBox->setChecked( true );
219
220#if QT_VERSION < 0x040000
221  sizeWidgetLayout->add(ratioCheckBox);
222#else
223  sizeWidgetLayout->addWidget(ratioCheckBox);
224#endif
225
226#if QT_VERSION < 0x040000
227  ratioCheckBox->setEnabled ( false );
228  heightWidget->setEnabled ( false );
229  widthWidget->setEnabled ( false );
230#else
231  ratioCheckBox->hide();
232  heightWidget->hide();
233  widthWidget->hide();
234#endif
235
236#if QT_VERSION >= 0x040000
237  sizeWidget->setLayout(sizeWidgetLayout);
238#endif
239  globalVLayout->addWidget(sizeWidget);
240
241 if (format == "eps") {
242
243   QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
244
245
246#if QT_VERSION < 0x040000
247
248    EPSWidgetGroupBox->setInsideMargin (15);
249
250    //    QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
251    //    EPSGroupBoxLayout = new QVBoxLayout(EPSColorButtonGroupBox);
252    //     colorButton = new QRadioButton("Color",EPSColorButtonGroupBox);
253    //     BWButton = new QRadioButton("Grayscale",EPSColorButtonGroupBox);
254    //     EPSColorButtonGroupBox->setInsideMargin (15);
255    //     EPSColorButtonGroupBox->insert(colorButton);
256    //     EPSColorButtonGroupBox->insert(BWButton);
257    //     EPSColorButtonGroupBox->setExclusive(true);
258    //     EPSWidgetGroupBox->add(EPSColorButtonGroupBox);
259
260    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
261
262#else
263    QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
264     EPSGroupBoxLayout->setMargin (15);
265
266//     colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
267//     BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
268
269//     QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
270//     EPSColorButtonGroupBox->addButton(colorButton);
271//     EPSColorButtonGroupBox->addButton(BWButton);
272//     EPSColorButtonGroupBox->setExclusive(true);
273
274//     EPSGroupBoxLayout->addWidget(colorButton);   
275//     EPSGroupBoxLayout->addWidget(BWButton);   
276
277    vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
278    EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
279
280    EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
281#endif
282    //    colorButton->setChecked( true );
283    vectorEPSCheckBox->setChecked( true );
284   
285    globalVLayout->addWidget(EPSWidgetGroupBox);
286    connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
287
288  }
289
290  if ((format == "jpg") ||
291      (format == "jpeg")) {
292   
293    QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
294    QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
295    hSliderLayout->setMargin (15);
296
297    qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
298#if QT_VERSION < 0x040000
299    qualitySlider->setMinValue(0);
300    qualitySlider->setMaxValue(100);
301    qualitySlider->setTickmarks(QSlider::Below);
302#else
303    qualitySlider->setMinimum(0);
304    qualitySlider->setMaximum(100);
305    qualitySlider->setTickPosition(QSlider::TicksBelow);
306#endif
307    qualitySlider->setValue(60);
308    hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
309    hSliderLayout->addWidget(qualitySlider);
310    hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
311   
312#if QT_VERSION >= 0x040000
313    imageGroupBox->setLayout(hSliderLayout);
314#endif
315
316#if QT_VERSION >= 0x040000
317    imageGroupBox->setLayout(hSliderLayout);
318#endif
319
320    globalVLayout->addWidget(imageGroupBox);
321  }
322
323
324  // button ok/cancel box
325
326  QWidget *buttonBox = new QWidget(this);
327
328  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
329
330  buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
331  buttonOk->setAutoDefault( TRUE );
332  buttonOk->setDefault( TRUE );
333  buttonBoxLayout->addWidget(buttonOk);
334
335  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
336  buttonCancel->setAutoDefault( TRUE );
337  buttonBoxLayout->addWidget(buttonCancel);
338
339#if QT_VERSION >= 0x040000
340  buttonBox->setLayout(buttonBoxLayout);
341#endif
342  globalVLayout->addWidget(buttonBox);
343
344
345
346#if QT_VERSION >= 0x040000
347  setLayout(globalVLayout);
348#endif
349
350  // signals and slots connections
351  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
352  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
353}
354
355
356
357int G4OpenGLQtExportDialog::getSliderValue()
358{
359  if (!qualitySlider) return -1;
360  return qualitySlider->value();
361}
362
363int G4OpenGLQtExportDialog::getHeight()
364{
365  if (!height) return originalHeight;
366  return height->text().toInt();
367}
368
369int G4OpenGLQtExportDialog::getWidth()
370{
371  if (!width) return originalWidth;
372  return width->text().toInt();
373}
374
375bool G4OpenGLQtExportDialog::getTransparency()
376{
377  if (!boxTransparency) return -1;
378  return boxTransparency->isChecked();
379}
380
381int G4OpenGLQtExportDialog::getNbColor()
382{
383  if (!colorButton) return -1;
384  // Black and white
385  if (!colorButton->isChecked())
386    return 1;
387  // rgb color
388  return 3;
389}
390
391bool G4OpenGLQtExportDialog::getVectorEPS()
392{
393  if (!vectorEPSCheckBox) return 0;
394  return vectorEPSCheckBox->isChecked();
395}
396
397
398void G4OpenGLQtExportDialog::changeVectorEPS()
399{
400  if (!vectorEPSCheckBox) return;
401  if (vectorEPSCheckBox->isChecked()) {
402#if QT_VERSION < 0x040000
403    original->setEnabled ( true );
404    modify->setEnabled ( true );
405#else
406    sizeGroupBox->show();
407    original->show();
408    modify->show();
409#endif
410    changeSizeBox();
411  } else {
412#if QT_VERSION < 0x040000
413    original->setEnabled ( false );
414    modify->setEnabled ( false );
415    ratioCheckBox->setEnabled ( false );
416    heightWidget->setEnabled ( false );
417    widthWidget->setEnabled ( false );
418#else
419    sizeGroupBox->hide();
420    original->hide();
421    modify->hide();
422    ratioCheckBox->hide();
423    heightWidget->hide();
424    widthWidget->hide();
425#endif
426  }
427}
428
429
430void G4OpenGLQtExportDialog::changeSizeBox()
431{
432  if (!original) return;
433  if (!heightWidget) return;
434  if (!widthWidget) return;
435  if (!ratioCheckBox) return;
436
437  if ( original->isChecked()) {
438#if QT_VERSION < 0x040000
439    ratioCheckBox->setEnabled ( false );
440    heightWidget->setEnabled ( false );
441    widthWidget->setEnabled ( false );
442#else
443    ratioCheckBox->hide();
444    heightWidget->hide();
445    widthWidget->hide();
446#endif
447  } else {
448#if QT_VERSION < 0x040000
449    ratioCheckBox->setEnabled ( true );
450    heightWidget->setEnabled ( true );
451    widthWidget->setEnabled ( true );
452#else
453    heightWidget->show();
454    widthWidget->show();
455    ratioCheckBox->show();
456#endif
457  }
458}
459
460
461void G4OpenGLQtExportDialog::textWidthChanged(
462 const QString & s
463 )
464{
465  if (!ratioCheckBox) return;
466  if (!width) return;
467  if (isChangingSize == true) return; // exclusive slot
468
469  if (ratioCheckBox->isChecked()){
470    isChangingSize = true;
471    QString tmp;
472  height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth))));
473  isChangingSize = false;
474  }
475}
476
477void G4OpenGLQtExportDialog::  textHeightChanged(
478 const QString & s
479)
480{
481  if (!ratioCheckBox) return;
482  if (!width) return;
483  if (isChangingSize == true) return; // exclusive slot
484
485  if (ratioCheckBox->isChecked()){
486  isChangingSize = true;
487    QString tmp;
488    width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
489  isChangingSize = false;
490  }
491}
492
493G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
494{
495}
496
497
498#endif
Note: See TracBrowser for help on using the repository browser.