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