Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4OpenGLQtExportDialog.cc 82764 2014-07-08 14:24:04Z gcosmo $
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 
48 G4OpenGLQtExportDialog::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 
76  // size box
77 
78  QWidget * sizeWidget = new QWidget(this); // widget containing group button
79  QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
80  sizeWidgetLayout->setMargin (10);
81 
82  // original and modify radiobuttons
83 
84  sizeGroupBox = new QGroupBox(tr("Size"));
85  QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
86  QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
87  sizeGroupBoxLayout->setMargin (15);
88 
89  original = new QRadioButton("Original");
90  modify = new QRadioButton("Modify");
91 
92  sizeButtonGroupBox->addButton(original);
93  sizeButtonGroupBox->addButton(modify);
94  sizeButtonGroupBox->setExclusive(true);
95 
96  sizeGroupBoxLayout->addWidget(original);
97  sizeGroupBoxLayout->addWidget(modify);
98 
99  sizeGroupBox->setLayout(sizeGroupBoxLayout);
100  sizeWidgetLayout->addWidget(sizeGroupBox);
101 
102  connect( sizeButtonGroupBox, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( changeSizeBox()) );
103  original->setChecked( true );
104 
105 
106  // height
107  heightWidget = new QWidget(sizeWidget);
108 
109  QHBoxLayout *heightLineLayout = new QHBoxLayout(heightWidget);
110 
111  QString tmp;
112 
113  heightLineLayout->addWidget(new QLabel("Height",heightWidget));
114  height = new QLineEdit(tmp.setNum(originalHeight),heightWidget);
115  height->setMaxLength(5);
116  heightLineLayout->addWidget(height);
117 
118  heightWidget->setLayout(heightLineLayout);
119 
120  sizeWidgetLayout->addWidget(heightWidget);
121  connect( height, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textHeightChanged(const QString &) ) );
122 
123 
124  // width
125  widthWidget = new QWidget(sizeWidget);
126 
127  QHBoxLayout *widthLineLayout = new QHBoxLayout(widthWidget);
128 
129  widthLineLayout->addWidget(new QLabel("Width ",widthWidget));
130  width = new QLineEdit(tmp.setNum(originalWidth),widthWidget);
131  width->setMaxLength(5);
132  widthLineLayout->addWidget(width);
133  widthWidget->setLayout(widthLineLayout);
134  sizeWidgetLayout->addWidget(widthWidget);
135  connect( width, SIGNAL( textChanged ( const QString& ) ), this, SLOT( textWidthChanged(const QString &) ) );
136 
137 
138 
139  // ratio check box
140 
141  ratioCheckBox = new QCheckBox( "Keep ratio",sizeWidget);
142  ratioCheckBox->setChecked( true );
143 
144  sizeWidgetLayout->addWidget(ratioCheckBox);
145 
146  ratioCheckBox->hide();
147  heightWidget->hide();
148  widthWidget->hide();
149 
150  sizeWidget->setLayout(sizeWidgetLayout);
151  globalVLayout->addWidget(sizeWidget);
152 
153  if (format == "eps") {
154 
155  QGroupBox *EPSWidgetGroupBox = new QGroupBox(tr("EPS options"),this); // widget containing group button
156 
157 
158  QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
159  EPSGroupBoxLayout->setMargin (15);
160 
161 // colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
162 // BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
163 
164 // QButtonGroup * EPSColorButtonGroupBox = new QButtonGroup();
165 // EPSColorButtonGroupBox->addButton(colorButton);
166 // EPSColorButtonGroupBox->addButton(BWButton);
167 // EPSColorButtonGroupBox->setExclusive(true);
168 
169 // EPSGroupBoxLayout->addWidget(colorButton);
170 // EPSGroupBoxLayout->addWidget(BWButton);
171 
172  vectorEPSCheckBox = new QCheckBox( "Vector EPS File",EPSWidgetGroupBox);
173  EPSGroupBoxLayout->addWidget(vectorEPSCheckBox);
174 
175  EPSWidgetGroupBox->setLayout(EPSGroupBoxLayout);
176  // colorButton->setChecked( true );
177  vectorEPSCheckBox->setChecked( true );
178 
179  globalVLayout->addWidget(EPSWidgetGroupBox);
180  connect( vectorEPSCheckBox, SIGNAL( clicked() ), this, SLOT( changeVectorEPS()) );
181 
182  }
183 
184  if ((format == "jpg") ||
185  (format == "jpeg")) {
186 
187  QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
188  QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
189  hSliderLayout->setMargin (15);
190 
191  qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
192  qualitySlider->setMinimum(0);
193  qualitySlider->setMaximum(100);
194  qualitySlider->setTickPosition(QSlider::TicksBelow);
195  qualitySlider->setValue(60);
196  hSliderLayout->addWidget(new QLabel("Low ",imageGroupBox));
197  hSliderLayout->addWidget(qualitySlider);
198  hSliderLayout->addWidget(new QLabel(" Maximum",imageGroupBox));
199 
200  imageGroupBox->setLayout(hSliderLayout);
201 
202  globalVLayout->addWidget(imageGroupBox);
203  }
204 
205 
206  // button ok/cancel box
207 
208  QWidget *buttonBox = new QWidget(this);
209 
210  QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
211 
212  buttonOk = new QPushButton( tr( "&OK" ),buttonBox );
213  buttonOk->setAutoDefault( true );
214  buttonOk->setDefault( true );
215  buttonBoxLayout->addWidget(buttonOk);
216 
217  buttonCancel = new QPushButton( tr( "&Cancel" ),buttonBox );
218  buttonCancel->setAutoDefault( true );
219  buttonBoxLayout->addWidget(buttonCancel);
220 
221  buttonBox->setLayout(buttonBoxLayout);
222  globalVLayout->addWidget(buttonBox);
223 
224 
225 
226  setLayout(globalVLayout);
227 
228  // signals and slots connections
229  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
230  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
231 }
232 
233 
234 
235 int G4OpenGLQtExportDialog::getSliderValue()
236 {
237  if (!qualitySlider) return -1;
238  return qualitySlider->value();
239 }
240 
241 int G4OpenGLQtExportDialog::getHeight()
242 {
243  if (!height) return originalHeight;
244  return height->text().toInt();
245 }
246 
248 {
249  if (!width) return originalWidth;
250  return width->text().toInt();
251 }
252 
253 bool G4OpenGLQtExportDialog::getVectorEPS()
254 {
255  if (!vectorEPSCheckBox) return 0;
256  return vectorEPSCheckBox->isChecked();
257 }
258 
259 
260 void G4OpenGLQtExportDialog::changeVectorEPS()
261 {
262  if (!vectorEPSCheckBox) return;
263  if (vectorEPSCheckBox->isChecked()) {
264  sizeGroupBox->show();
265  original->show();
266  modify->show();
267  changeSizeBox();
268  } else {
269  sizeGroupBox->hide();
270  original->hide();
271  modify->hide();
272  ratioCheckBox->hide();
273  heightWidget->hide();
274  widthWidget->hide();
275  }
276 }
277 
278 
279 void G4OpenGLQtExportDialog::changeSizeBox()
280 {
281  if (!original) return;
282  if (!heightWidget) return;
283  if (!widthWidget) return;
284  if (!ratioCheckBox) return;
285 
286  if ( original->isChecked()) {
287  ratioCheckBox->hide();
288  heightWidget->hide();
289  widthWidget->hide();
290  } else {
291  heightWidget->show();
292  widthWidget->show();
293  ratioCheckBox->show();
294  }
295 }
296 
297 
298 void G4OpenGLQtExportDialog::textWidthChanged(
299  const QString & s
300  )
301 {
302  if (!ratioCheckBox) return;
303  if (!width) return;
304  if (isChangingSize == true) return; // exclusive slot
305 
306  if (ratioCheckBox->isChecked()){
307  isChangingSize = true;
308  QString tmp;
309  height->setText(tmp.setNum((int)(s.toInt()*(double)((double)originalHeight/(double)originalWidth))));
310  isChangingSize = false;
311  }
312 }
313 
314 void G4OpenGLQtExportDialog:: textHeightChanged(
315  const QString & s
316 )
317 {
318  if (!ratioCheckBox) return;
319  if (!width) return;
320  if (isChangingSize == true) return; // exclusive slot
321 
322  if (ratioCheckBox->isChecked()){
323  isChangingSize = true;
324  QString tmp;
325  width->setText(tmp.setNum(s.toInt()*originalWidth/originalHeight));
326  isChangingSize = false;
327  }
328 }
329 
330 G4OpenGLQtExportDialog::~G4OpenGLQtExportDialog()
331 {
332 }
333 
334 
335 #endif
G4double getWidth(const ParticleType t)
Get particle width (in s)
Float_t tmp
const XML_Char * s
Definition: expat.h:262
#define width