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

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

amelioration du ticket #66

  • 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 ,int aHeight
54 ,int aWidth
55)
56 : QDialog( parent )
57{
58#if QT_VERSION < 0x040000
59 setCaption( tr( " Export options" ));
60#else
61 setWindowTitle( tr( " Export options" ));
62#endif
63 originalWidth = aWidth;
64 originalHeight = aHeight;
65
66 // Initializations
67 qualitySlider = NULL;
68 width = NULL;
69 height = NULL;
70 colorButton = NULL;
71 BWButton = NULL;
72
73 // global layout
74 QVBoxLayout* globalVLayout = new QVBoxLayout(this);
75
76
77 if (nomFich.endsWith(".jpg") ||
78 nomFich.endsWith(".jpeg")) {
79
80 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
81 QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout(imageGroupBox);
82 QWidget *sliderBox = new QWidget();
83
84 QHBoxLayout *hSliderLayout = new QHBoxLayout(sliderBox);
85
86 // qualityLabel = new QLabel( tr( "Image quality" ) );
87 // imageGroupBoxLayout->addWidget(qualityLabel);
88 qualitySlider= new QSlider(Qt::Horizontal,sliderBox);
89#if QT_VERSION < 0x040000
90 qualitySlider->setMinValue(0);
91 qualitySlider->setMaxValue(100);
92 qualitySlider->setTickmarks(QSlider::Below);
93#else
94 qualitySlider->setMinimum(0);
95 qualitySlider->setMaximum(100);
96 qualitySlider->setTickPosition(QSlider::TicksBelow);
97#endif
98 qualitySlider->setValue(60);
99 hSliderLayout->addWidget(new QLabel("low",sliderBox));
100 hSliderLayout->addWidget(qualitySlider);
101 hSliderLayout->addWidget(new QLabel("Maximum",sliderBox));
102#if QT_VERSION >= 0x040000
103 sliderBox->setLayout(hSliderLayout);
104#endif
105 imageGroupBoxLayout->addWidget(sliderBox);
106
107#if QT_VERSION >= 0x040000
108 imageGroupBox->setLayout(imageGroupBoxLayout);
109#endif
110 globalVLayout->addWidget(imageGroupBox);
111 }
112
113 // FIXME : L. Garnier 4/12/07
114 // This is not working for PS and PDF images, it does nothing.
115 // Image is staying in color mode
116 // if ((nomFich.endsWith(".ps")) || (nomFich.endsWith(".pdf")) || (nomFich.endsWith(".eps"))) {
117 if ((nomFich.endsWith(".eps"))) {
118
119
120 QWidget * EPSWidgetGroupBox; // widget containing group button
121 QButtonGroup * EPSButtonGroupBox; // group button
122
123
124#if QT_VERSION < 0x040000
125 colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
126 BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
127 EPSButtonGroupBox = new QButtonGroup( 2,Qt::Vertical, tr("EPS options"),this);
128 EPSButtonGroupBox->insert(colorButton);
129 EPSButtonGroupBox->insert(BWButton);
130 EPSButtonGroupBox->setExclusive(true);
131 EPSWidgetGroupBox = EPSButtonGroupBox;
132
133#else
134 EPSWidgetGroupBox = new QGroupBox(tr("EPS options"));
135 QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
136
137 colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
138 BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
139
140 EPSButtonGroupBox = new QButtonGroup();
141 EPSButtonGroupBox->addButton(colorButton);
142 EPSButtonGroupBox->addButton(BWButton);
143 EPSButtonGroupBox->setExclusive(true);
144
145 EPSGroupBoxLayout->addWidget(colorButton);
146 EPSGroupBoxLayout->addWidget(BWButton);
147 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
148
149#endif
150 colorButton->setChecked( true );
151
152 globalVLayout->addWidget(EPSWidgetGroupBox);
153
154 }
155
156 // FIXME : L. Garnier 4/12/07
157 // Not implented. Should deal with alpha channel
158
159// if(nomFich.endsWith(".tif") ||
160// nomFich.endsWith(".tiff") ||
161// nomFich.endsWith(".jpg") ||
162// nomFich.endsWith(".jpeg") ||
163// nomFich.endsWith(".png") ||
164// nomFich.endsWith(".xpm")) {
165
166// QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
167// QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
168
169// boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
170// boxTransparency->setChecked( false );
171
172// transparencyGroupBoxLayout->addWidget(boxTransparency);
173// #if QT_VERSION >= 0x040000
174// transparencyGroupBox->setLayout(transparencyGroupBoxLayout);
175// #endif
176// globalVLayout->addWidget(transparencyGroupBox);
177
178// }
179
180 // size box
181 QWidget* modifyAndRatioWidget = new QWidget();
182
183 QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout(modifyAndRatioWidget);
184
185 QWidget * sizeWidgetGroupBox; // widget containing group button
186 QButtonGroup * sizeButtonGroupBox; // group button
187 QLayout *sizeGroupBoxLayout;
188#if QT_VERSION < 0x040000
189 sizeButtonGroupBox = new QButtonGroup ( 2,Qt::Vertical, tr("Size"),this);
190
191 original = new QRadioButton("Original",sizeButtonGroupBox);
192 modify = new QRadioButton("Modify",sizeButtonGroupBox);
193
194 sizeButtonGroupBox->insert(original);
195 sizeButtonGroupBox->insert(modify);
196 sizeButtonGroupBox->setExclusive(true);
197 sizeWidgetGroupBox = sizeButtonGroupBox;
198 sizeGroupBoxLayout = sizeWidgetGroupBox->layout();
199
200#else
201
202 sizeWidgetGroupBox = new QGroupBox(tr("Size"));
203 sizeGroupBoxLayout = new QVBoxLayout(sizeWidgetGroupBox);
204 sizeButtonGroupBox = new QButtonGroup();
205
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 original->setChecked( true );
219
220
221 ratioCheckBox = new QCheckBox( "Keep ratio",modifyAndRatioWidget);
222 ratioCheckBox->setChecked( true );
223
224 modifyAndRatioLayout->addWidget(modify);
225 modifyAndRatioLayout->addWidget(ratioCheckBox);
226#if QT_VERSION >= 0x040000
227 modifyAndRatioWidget->setLayout(modifyAndRatioLayout);
228#endif
229#if QT_VERSION < 0x040000
230 sizeGroupBoxLayout->add(modifyAndRatioWidget);
231#else
232 sizeGroupBoxLayout->addWidget(modifyAndRatioWidget);
233#endif
234 if (modify->isChecked()) {
235 ratioCheckBox->show();
236 } else {
237 ratioCheckBox->hide();
238 }
239
240#if QT_VERSION < 0x040000
241 connect( sizeButtonGroupBox, SIGNAL( clicked(int) ), this, SLOT( changeSizeBox()) );
242#else
243 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(int) ), this, SLOT( changeSizeBox()) );
244#endif
245
246 // height
247 heightWidget = new QWidget();
248
249 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
250
251 QString tmp;
252
253 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
254 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
255 height->setMaxLength(5);
256#if QT_VERSION < 0x040000
257 heightLineLayout->add(height);
258#else
259 heightLineLayout->addWidget(height);
260#endif
261#if QT_VERSION >= 0x040000
262 heightWidget->setLayout(heightLineLayout);
263#endif
264#if QT_VERSION < 0x040000
265 sizeGroupBoxLayout->add(heightWidget);
266#else
267 sizeGroupBoxLayout->addWidget(heightWidget);
268#endif
269 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
270
271
272 // width
273 widthWidget = new QWidget();
274
275 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
276
277#if QT_VERSION < 0x040000
278 widthLineLayout->add(new QLabel("Width ",widthWidget));
279#else
280 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
281#endif
282 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
283 width->setMaxLength(5);
284#if QT_VERSION < 0x040000
285 widthLineLayout->add(width);
286#else
287 widthLineLayout->addWidget(width);
288#endif
289#if QT_VERSION >= 0x040000
290 widthWidget->setLayout(widthLineLayout);
291#endif
292#if QT_VERSION < 0x040000
293 sizeGroupBoxLayout->add(widthWidget);
294#else
295 sizeGroupBoxLayout->addWidget(widthWidget);
296#endif
297 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
298
299#if QT_VERSION >= 0x040000
300 sizeWidgetGroupBox->setLayout(sizeGroupBoxLayout);
301#endif
302 globalVLayout->addWidget(sizeWidgetGroupBox);
303
304 heightWidget->hide();
305 widthWidget->hide();
306
307 // button ok/cancel box
308
309 QGroupBox *buttonGroupBox = new QGroupBox(this);
310
311 QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout(buttonGroupBox);
312
313 buttonOk = new QPushButton( tr( "&OK" ),buttonGroupBox );
314 buttonOk->setAutoDefault( TRUE );
315 buttonOk->setDefault( TRUE );
316 buttonGroupBoxLayout->addWidget(buttonOk);
317
318 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonGroupBox );
319 buttonCancel->setAutoDefault( TRUE );
320 buttonGroupBoxLayout->addWidget(buttonCancel);
321
322#if QT_VERSION >= 0x040000
323 buttonGroupBox->setLayout(buttonGroupBoxLayout);
324#endif
325 globalVLayout->addWidget(buttonGroupBox);
326
327
328#if QT_VERSION >= 0x040000
329 setLayout(globalVLayout);
330#endif
331
332 // signals and slots connections
333 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
334 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
335}
336
337
338
339int G4OpenGLQtExportDialog::getSliderValue()
340{
341 if (!qualitySlider) return -1;
342 return qualitySlider->value();
343}
344
345int G4OpenGLQtExportDialog::getHeight()
346{
347 if (!height) return -1;
348 return height->text().toInt();
349}
350
351int G4OpenGLQtExportDialog::getWidth()
352{
353 if (!width) return -1;
354 return width->text().toInt();
355}
356
357bool G4OpenGLQtExportDialog::getTransparency()
358{
359 if (!boxTransparency) return -1;
360 return boxTransparency->isChecked();
361}
362
363int G4OpenGLQtExportDialog::getNbColor()
364{
365 if (!colorButton) return -1;
366 // Black and white
367 if (!colorButton->isChecked())
368 return 1;
369 // rgb color
370 return 3;
371}
372
373
374void G4OpenGLQtExportDialog::changeSizeBox()
375{
376 if (!original) return;
377 if (!heightWidget) return;
378 if (!widthWidget) return;
379 if (!ratioCheckBox) return;
380
381 if ( original->isChecked()) {
382 heightWidget->hide();
383 widthWidget->hide();
384 ratioCheckBox->hide();
385 } else {
386 heightWidget->show();
387 widthWidget->show();
388 ratioCheckBox->show();
389 }
390}
391
392void G4OpenGLQtExportDialog::textWidthChanged(
393 const QString & s
394 )
395{
396 if (!ratioCheckBox) return;
397 if (!width) return;
398
399 if (ratioCheckBox->isChecked()){
400 QString tmp;
401 width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight));
402 }
403}
404
405void G4OpenGLQtExportDialog:: textHeightChanged(
406 const QString & s
407)
408{
409 if (!ratioCheckBox) return;
410 if (!width) return;
411
412 if (ratioCheckBox->isChecked()){
413 QString tmp;
414 width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth));
415 }
416}
417
418G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
419{
420}
421
422
423#endif
Note: See TracBrowser for help on using the repository browser.