source: trunk/source/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc@ 843

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

corrections pour Qt3 mises sous cvs

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