Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
28//
29
30#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
31
33
34#include <qvariant.h>
35#include <qpushbutton.h>
36#include <qcheckbox.h>
37#include <qlabel.h>
38#include <qcombobox.h>
39#include <qslider.h>
40#include <qlayout.h>
41#include <qgroupbox.h>
42#include <qradiobutton.h>
43#include <qimage.h>
44#include <qlineedit.h>
45#include <qbuttongroup.h>
46
47#ifndef G4GMAKE
48#include "moc_G4OpenGLQtExportDialog.cpp"
49#endif
50
51G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
52 QWidget* parentw
53,QString format
54 ,int aHeight
55 ,int aWidth
56)
57 : QDialog( parentw ),
58 isChangingSize(false)
59{
60 setWindowTitle( tr( " Export options" ));
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 QVBoxLayout* globalVLayout = new QVBoxLayout(this);
73 globalVLayout->setMargin(10);
74 globalVLayout->setSpacing(10);
75
76
77
78
79 // size box
80
81 QWidget * sizeWidget = new QWidget(this); // widget containing group button
82 QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
83 sizeWidgetLayout->setMargin (10);
84
85 // original and modify radiobuttons
86
87 sizeGroupBox = new QGroupBox(tr("Size"));
88 QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
89 QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
90 sizeGroupBoxLayout->setMargin (15);
91
92 original = new QRadioButton("Original");
93 modify = new QRadioButton("Modify");
94
95 sizeButtonGroupBox->addButton(original);
96 sizeButtonGroupBox->addButton(modify);
97 sizeButtonGroupBox->setExclusive(true);
98
99 sizeGroupBoxLayout->addWidget(original);
100 sizeGroupBoxLayout->addWidget(modify);
101
102 sizeGroupBox->setLayout(sizeGroupBoxLayout);
103 sizeWidgetLayout->addWidget(sizeGroupBox);
104
105 connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) );
106 original->setChecked( true );
107
108
109 // height
110 heightWidget = new QWidget(sizeWidget);
111
112 QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
113
114 QString tmp;
115
116 heightLineLayout->addWidget(new QLabel("Height",heightWidget));
117 height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
118 height->setMaxLength(5);
119 heightLineLayout->addWidget(height);
120
121 heightWidget->setLayout(heightLineLayout);
122
123 sizeWidgetLayout->addWidget(heightWidget);
124 connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
125
126
127 // width
128 widthWidget = new QWidget(sizeWidget);
129
130 QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
131
132 widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
133 width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
134 width->setMaxLength(5);
135 widthLineLayout->addWidget(width);
136 widthWidget->setLayout(widthLineLayout);
137 sizeWidgetLayout->addWidget(widthWidget);
138 connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
139
140
141
142 // ratio check box
143
144 ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
145 ratioCheckBox->setChecked( true );
146
147 sizeWidgetLayout->addWidget(ratioCheckBox);
148
149 ratioCheckBox->hide();
150 heightWidget->hide();
151 widthWidget->hide();
152
153 sizeWidget->setLayout(sizeWidgetLayout);
154 globalVLayout->addWidget(sizeWidget);
155
156 if (format == "eps") {
157
158 QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
159
160
161 QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
162 EPSGroupBoxLayout->setMargin (15);
163
164// colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
165// BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
166
167// QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
168// EPSColorButtonGroupBox->addButton(colorButton);
169// EPSColorButtonGroupBox->addButton(BWButton);
170// EPSColorButtonGroupBox->setExclusive(true);
171
172// EPSGroupBoxLayout->addWidget(colorButton);
173// EPSGroupBoxLayout->addWidget(BWButton);
174
175 vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
176 EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
177
178 EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
179 // colorButton->setChecked( true );
180 vectorEPSCheckBox->setChecked( true );
181
182 globalVLayout->addWidget(EPSWidgetGroupBox);
183 connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
184
185 }
186
187 if ((format == "jpg") ||
188 (format == "jpeg")) {
189
190 QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
191 QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
192 hSliderLayout->setMargin (15);
193
194 qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
195 qualitySlider->setMinimum(0);
196 qualitySlider->setMaximum(100);
197 qualitySlider->setTickPosition(QSlider::TicksBelow);
198 qualitySlider->setValue(60);
199 hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
200 hSliderLayout->addWidget(qualitySlider);
201 hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
202
203 imageGroupBox->setLayout(hSliderLayout);
204
205 globalVLayout->addWidget(imageGroupBox);
206 }
207
208
209 // button ok/cancel box
210
211 QWidget *buttonBox = new QWidget(this);
212
213 QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
214
215 buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
216 buttonOk->setAutoDefault( true );
217 buttonOk->setDefault( true );
218 buttonBoxLayout->addWidget(buttonOk);
219
220 buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
221 buttonCancel->setAutoDefault( true );
222 buttonBoxLayout->addWidget(buttonCancel);
223
224 buttonBox->setLayout(buttonBoxLayout);
225 globalVLayout->addWidget(buttonBox);
226
227
228
229 setLayout(globalVLayout);
230
231 // signals and slots connections
232 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
233 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
234}
235
236
237
238int G4OpenGLQtExportDialog::getSliderValue()
239{
240 if (!qualitySlider) return -1;
241 return qualitySlider->value();
242}
243
244int G4OpenGLQtExportDialog::getHeight()
245{
246 if (!height) return originalHeight;
247 return height->text().toInt();
248}
249
250int G4OpenGLQtExportDialog::getWidth()
251{
252 if (!width) return originalWidth;
253 return width->text().toInt();
254}
255
256bool G4OpenGLQtExportDialog::getVectorEPS()
257{
258 if (!vectorEPSCheckBox) return 0;
259 return vectorEPSCheckBox->isChecked();
260}
261
262
263void G4OpenGLQtExportDialog::changeVectorEPS()
264{
265 if (!vectorEPSCheckBox) return;
266 if (vectorEPSCheckBox->isChecked()) {
267 sizeGroupBox->show();
268 original->show();
269 modify->show();
270 changeSizeBox();
271 } else {
272 sizeGroupBox->hide();
273 original->hide();
274 modify->hide();
275 ratioCheckBox->hide();
276 heightWidget->hide();
277 widthWidget->hide();
278 }
279}
280
281
282void G4OpenGLQtExportDialog::changeSizeBox()
283{
284 if (!original) return;
285 if (!heightWidget) return;
286 if (!widthWidget) return;
287 if (!ratioCheckBox) return;
288
289 if ( original->isChecked()) {
290 ratioCheckBox->hide();
291 heightWidget->hide();
292 widthWidget->hide();
293 } else {
294 heightWidget->show();
295 widthWidget->show();
296 ratioCheckBox->show();
297 }
298}
299
300
301void G4OpenGLQtExportDialog::textWidthChanged(
302 const QString & s
303 )
304{
305 if (!ratioCheckBox) return;
306 if (!width) return;
307 if (isChangingSize == true) return; // exclusive slot
308
309 if (ratioCheckBox->isChecked()){
310 isChangingSize = true;
311 QString tmp;
312 height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth))));
313 isChangingSize = false;
314 }
315}
316
317void G4OpenGLQtExportDialog:: textHeightChanged(
318 const QString & s
319)
320{
321 if (!ratioCheckBox) return;
322 if (!width) return;
323 if (isChangingSize == true) return; // exclusive slot
324
325 if (ratioCheckBox->isChecked()){
326 isChangingSize = true;
327 QString tmp;
328 width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
329 isChangingSize = false;
330 }
331}
332
333G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
334{
335}
336
337
338#endif