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 0.1 2007/09/20 15:18:20 garnier $ |
---|
28 | // GEANT4 tag $Name: geant4-08-02-patch-01 $ |
---|
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 | |
---|
48 | G4OpenGLQtExportDialog::G4OpenGLQtExportDialog( |
---|
49 | QWidget* parent |
---|
50 | ,QString nomFich |
---|
51 | ,int aHeight |
---|
52 | ,int aWidth |
---|
53 | ) |
---|
54 | : QDialog( parent ) |
---|
55 | { |
---|
56 | setWindowTitle( tr( " Export options" )); |
---|
57 | originalWidth = aWidth; |
---|
58 | originalHeight = aHeight; |
---|
59 | |
---|
60 | // global layout |
---|
61 | QVBoxLayout* globalVLayout = new QVBoxLayout(); |
---|
62 | |
---|
63 | |
---|
64 | if (nomFich.endsWith(".jpg") || |
---|
65 | nomFich.endsWith(".jepg")) { |
---|
66 | |
---|
67 | QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality")); |
---|
68 | QVBoxLayout *imageGroupBoxLayout = new QVBoxLayout; |
---|
69 | |
---|
70 | QWidget *sliderBox = new QWidget; |
---|
71 | QHBoxLayout *hSlider = new QHBoxLayout; |
---|
72 | // qualityLabel = new QLabel( tr( "Image quality" ) ); |
---|
73 | // imageGroupBoxLayout->addWidget(qualityLabel); |
---|
74 | qualitySlider= new QSlider(Qt::Horizontal); |
---|
75 | qualitySlider->setMinimum(0); |
---|
76 | qualitySlider->setMaximum(100); |
---|
77 | qualitySlider->setTickPosition(QSlider::TicksBelow); |
---|
78 | qualitySlider->setValue(60); |
---|
79 | hSlider->addWidget(new QLabel("low")); |
---|
80 | hSlider->addWidget(qualitySlider); |
---|
81 | hSlider->addWidget(new QLabel("Maximum")); |
---|
82 | sliderBox->setLayout(hSlider); |
---|
83 | imageGroupBoxLayout->addWidget(sliderBox); |
---|
84 | |
---|
85 | imageGroupBox->setLayout(imageGroupBoxLayout); |
---|
86 | globalVLayout->addWidget(imageGroupBox); |
---|
87 | } |
---|
88 | |
---|
89 | if(nomFich.endsWith(".eps") || |
---|
90 | nomFich.endsWith(".jpg")) { |
---|
91 | QGroupBox *EPSGroupBox = new QGroupBox(tr("EPS options")); |
---|
92 | QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout; |
---|
93 | |
---|
94 | transparencyEPS = new QCheckBox( "transparencyEPS" ); |
---|
95 | transparencyEPS->setText( "save background" ); |
---|
96 | transparencyEPS->setChecked( true ); |
---|
97 | |
---|
98 | color = new QRadioButton("Color"); |
---|
99 | BW = new QRadioButton("Grayscale"); |
---|
100 | color->setChecked( true ); |
---|
101 | BW->setChecked( false ); |
---|
102 | |
---|
103 | |
---|
104 | EPSGroupBoxLayout->addWidget(transparencyEPS); |
---|
105 | EPSGroupBoxLayout->addWidget(color); |
---|
106 | EPSGroupBoxLayout->addWidget(BW); |
---|
107 | EPSGroupBox->setLayout(EPSGroupBoxLayout); |
---|
108 | globalVLayout->addWidget(EPSGroupBox); |
---|
109 | |
---|
110 | } |
---|
111 | |
---|
112 | if(nomFich.endsWith(".tif") || |
---|
113 | nomFich.endsWith(".tiff") || |
---|
114 | nomFich.endsWith(".jpg") || |
---|
115 | nomFich.endsWith(".png") || |
---|
116 | nomFich.endsWith(".xpm")) { |
---|
117 | |
---|
118 | QGroupBox *transparencyGroupBox = new QGroupBox(tr("Transparency")); |
---|
119 | QVBoxLayout *transparencyGroupBoxLayout = new QVBoxLayout; |
---|
120 | |
---|
121 | boxTransparency = new QCheckBox("Save transparency"); |
---|
122 | boxTransparency->setChecked( false ); |
---|
123 | // boxTransparency->setEnabled(false); |
---|
124 | |
---|
125 | transparencyGroupBoxLayout->addWidget(boxTransparency); |
---|
126 | transparencyGroupBox->setLayout(transparencyGroupBoxLayout); |
---|
127 | globalVLayout->addWidget(transparencyGroupBox); |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | // size box |
---|
132 | QGroupBox *sizeGroupBox = new QGroupBox(tr("Size")); |
---|
133 | QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout; |
---|
134 | |
---|
135 | QHBoxLayout *modifyAndRatioLayout = new QHBoxLayout; |
---|
136 | QWidget* modifyAndRatioWidget = new QWidget; |
---|
137 | |
---|
138 | // original button |
---|
139 | original = new QRadioButton("Original"); |
---|
140 | original->setChecked( true ); |
---|
141 | sizeGroupBoxLayout->addWidget(original); |
---|
142 | |
---|
143 | // modify and ratio |
---|
144 | modify = new QRadioButton("Modify"); |
---|
145 | modify->setChecked( false ); |
---|
146 | |
---|
147 | ratioCheckBox = new QCheckBox( "Keep ratio" ); |
---|
148 | ratioCheckBox->setChecked( true ); |
---|
149 | |
---|
150 | modifyAndRatioLayout->addWidget(modify); |
---|
151 | modifyAndRatioLayout->addWidget(ratioCheckBox); |
---|
152 | modifyAndRatioWidget->setLayout(modifyAndRatioLayout); |
---|
153 | sizeGroupBoxLayout->addWidget(modifyAndRatioWidget); |
---|
154 | ratioCheckBox->setVisible(modify->isChecked()); |
---|
155 | |
---|
156 | connect( original, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(true)) ); |
---|
157 | connect( modify, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(false) ) ); |
---|
158 | |
---|
159 | // height |
---|
160 | QHBoxLayout *heightLineLayout = new QHBoxLayout; |
---|
161 | heightWidget = new QWidget; |
---|
162 | QString tmp; |
---|
163 | |
---|
164 | heightLineLayout->addWidget(new QLabel("Height")); |
---|
165 | height = new QLineEdit(tmp.setNum(originalHeight)); |
---|
166 | height->setMaxLength(5); |
---|
167 | heightLineLayout->addWidget(height); |
---|
168 | heightWidget->setLayout(heightLineLayout); |
---|
169 | sizeGroupBoxLayout->addWidget(heightWidget); |
---|
170 | connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) ); |
---|
171 | |
---|
172 | |
---|
173 | // width |
---|
174 | QHBoxLayout *widthLineLayout = new QHBoxLayout; |
---|
175 | widthWidget = new QWidget; |
---|
176 | |
---|
177 | widthLineLayout->addWidget(new QLabel("Width ")); |
---|
178 | width = new QLineEdit(tmp.setNum(originalWidth)); |
---|
179 | width->setMaxLength(5); |
---|
180 | widthLineLayout->addWidget(width); |
---|
181 | widthWidget->setLayout(widthLineLayout); |
---|
182 | sizeGroupBoxLayout->addWidget(widthWidget); |
---|
183 | connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) ); |
---|
184 | |
---|
185 | sizeGroupBox->setLayout(sizeGroupBoxLayout); |
---|
186 | globalVLayout->addWidget(sizeGroupBox); |
---|
187 | |
---|
188 | heightWidget->setVisible(false); |
---|
189 | widthWidget->setVisible(false); |
---|
190 | |
---|
191 | // button ok/cancel box |
---|
192 | |
---|
193 | QGroupBox *buttonGroupBox = new QGroupBox(); |
---|
194 | QHBoxLayout *buttonGroupBoxLayout = new QHBoxLayout; |
---|
195 | |
---|
196 | buttonOk = new QPushButton( tr( "&OK" ) ); |
---|
197 | buttonOk->setAutoDefault( TRUE ); |
---|
198 | buttonOk->setDefault( TRUE ); |
---|
199 | buttonGroupBoxLayout->addWidget(buttonOk); |
---|
200 | |
---|
201 | buttonCancel = new QPushButton( tr( "&Cancel" ) ); |
---|
202 | buttonCancel->setAutoDefault( TRUE ); |
---|
203 | buttonGroupBoxLayout->addWidget(buttonCancel); |
---|
204 | |
---|
205 | buttonGroupBox->setLayout(buttonGroupBoxLayout); |
---|
206 | globalVLayout->addWidget(buttonGroupBox); |
---|
207 | |
---|
208 | |
---|
209 | setLayout(globalVLayout); |
---|
210 | |
---|
211 | // signals and slots connections |
---|
212 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
---|
213 | connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | int G4OpenGLQtExportDialog::getSliderValue() |
---|
219 | { |
---|
220 | return qualitySlider->value(); |
---|
221 | } |
---|
222 | |
---|
223 | int G4OpenGLQtExportDialog::getHeight() |
---|
224 | { |
---|
225 | return height->text().toInt(); |
---|
226 | } |
---|
227 | |
---|
228 | int G4OpenGLQtExportDialog::getWidth() |
---|
229 | { |
---|
230 | return width->text().toInt(); |
---|
231 | } |
---|
232 | |
---|
233 | int G4OpenGLQtExportDialog::getTransparency() |
---|
234 | { |
---|
235 | return boxTransparency->isChecked(); |
---|
236 | } |
---|
237 | |
---|
238 | int G4OpenGLQtExportDialog::getNbColor() |
---|
239 | { |
---|
240 | // Black and white |
---|
241 | if (!color->isChecked()) |
---|
242 | return 1; |
---|
243 | // rgb color with alpha |
---|
244 | if (color->isChecked() && transparencyEPS->isChecked()) |
---|
245 | return 4; |
---|
246 | // rgb color |
---|
247 | return 3; |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | void G4OpenGLQtExportDialog::changeSizeBox(bool aClick) |
---|
252 | { |
---|
253 | if (aClick) { |
---|
254 | modify->toggle(); |
---|
255 | } else { |
---|
256 | original->toggle(); |
---|
257 | } |
---|
258 | if ( original->isChecked()) { |
---|
259 | heightWidget->setVisible(false); |
---|
260 | widthWidget->setVisible(false); |
---|
261 | ratioCheckBox->setVisible(false); |
---|
262 | } else { |
---|
263 | heightWidget->setVisible(true); |
---|
264 | widthWidget->setVisible(true); |
---|
265 | ratioCheckBox->setVisible(true); |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | void G4OpenGLQtExportDialog::textWidthChanged( |
---|
270 | const QString & s |
---|
271 | ) |
---|
272 | { |
---|
273 | if (ratioCheckBox->isChecked()){ |
---|
274 | QString tmp; |
---|
275 | width->setText(tmp.setNum(s.toInt()*originalHeight/originalHeight)); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | void G4OpenGLQtExportDialog:: textHeightChanged( |
---|
280 | const QString & s |
---|
281 | ) |
---|
282 | { |
---|
283 | if (ratioCheckBox->isChecked()){ |
---|
284 | QString tmp; |
---|
285 | width->setText(tmp.setNum(s.toInt()*originalWidth/originalWidth)); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog() |
---|
290 | { |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | #endif |
---|