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

Last change on this file since 600 was 599, checked in by garnier, 17 years ago

r636@mac-90108: laurentgarnier | 2007-11-12 16:46:00 +0100
modif pour qt3

  • Property svn:mime-type set to text/cpp
File size: 10.5 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.3 2007/11/09 15:03:21 lgarnier Exp $
28// GEANT4 tag $Name:  $
29//
30//
31
32#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
33
34#include "G4OpenGLQtExportDialog.hh"
35
36#include <qvariant.h>
37#include <qpushbutton.h>
38#include <qcheckbox.h>
39#include <qlabel.h>
40#include <qcombobox.h>
41#include <qslider.h>
42#include <qlayout.h>
43#include <qgroupbox.h>
44#include <qradiobutton.h>
45#include <qimage.h>
46#include <qlineedit.h>
47
48G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
49 QWidget* parent
50,QString nomFich
51 ,int aHeight
52 ,int aWidth
53)
54  : QDialog( parent )
55{
56#if QT_VERSION < 0x040000
57  setCaption( tr( " Export options" ));
58#else
59  setWindowTitle( tr( " Export options" ));
60#endif
61  originalWidth = aWidth;
62  originalHeight = aHeight;
63
64  // Initializations
65  qualitySlider = NULL;
66  width = NULL;
67  height = NULL;
68  colorButton = NULL;
69  BWButton = NULL;
70
71  // global layout
72#if QT_VERSION < 0x040000
73  QVBoxLayout* globalVLayout = new QVBoxLayout(this);
74#else
75  QVBoxLayout* globalVLayout = new QVBoxLayout();
76#endif
77
78 
79  if (nomFich.endsWith(".jpg") ||
80      nomFich.endsWith(".jepg")) {
81   
82    QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"));
83#if QT_VERSION < 0x040000
84    QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout(imageGroupBox);
85#else
86    QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout;
87#endif
88    QWidget *sliderBox = new QWidget;
89
90#if QT_VERSION < 0x040000
91    QHBoxLayout *hSlider = new QHBoxLayout(sliderBox);
92#else
93    QHBoxLayout *hSlider = new QHBoxLayout;
94#endif
95
96    //    qualityLabel =  new QLabel( tr( "Image quality" ) );
97    //    imageGroupBoxLayout->addWidget(qualityLabel);
98    qualitySlider= new QSlider(Qt::Horizontal,0);
99#if QT_VERSION < 0x040000
100    qualitySlider->setMinValue(0);
101    qualitySlider->setMaxValue(100);
102    qualitySlider->setTickmarks(QSlider::Below);
103#else
104    qualitySlider->setMinimum(0);
105    qualitySlider->setMaximum(100);
106    qualitySlider->setTickPosition(QSlider::TicksBelow);
107#endif
108    qualitySlider->setValue(60);
109    hSlider->addWidget(new QLabel("low",0));
110    hSlider->addWidget(qualitySlider);
111    hSlider->addWidget(new QLabel("Maximum",0));
112#if QT_VERSION >= 0x040000
113    sliderBox->setLayout(hSlider);
114#endif
115    imageGroupBoxLayout->addWidget(sliderBox);
116
117#if QT_VERSION >= 0x040000
118    imageGroupBox->setLayout(imageGroupBoxLayout);
119#endif
120    globalVLayout->addWidget(imageGroupBox);
121  }
122 
123  if(nomFich.endsWith(".eps")) {
124    QGroupBox *EPSGroupBox = new QGroupBox(tr("EPS options"));
125
126#if QT_VERSION < 0x040000
127    QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSGroupBox);
128#else
129    QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout;
130#endif
131
132    //    transparencyEPS = new QCheckBox( "transparencyEPS" );
133    //    transparencyEPS->setText( "save background" );
134    //    transparencyEPS->setChecked( true );
135
136    colorButton = new QRadioButton("Color",0);
137    BWButton = new QRadioButton("Grayscale",0);
138    colorButton->setChecked( true );
139    BWButton->setChecked( false );
140
141
142    //    EPSGroupBoxLayout->addWidget(transparencyEPS);   
143    EPSGroupBoxLayout->addWidget(colorButton);   
144    EPSGroupBoxLayout->addWidget(BWButton);   
145#if QT_VERSION >= 0x040000
146    EPSGroupBox->setLayout(EPSGroupBoxLayout);
147#endif
148    globalVLayout->addWidget(EPSGroupBox);
149
150  }
151
152  if(nomFich.endsWith(".tif") ||
153     nomFich.endsWith(".tiff") ||
154     nomFich.endsWith(".jpg") ||
155     nomFich.endsWith(".png") ||
156     nomFich.endsWith(".xpm")) {
157
158    QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"));
159#if QT_VERSION < 0x040000
160    QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
161#else
162    QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout;
163#endif
164
165    boxTransparency = new QCheckBox("Save transparency",0);
166    boxTransparency->setChecked( false );
167    //    boxTransparency->setEnabled(false);
168
169    transparencyGroupBoxLayout->addWidget(boxTransparency);   
170#if QT_VERSION >= 0x040000
171    transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
172#endif
173    globalVLayout->addWidget(transparencyGroupBox);
174
175  }
176
177  // size box
178  QGroupBox *sizeGroupBox = new QGroupBox(tr("Size"));
179  QWidget* modifyAndRatioWidget = new QWidget;
180
181#if QT_VERSION < 0x040000
182  QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget);
183  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
184#else
185  QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout;
186  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout;
187#endif
188
189  // original button
190  original = new QRadioButton("Original",0);
191  original->setChecked( true );
192  sizeGroupBoxLayout->addWidget(original);
193
194  // modify and ratio
195  modify = new QRadioButton("Modify",0);
196  modify->setChecked( false );
197
198  ratioCheckBox = new QCheckBox( "Keep ratio",0 );
199  ratioCheckBox->setChecked( true );
200
201  modifyAndRatioLayout->addWidget(modify);
202  modifyAndRatioLayout->addWidget(ratioCheckBox);
203#if QT_VERSION >= 0x040000
204  modifyAndRatioWidget->setLayout(modifyAndRatioLayout);
205#endif
206  sizeGroupBoxLayout->addWidget(modifyAndRatioWidget);
207  if (modify->isChecked()) {
208    ratioCheckBox->show();
209  } else {
210    ratioCheckBox->hide();
211  }
212
213  connect( original, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(true)) );
214  connect( modify, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(false) ) );
215
216  // height
217  heightWidget = new QWidget;
218
219#if QT_VERSION < 0x040000
220  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
221#else
222  QHBoxLayout *heightLineLayout = new QHBoxLayout;
223#endif
224
225  QString tmp;
226 
227  heightLineLayout->addWidget(new QLabel("Height",0));
228  height = new QLineEdit(tmp.setNum(originalHeight),0);
229  height->setMaxLength(5);
230  heightLineLayout->addWidget(height);
231#if QT_VERSION >= 0x040000
232  heightWidget->setLayout(heightLineLayout);
233#endif
234  sizeGroupBoxLayout->addWidget(heightWidget);
235  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
236
237
238  // width
239  widthWidget = new QWidget;
240
241#if QT_VERSION < 0x040000
242  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
243#else
244  QHBoxLayout *widthLineLayout = new QHBoxLayout;
245#endif
246
247  widthLineLayout->addWidget(new QLabel("Width ",0));
248  width = new QLineEdit(tmp.setNum(originalWidth),0);
249  width->setMaxLength(5);
250  widthLineLayout->addWidget(width);
251#if QT_VERSION >= 0x040000
252  widthWidget->setLayout(widthLineLayout);
253#endif
254  sizeGroupBoxLayout->addWidget(widthWidget);
255  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
256
257#if QT_VERSION >= 0x040000
258  sizeGroupBox->setLayout(sizeGroupBoxLayout);
259#endif
260  globalVLayout->addWidget(sizeGroupBox);
261
262  heightWidget->hide();
263  widthWidget->hide();
264
265  // button ok/cancel box
266
267  QGroupBox *buttonGroupBox = new QGroupBox();
268
269#if QT_VERSION < 0x040000
270  QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox);
271#else
272  QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout;
273#endif
274
275  buttonOk = new QPushButton( tr( "&OK" ),0 );
276  buttonOk->setAutoDefault( TRUE );
277  buttonOk->setDefault( TRUE );
278  buttonGroupBoxLayout->addWidget(buttonOk);
279
280  buttonCancel = new QPushButton( tr( "&Cancel" ),0 );
281  buttonCancel->setAutoDefault( TRUE );
282  buttonGroupBoxLayout->addWidget(buttonCancel);
283
284#if QT_VERSION >= 0x040000
285  buttonGroupBox->setLayout(buttonGroupBoxLayout);
286#endif
287  globalVLayout->addWidget(buttonGroupBox);
288
289
290#if QT_VERSION >= 0x040000
291  setLayout(globalVLayout);
292#endif
293
294  // signals and slots connections
295  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
296  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
297}
298
299
300
301int G4OpenGLQtExportDialog::getSliderValue()
302{
303  if (!qualitySlider) return -1;
304  return qualitySlider->value();
305}
306
307int G4OpenGLQtExportDialog::getHeight()
308{
309  if (!height) return -1;
310  return height->text().toInt();
311}
312
313int G4OpenGLQtExportDialog::getWidth()
314{
315  if (!width) return -1;
316  return width->text().toInt();
317}
318
319bool G4OpenGLQtExportDialog::getTransparency()
320{
321  if (!boxTransparency) return -1;
322  return boxTransparency->isChecked();
323}
324
325int G4OpenGLQtExportDialog::getNbColor()
326{
327  // Black and white
328  if (!colorButton->isChecked())
329    return 1;
330  // rgb color
331  return 3;
332}
333
334
335void G4OpenGLQtExportDialog::changeSizeBox(bool aClick)
336{
337  if (aClick) {
338    modify->toggle();
339  } else {
340    original->toggle();
341  }
342  if ( original->isChecked()) {
343    heightWidget->hide();
344    widthWidget->hide();
345    ratioCheckBox->hide();
346  } else {
347    heightWidget->show();
348    widthWidget->show();
349    ratioCheckBox->show();
350  }
351}
352
353void G4OpenGLQtExportDialog::textWidthChanged(
354 const QString & s
355 )
356{
357  if (ratioCheckBox->isChecked()){
358    QString tmp;
359    width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
360  }
361}
362
363void G4OpenGLQtExportDialog::  textHeightChanged(
364 const QString & s
365)
366{
367  if (ratioCheckBox->isChecked()){
368    QString tmp;
369    width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
370  }
371}
372
373G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
374{
375}
376
377
378#endif
Note: See TracBrowser for help on using the repository browser.