Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4OpenGLQtExportDialog.cc
Go to the documentation of this file.
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$
28//
29//
30
31#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
32
34
35#include <qvariant.h>
36#include <qpushbutton.h>
37#include <qcheckbox.h>
38#include <qlabel.h>
39#include <qcombobox.h>
40#include <qslider.h>
41#include <qlayout.h>
42#include <qgroupbox.h>
43#include <qradiobutton.h>
44#include <qimage.h>
45#include <qlineedit.h>
46#include <qbuttongroup.h>
47
48G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
49 QWidget* parentw
50,QString format
51 ,int aHeight
52 ,int aWidth
53)
54 : QDialog( parentw ),
55 isChangingSize(false)
56{
57 setWindowTitle( tr( " Export options" ));
58 originalWidth = aWidth;
59 originalHeight = aHeight;
60
61 // Initializations
62 qualitySlider = NULL;
63 width = NULL;
64 height = NULL;
65 colorButton = NULL;
66 BWButton = NULL;
67
68 // global layout
69 QVBoxLayout* globalVLayout = new QVBoxLayout(this);
70 globalVLayout->setMargin(10);
71 globalVLayout->setSpacing(10);
72
73
74
75 // FIXME : L. Garnier 4/12/07
76 // Not implented. Should deal with alpha channel
77
78// if((format == "tif") ||
79// (format == "tiff") ||
80// (format == "jpg") ||
81// (format == "jpeg") ||
82// (format == "png") ||
83// (format == "xpm")) {
84
85// QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency"),this);
86// QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout(transparencyGroupBox);
87
88// boxTransparency = new QCheckBox("Save transparency",transparencyGroupBox);
89// boxTransparency->setChecked( false );
90
91// transparencyGroupBoxLayout->addWidget(boxTransparency);
92// globalVLayout->addWidget(transparencyGroupBox);
93
94// }
95
96 // FIXME : L. Garnier 4/12/07
97 // This is not working for PS and PDF images, it does nothing.
98 // Image is staying in color mode
99 // if ((format == "ps") || (format == "pdf") || (format == "eps")) {
100
101
102 // size box
103
104 QWidget * sizeWidget = new QWidget(this); // widget containing group button
105 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
106 sizeWidgetLayout->setMargin (10);
107
108 // original and modify radiobuttons
109
110 sizeGroupBox = new QGroupBox(tr("Size"));
111 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
112 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
113 sizeGroupBoxLayout->setMargin (15);
114
115 original = new QRadioButton("Original");
116 modify = new QRadioButton("Modify");
117
118 sizeButtonGroupBox->addButton(original);
119 sizeButtonGroupBox->addButton(modify);
120 sizeButtonGroupBox->setExclusive(true);
121
122 sizeGroupBoxLayout->addWidget(original);
123 sizeGroupBoxLayout->addWidget(modify);
124
125 sizeGroupBox->setLayout(sizeGroupBoxLayout);
126 sizeWidgetLayout->addWidget(sizeGroupBox);
127
128 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) );
129 original->setChecked( true );
130
131
132 // height
133 heightWidget = new QWidget(sizeWidget);
134
135 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
136
137 QString tmp;
138
139 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
140 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
141 height->setMaxLength(5);
142 heightLineLayout->addWidget(height);
143
144 heightWidget->setLayout(heightLineLayout);
145
146 sizeWidgetLayout->addWidget(heightWidget);
147 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
148
149
150 // width
151 widthWidget = new QWidget(sizeWidget);
152
153 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
154
155 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
156 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
157 width->setMaxLength(5);
158 widthLineLayout->addWidget(width);
159 widthWidget->setLayout(widthLineLayout);
160 sizeWidgetLayout->addWidget(widthWidget);
161 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
162
163
164
165 // ratio check box
166
167 ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
168 ratioCheckBox->setChecked( true );
169
170 sizeWidgetLayout->addWidget(ratioCheckBox);
171
172 ratioCheckBox->hide();
173 heightWidget->hide();
174 widthWidget->hide();
175
176 sizeWidget->setLayout(sizeWidgetLayout);
177 globalVLayout->addWidget(sizeWidget);
178
179 if (format == "eps") {
180
181 QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
182
183
184 QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
185 EPSGroupBoxLayout->setMargin (15);
186
187// colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
188// BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
189
190// QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
191// EPSColorButtonGroupBox->addButton(colorButton);
192// EPSColorButtonGroupBox->addButton(BWButton);
193// EPSColorButtonGroupBox->setExclusive(true);
194
195// EPSGroupBoxLayout->addWidget(colorButton);
196// EPSGroupBoxLayout->addWidget(BWButton);
197
198 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
199 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
200
201 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
202 // colorButton->setChecked( true );
203 vectorEPSCheckBox->setChecked( true );
204
205 globalVLayout->addWidget(EPSWidgetGroupBox);
206 connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
207
208 }
209
210 if ((format == "jpg") ||
211 (format == "jpeg")) {
212
213 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
214 QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
215 hSliderLayout->setMargin (15);
216
217 qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
218 qualitySlider->setMinimum(0);
219 qualitySlider->setMaximum(100);
220 qualitySlider->setTickPosition(QSlider::TicksBelow);
221 qualitySlider->setValue(60);
222 hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
223 hSliderLayout->addWidget(qualitySlider);
224 hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
225
226 imageGroupBox->setLayout(hSliderLayout);
227
228 globalVLayout->addWidget(imageGroupBox);
229 }
230
231
232 // button ok/cancel box
233
234 QWidget *buttonBox = new QWidget(this);
235
236 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
237
238 buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
239 buttonOk->setAutoDefault( TRUE );
240 buttonOk->setDefault( TRUE );
241 buttonBoxLayout->addWidget(buttonOk);
242
243 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
244 buttonCancel->setAutoDefault( TRUE );
245 buttonBoxLayout->addWidget(buttonCancel);
246
247 buttonBox->setLayout(buttonBoxLayout);
248 globalVLayout->addWidget(buttonBox);
249
250
251
252 setLayout(globalVLayout);
253
254 // signals and slots connections
255 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
256 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
257}
258
259
260
261int G4OpenGLQtExportDialog::getSliderValue()
262{
263 if (!qualitySlider) return -1;
264 return qualitySlider->value();
265}
266
267int G4OpenGLQtExportDialog::getHeight()
268{
269 if (!height) return originalHeight;
270 return height->text().toInt();
271}
272
273int G4OpenGLQtExportDialog::getWidth()
274{
275 if (!width) return originalWidth;
276 return width->text().toInt();
277}
278
279int G4OpenGLQtExportDialog::getTransparency()
280{
281 if (!boxTransparency) return -1;
282 return boxTransparency->isChecked();
283}
284
285int G4OpenGLQtExportDialog::getNbColor()
286{
287 if (!colorButton) return -1;
288 // Black and white
289 if (!colorButton->isChecked())
290 return 1;
291 // rgb color
292 return 3;
293}
294
295bool G4OpenGLQtExportDialog::getVectorEPS()
296{
297 if (!vectorEPSCheckBox) return 0;
298 return vectorEPSCheckBox->isChecked();
299}
300
301
302void G4OpenGLQtExportDialog::changeVectorEPS()
303{
304 if (!vectorEPSCheckBox) return;
305 if (vectorEPSCheckBox->isChecked()) {
306 sizeGroupBox->show();
307 original->show();
308 modify->show();
309 changeSizeBox();
310 } else {
311 sizeGroupBox->hide();
312 original->hide();
313 modify->hide();
314 ratioCheckBox->hide();
315 heightWidget->hide();
316 widthWidget->hide();
317 }
318}
319
320
321void G4OpenGLQtExportDialog::changeSizeBox()
322{
323 if (!original) return;
324 if (!heightWidget) return;
325 if (!widthWidget) return;
326 if (!ratioCheckBox) return;
327
328 if ( original->isChecked()) {
329 ratioCheckBox->hide();
330 heightWidget->hide();
331 widthWidget->hide();
332 } else {
333 heightWidget->show();
334 widthWidget->show();
335 ratioCheckBox->show();
336 }
337}
338
339
340void G4OpenGLQtExportDialog::textWidthChanged(
341 const QString & s
342 )
343{
344 if (!ratioCheckBox) return;
345 if (!width) return;
346 if (isChangingSize == true) return; // exclusive slot
347
348 if (ratioCheckBox->isChecked()){
349 isChangingSize = true;
350 QString tmp;
351 height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth))));
352 isChangingSize = false;
353 }
354}
355
356void G4OpenGLQtExportDialog:: textHeightChanged(
357 const QString & s
358)
359{
360 if (!ratioCheckBox) return;
361 if (!width) return;
362 if (isChangingSize == true) return; // exclusive slot
363
364 if (ratioCheckBox->isChecked()){
365 isChangingSize = true;
366 QString tmp;
367 width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
368 isChangingSize = false;
369 }
370}
371
372G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
373{
374}
375
376
377#endif
#define TRUE
Definition: globals.hh:55