source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc@ 606

Last change on this file since 606 was 606, checked in by garnier, 18 years ago

r647@mac-90108: laurentgarnier | 2007-11-15 11:32:46 +0100
Ok en Qt 4.3.0

  • Property svn:mime-type set to text/cpp
File size: 42.2 KB
Line 
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: G4OpenGLQtViewer.cc,v 1.6 2007/11/14 11:49:00 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// G4OpenGLQtViewer : Class to provide Qt specific
32// functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
37
38#include "G4OpenGLQtViewer.hh"
39
40#include "G4ios.hh"
41#include "G4VisExtent.hh"
42#include "G4LogicalVolume.hh"
43#include "G4VSolid.hh"
44#include "G4Point3D.hh"
45#include "G4Normal3D.hh"
46#include "G4Scene.hh"
47#include "G4OpenGLQtExportDialog.hh"
48
49#include "G4Qt.hh"
50#include "G4UIsession.hh"
51#include "G4UImanager.hh"
52#include <qapplication.h>
53#include <qlayout.h>
54#include <qdialog.h>
55
56#if QT_VERSION >= 0x040000
57#include <qmenu.h>
58#include <qimagewriter.h>
59#else
60#include <qaction.h>
61#include <qwidgetlist.h>
62#include <qpopupmenu.h>
63#include <qimage.h>
64#endif
65
66#include <qmessagebox.h>
67#include <qfiledialog.h>
68#include <qprinter.h>
69#include <qpainter.h>
70#include <qgl.h> // include <qglwidget.h>
71#include <qdialog.h>
72#include <qevent.h> //include <qcontextmenuevent.h>
73
74
75//////////////////////////////////////////////////////////////////////////////
76/**
77 Implementation of virtual method of G4VViewer
78*/
79void G4OpenGLQtViewer::SetView (
80)
81//////////////////////////////////////////////////////////////////////////////
82//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
83{
84 printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
85 // if(!fHDC) return;
86 // if(!fHGLRC) return;
87 // ::wglMakeCurrent(fHDC,fHGLRC);
88 // fWindow->makeCurrent();
89 G4OpenGLViewer::SetView ();
90 printf("G4OpenGLQtViewer::SetView --------------------\n");
91}
92
93
94
95//////////////////////////////////////////////////////////////////////////////
96/**
97 Implementation of virtual method of G4VViewer
98*/
99void G4OpenGLQtViewer::ShowView (
100)
101//////////////////////////////////////////////////////////////////////////////
102//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
103{
104 printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n");
105 glFlush ();
106 if (!GLWindow) {
107 G4cerr << "Visualization window not defined, please choose one before" << G4endl;
108 } else {
109#if QT_VERSION < 0x040000
110 GLWindow->setActiveWindow();
111#else
112 GLWindow->activateWindow();
113#endif
114 printf("G4OpenGLQtViewer::ShowView -----------------------\n");
115 }
116 // // Empty the Windows message queue :
117 // MSG event;
118 // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
119 // ::TranslateMessage(&event);
120 // ::DispatchMessage (&event);
121 // }
122}
123
124
125
126//////////////////////////////////////////////////////////////////////////////
127void G4OpenGLQtViewer::CreateGLQtContext (
128)
129//////////////////////////////////////////////////////////////////////////////
130//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
131{
132 printf("G4OpenGLQtViewer::CreateGLQtContext \n");
133}
134
135
136//////////////////////////////////////////////////////////////////////////////
137void G4OpenGLQtViewer::CreateMainWindow (
138 QGLWidget* glWidget
139)
140//////////////////////////////////////////////////////////////////////////////
141//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
142{
143
144 if(fWindow) return; //Done.
145 printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
146
147 // launch Qt if not
148 G4Qt* interactorManager = G4Qt::getInstance ();
149 // G4UImanager* UI = G4UImanager::GetUIpointer();
150
151 fWindow = glWidget ;
152 // fWindow->makeCurrent();
153
154 // create window
155 if (((QApplication*)interactorManager->GetMainInteractor())) {
156 // look for the main window
157 bool found = false;
158#if QT_VERSION < 0x040000
159 QWidgetList *list = QApplication::allWidgets();
160 QWidgetListIt it( *list ); // iterate over the widgets
161 QWidget * widget;
162 while ( (widget=it.current()) != 0 ) { // for each widget...
163 ++it;
164 if ((found== false) && (widget->inherits("QMainWindow"))) {
165 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
166 GLWindow = new QDialog(widget,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
167 found = true;
168 }
169 }
170 delete list; // delete the list, not the widgets
171#else
172 foreach (QWidget *widget, QApplication::allWidgets()) {
173 if ((found== false) && (widget->inherits("QMainWindow"))) {
174 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
175 GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
176 found = true;
177 }
178 }
179#endif
180
181 if (found==false) {
182 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
183 GLWindow = new QDialog();
184 }
185 } else {
186 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
187 GLWindow = new QDialog();
188 }
189
190#if QT_VERSION < 0x040000
191 QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
192#else
193 QHBoxLayout *mainLayout = new QHBoxLayout;
194#endif
195
196 mainLayout->addWidget(fWindow);
197
198#if QT_VERSION < 0x040000
199 GLWindow->setCaption( tr( "QGl Viewer" ));
200#else
201 GLWindow->setLayout(mainLayout);
202 GLWindow->setWindowTitle(tr("QGl Viewer"));
203#endif
204 GLWindow->resize(300, 300);
205 GLWindow->move(900,300);
206 GLWindow->show();
207
208 // delete the pointer if close this
209 // GLWindow->setAttribute(Qt::WA_DeleteOnClose);
210
211 QObject ::connect(GLWindow,
212 SIGNAL(rejected()),
213 this,
214 SLOT(dialogClosed()));
215
216 WinSize_x = 400;
217 WinSize_y = 400;
218 if (WinSize_x < fVP.GetWindowSizeHintX ())
219 WinSize_x = fVP.GetWindowSizeHintX ();
220 if (WinSize_y < fVP.GetWindowSizeHintY ())
221 WinSize_y = fVP.GetWindowSizeHintY ();
222
223 if(!fWindow) return;
224 printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
225
226 if (!fContextMenu)
227 createPopupMenu();
228
229}
230
231/** Close the dialog and set the pointer to NULL
232 */
233void G4OpenGLQtViewer::dialogClosed() {
234 GLWindow = NULL;
235}
236
237
238//////////////////////////////////////////////////////////////////////////////
239G4OpenGLQtViewer::G4OpenGLQtViewer (
240 G4OpenGLSceneHandler& scene
241 )
242 :G4VViewer (scene, -1)
243 ,G4OpenGLViewer (scene)
244 ,fWindow(0)
245 ,fContextMenu(0)
246 ,fMouseAction(true)
247{
248 printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
249}
250
251//////////////////////////////////////////////////////////////////////////////
252G4OpenGLQtViewer::~G4OpenGLQtViewer (
253)
254//////////////////////////////////////////////////////////////////////////////
255//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
256{
257 printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
258 delete fContextMenu;
259}
260
261
262/**
263 Create a popup menu for the widget. This menu is activated by right-mouse click
264*/
265void G4OpenGLQtViewer::createPopupMenu() {
266
267#if QT_VERSION < 0x040000
268 fContextMenu = new QPopupMenu( GLWindow,"All" );
269#else
270 fContextMenu = new QMenu("All");
271#endif
272 Q_CHECK_PTR( fContextMenu );
273
274#if QT_VERSION < 0x040000
275 // === Mouse menu ===
276 QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
277 Q_CHECK_PTR( mMouseAction );
278
279 QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction);
280 QAction *move = new QAction("&Move scene",CTRL+Key_M,mMouseAction);
281 rotate->addTo(mMouseAction);
282 move->addTo(mMouseAction);
283
284 fContextMenu->insertItem( "&Mouse action", mMouseAction);
285
286#else
287 // === Mouse menu ===
288 QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
289
290 QAction *rotate = mMouseAction->addAction("&Rotate scene");
291 QAction *move = mMouseAction->addAction("&Move scene");
292#endif
293
294 // INIT mMouse
295 createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
296
297#if QT_VERSION < 0x040000
298 // === Style Menu ===
299 QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
300
301 QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
302
303 QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
304 QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
305 polyhedron->addTo(mRepresentation);
306 nurbs->addTo(mRepresentation);
307
308 mStyle->insertItem("&Representation",mRepresentation);
309 fContextMenu->insertItem("&Style",mStyle);
310
311#else
312 // === Style Menu ===
313 QMenu *mStyle = fContextMenu->addMenu("&Style");
314
315 QMenu *mRepresentation = mStyle->addMenu("&Representation");
316 QAction *polyhedron = mRepresentation->addAction("Polyhedron");
317 QAction *nurbs = mRepresentation->addAction("NURBS");
318#endif
319 // INIT mStyle
320 G4ViewParameters::RepStyle style;
321 style = fVP.GetRepStyle();
322 if (style == G4ViewParameters::polyhedron) {
323 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
324 } else if (style == G4ViewParameters::nurbs) {
325 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
326 } else {
327 mRepresentation->clear();
328 }
329
330
331#if QT_VERSION < 0x040000
332 // === Drawing Menu ===
333 QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
334 fContextMenu->insertItem("&Drawing",mDrawing);
335
336 fDrawingWireframe = new QPopupMenu(mDrawing);
337 mDrawing->insertItem("&Wireframe",fDrawingWireframe);
338
339 mDrawing->setCheckable(true);
340 fDrawingWireframe->setCheckable(true);
341
342 fDrawingLineRemoval = new QPopupMenu(mDrawing);
343 mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
344 fDrawingLineRemoval->setCheckable(true);
345
346 fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
347 mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
348 fDrawingSurfaceRemoval->setCheckable(true);
349
350 fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
351 mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
352 fDrawingLineSurfaceRemoval->setCheckable(true);
353
354#else
355 // === Drawing Menu ===
356 QMenu *mDrawing = mStyle->addMenu("&Drawing");
357
358 fDrawingWireframe = mDrawing->addAction("Wireframe");
359 fDrawingWireframe->setCheckable(true);
360
361 fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
362 fDrawingLineRemoval->setCheckable(true);
363
364 fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
365 fDrawingSurfaceRemoval->setCheckable(true);
366
367 fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
368 fDrawingLineSurfaceRemoval->setCheckable(true);
369#endif
370 // INIT Drawing
371 G4ViewParameters::DrawingStyle d_style;
372 d_style = fVP.GetDrawingStyle();
373
374#if QT_VERSION < 0x040000
375 if (d_style == G4ViewParameters::wireframe) {
376 fDrawingWireframe->setItemChecked(0,true);
377 } else if (d_style == G4ViewParameters::hlr) {
378 fDrawingLineRemoval->setItemChecked(0,true);
379 } else if (d_style == G4ViewParameters::hsr) {
380 fDrawingSurfaceRemoval->setItemChecked(0,true);
381 } else if (d_style == G4ViewParameters::hlhsr) {
382 fDrawingLineSurfaceRemoval->setItemChecked(0,true);
383 } else {
384 mDrawing->clear();
385 }
386#else
387 if (d_style == G4ViewParameters::wireframe) {
388 fDrawingWireframe->setChecked(true);
389 } else if (d_style == G4ViewParameters::hlr) {
390 fDrawingLineRemoval->setChecked(true);
391 } else if (d_style == G4ViewParameters::hsr) {
392 fDrawingSurfaceRemoval->setChecked(true);
393 } else if (d_style == G4ViewParameters::hlhsr) {
394 fDrawingLineSurfaceRemoval->setChecked(true);
395 } else {
396 mDrawing->clear();
397 }
398#endif
399
400 QObject ::connect(fDrawingWireframe,
401 SIGNAL(triggered(bool)),
402 this,
403 SLOT(actionDrawingWireframe()));
404 QObject ::connect(fDrawingLineRemoval,
405 SIGNAL(triggered(bool)),
406 this,
407 SLOT(actionDrawingLineRemoval()));
408 QObject ::connect(fDrawingSurfaceRemoval,
409 SIGNAL(triggered(bool)),
410 this,
411 SLOT(actionDrawingSurfaceRemoval()));
412 QObject ::connect(fDrawingLineSurfaceRemoval,
413 SIGNAL(triggered(bool)),
414 this,
415 SLOT(actionDrawingLineSurfaceRemoval()));
416
417
418#if QT_VERSION < 0x040000
419 QPopupMenu *mBackground = new QPopupMenu(mStyle);
420 mStyle->insertItem("&Background color",mBackground);
421
422 QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
423 QAction *black = new QAction("&Black",CTRL+Key_B,mBackground);
424 white->addTo(mBackground);
425 black->addTo(mBackground);
426
427#else
428 QMenu *mBackground = mStyle->addMenu("&Background color");
429 QAction *white = mBackground->addAction("White");
430 QAction *black = mBackground->addAction("Black");
431
432#endif
433 if (background.GetRed() == 1. &&
434 background.GetGreen() == 1. &&
435 background.GetBlue() == 1.) {
436 createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
437 } else {
438 createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
439 }
440
441
442#if QT_VERSION < 0x040000
443 // === Action Menu ===
444 QPopupMenu *mActions = new QPopupMenu(fContextMenu);
445 fContextMenu->insertItem("&Actions",mActions);
446
447 QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
448 QAction *exitG4 = new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
449 QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions);
450 controlPanels->addTo(mActions);
451 exitG4->addTo(mActions);
452 createEPS->addTo(mActions);
453
454#else
455 // === Action Menu ===
456 QMenu *mActions = fContextMenu->addMenu("&Actions");
457 QAction *controlPanels = mActions->addAction("Control panels");
458 QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
459 QAction *createEPS = mActions->addAction("Save as ...");
460#endif
461
462 QObject ::connect(controlPanels,
463 SIGNAL(triggered()),
464 this,
465 SLOT(actionControlPanels()));
466 QObject ::connect(exitG4,
467 SIGNAL(triggered()),
468 this,
469 SLOT(actionExitG4()));
470 QObject ::connect(createEPS,
471 SIGNAL(triggered()),
472 this,
473 SLOT(actionCreateEPS()));
474
475
476#if QT_VERSION < 0x040000
477 // === Special Menu ===
478 QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
479 fContextMenu->insertItem("S&pecial",mSpecial);
480
481 QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
482 mSpecial->insertItem("Transparency",mTransparency);
483
484 QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
485 QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
486 transparencyOn->addTo(mTransparency);
487 transparencyOff->addTo(mTransparency);
488
489#else
490 // === Special Menu ===
491 QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
492 QMenu *mTransparency = mSpecial->addMenu("Transparency");
493 QAction *transparencyOn = mTransparency->addAction("On");
494 QAction *transparencyOff = mTransparency->addAction("Off");
495#endif
496
497 if (transparency_enabled == false) {
498 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
499 } else if (transparency_enabled == true) {
500 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
501 } else {
502 mSpecial->clear();
503 }
504
505
506#if QT_VERSION < 0x040000
507 QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
508 mSpecial->insertItem("Antialiasing",mAntialiasing);
509
510 QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
511 QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
512 antialiasingOn->addTo(mAntialiasing);
513 antialiasingOff->addTo(mAntialiasing);
514
515#else
516 QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
517 QAction *antialiasingOn = mAntialiasing->addAction("On");
518 QAction *antialiasingOff = mAntialiasing->addAction("Off");
519#endif
520
521 if (antialiasing_enabled == false) {
522 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
523 } else if (antialiasing_enabled == true) {
524 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
525 } else {
526 mAntialiasing->clear();
527 }
528
529#if QT_VERSION < 0x040000
530 QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
531 mSpecial->insertItem("Haloing",mHaloing);
532
533 QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
534 QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
535 haloingOn->addTo(mHaloing);
536 haloingOff->addTo(mHaloing);
537#else
538 QMenu *mHaloing = mSpecial->addMenu("Haloing");
539 QAction *haloingOn = mHaloing->addAction("On");
540 QAction *haloingOff = mHaloing->addAction("Off");
541#endif
542 if (haloing_enabled == false) {
543 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
544 } else if (haloing_enabled == true) {
545 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
546 } else {
547 mHaloing->clear();
548 }
549
550#if QT_VERSION < 0x040000
551 QPopupMenu *mAux = new QPopupMenu(mSpecial);
552 mSpecial->insertItem("Auxiliairy edges",mAux);
553
554 QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
555 QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
556 auxOn->addTo(mAux);
557 auxOff->addTo(mAux);
558
559#else
560 QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
561 QAction *auxOn = mAux->addAction("On");
562 QAction *auxOff = mAux->addAction("Off");
563#endif
564 if (!fVP.IsAuxEdgeVisible()) {
565 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
566 } else {
567 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
568 }
569
570
571#if QT_VERSION < 0x040000
572 QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
573 mSpecial->insertItem("Full screen",mFullScreen);
574
575 QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
576 QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
577 fullOn->addTo(mFullScreen);
578 fullOff->addTo(mFullScreen);
579#else
580 QMenu *mFullScreen = mSpecial->addMenu("Full screen");
581 QAction *fullOn = mFullScreen->addAction("On");
582 QAction *fullOff = mFullScreen->addAction("Off");
583#endif
584 createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
585
586}
587
588void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
589{
590 if (!GLWindow) {
591 G4cerr << "Visualization window not defined, please choose one before" << G4endl;
592 } else {
593
594 if (!fContextMenu)
595 createPopupMenu();
596
597 // launch menu
598 if ( fContextMenu ) {
599 fContextMenu->exec( e->globalPos() );
600 // delete fContextMenu;
601 }
602 }
603 e->accept();
604}
605
606
607/**
608 Create a radio button menu. The two menu will be connected. When click on one,
609 eatch state will be invert and callback method will be called.
610 @param action1 first action to connect
611 @param action2 second action to connect
612 @param method callback method
613 @param nCheck: 1 : first action will be set true. 2 : second action will be set true
614*/
615#if QT_VERSION < 0x040000
616void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
617
618 if (action1->parent()->inherits("QPopupMenu")){
619 ((QPopupMenu*)action1->parent())->setCheckable(true);
620 }
621 ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
622 ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
623
624 if (nCheck ==1)
625 ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
626 else
627 ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
628
629 QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
630 QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
631
632 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
633}
634
635#else
636void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
637
638 action1->setCheckable(true);
639 action2->setCheckable(true);
640
641 if (nCheck ==1)
642 action1->setChecked (true);
643 else
644 action2->setChecked (true);
645
646 QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
647 QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
648
649 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
650
651}
652#endif
653
654/**
655 Slot activate when drawing->wireframe menu is set
656 */
657void G4OpenGLQtViewer::actionDrawingWireframe() {
658 emit toggleDrawingAction(1);
659}
660
661/**
662 Slot activate when drawing->line removal menu is set
663 */
664void G4OpenGLQtViewer::actionDrawingLineRemoval() {
665 emit toggleDrawingAction(2);
666}
667
668/**
669 Slot activate when drawing->surface removal menu is set
670 */
671void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
672 emit toggleDrawingAction(3);
673}
674
675/**
676 Slot activate when drawing->wireframe menu is set
677 */
678void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
679 emit toggleDrawingAction(4);
680}
681
682
683/**
684 Slot activated when drawing menu is toggle
685 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
686 KernelVisitDecision () will be call and will set the fNeedKernelVisit
687 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
688 It will cause a redraw of the view
689 @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
690 @see G4OpenGLStoredQtViewer::DrawView
691 @see G4XXXStoredViewer::CompareForKernelVisit
692 */
693void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
694
695 G4ViewParameters::DrawingStyle d_style;
696
697
698 if (aAction ==1) {
699#if QT_VERSION < 0x040000
700 fDrawingWireframe->setItemChecked (0,true);
701 fDrawingLineRemoval->setItemChecked (0,false);
702 fDrawingSurfaceRemoval->setItemChecked (0,false);
703 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
704#else
705 fDrawingWireframe->setChecked (true);
706 fDrawingLineRemoval->setChecked (false);
707 fDrawingSurfaceRemoval->setChecked (false);
708 fDrawingLineSurfaceRemoval->setChecked (false);
709#endif
710
711 d_style = G4ViewParameters::wireframe;
712
713 } else if (aAction ==2) {
714#if QT_VERSION < 0x040000
715 fDrawingWireframe->setItemChecked (0,false);
716 fDrawingLineRemoval->setItemChecked (0,true);
717 fDrawingSurfaceRemoval->setItemChecked (0,false);
718 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
719#else
720 fDrawingWireframe->setChecked (false);
721 fDrawingLineRemoval->setChecked (true);
722 fDrawingSurfaceRemoval->setChecked (false);
723 fDrawingLineSurfaceRemoval->setChecked (false);
724#endif
725
726 d_style = G4ViewParameters::hlr;
727
728 } else if (aAction ==3) {
729#if QT_VERSION < 0x040000
730 fDrawingWireframe->setItemChecked (0,false);
731 fDrawingLineRemoval->setItemChecked (0,false);
732 fDrawingSurfaceRemoval->setItemChecked (0,true);
733 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
734#else
735 fDrawingWireframe->setChecked (false);
736 fDrawingLineRemoval->setChecked (false);
737 fDrawingSurfaceRemoval->setChecked (true);
738 fDrawingLineSurfaceRemoval->setChecked (false);
739#endif
740
741 d_style = G4ViewParameters::hsr;
742
743 } else if (aAction ==4) {
744#if QT_VERSION < 0x040000
745 fDrawingWireframe->setItemChecked (0,false);
746 fDrawingLineRemoval->setItemChecked (0,false);
747 fDrawingSurfaceRemoval->setItemChecked (0,false);
748 fDrawingLineSurfaceRemoval->setItemChecked (0,true);
749#else
750 fDrawingWireframe->setChecked (false);
751 fDrawingLineRemoval->setChecked (false);
752 fDrawingSurfaceRemoval->setChecked (false);
753 fDrawingLineSurfaceRemoval->setChecked (true);
754#endif
755 d_style = G4ViewParameters::hlhsr;
756 }
757 fVP.SetDrawingStyle(d_style);
758
759 updateQWidget();
760 printf("G4OpenGLQtViewer::toggleDrawingAction\n");
761}
762
763
764/**
765 SLOT Activate by a click on the representation menu
766 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
767 KernelVisitDecision () will be call and will set the fNeedKernelVisit
768 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
769 It will cause a redraw of the view
770 @param check : 1 polyhedron, 0 nurbs
771 @see G4OpenGLStoredQtViewer::DrawView
772 @see G4XXXStoredViewer::CompareForKernelVisit
773*/
774void G4OpenGLQtViewer::toggleRepresentation(bool check) {
775
776 G4ViewParameters::RepStyle style;
777 if (check == 1) {
778 style = G4ViewParameters::polyhedron;
779 } else {
780 style = G4ViewParameters::nurbs;
781 }
782 fVP.SetRepStyle (style);
783
784 printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
785 updateQWidget();
786 printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
787}
788
789/**
790 SLOT Activate by a click on the background menu
791@param check : 1 white, 0 black
792*/
793void G4OpenGLQtViewer::toggleBackground(bool check) {
794
795 // //I need to revisit the kernel if the background colour changes and
796 // //hidden line removal is enabled, because hlr drawing utilises the
797 // //background colour in its drawing...
798 // // (Note added by JA 13/9/2005) Background now handled in view
799 // // parameters. A kernel visit is triggered on change of background.
800 if (check == 1) {
801 ((G4ViewParameters&)this->GetViewParameters()).
802 SetBackgroundColour(G4Colour(1.,1.,1.)); // White
803 } else {
804 ((G4ViewParameters&)this->GetViewParameters()).
805 SetBackgroundColour(G4Colour(0.,0.,0.)); // Black
806 }
807 updateQWidget();
808}
809
810/**
811 SLOT Activate by a click on the transparency menu
812@param check : 1 , 0
813*/
814void G4OpenGLQtViewer::toggleTransparency(bool check) {
815
816 if (check) {
817 transparency_enabled = false;
818 } else {
819 transparency_enabled = true;
820 }
821 SetNeedKernelVisit (true);
822 updateQWidget();
823}
824
825/**
826 SLOT Activate by a click on the antialiasing menu
827@param check : 1 , 0
828*/
829void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
830
831 if (!check) {
832 antialiasing_enabled = false;
833 glDisable (GL_LINE_SMOOTH);
834 glDisable (GL_POLYGON_SMOOTH);
835 } else {
836 antialiasing_enabled = true;
837 glEnable (GL_LINE_SMOOTH);
838 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
839 glEnable (GL_POLYGON_SMOOTH);
840 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
841 }
842
843 updateQWidget();
844 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
845}
846
847/**
848 SLOT Activate by a click on the haloing menu
849@param check : 1 , 0
850*/
851//FIXME : I SEE NOTHING...
852void G4OpenGLQtViewer::toggleHaloing(bool check) {
853 if (check) {
854 haloing_enabled = false;
855 } else {
856 haloing_enabled = true;
857 }
858
859 updateQWidget();
860
861 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
862}
863
864/**
865 SLOT Activate by a click on the auxiliaire edges menu
866@param check : 1 , 0
867*/
868void G4OpenGLQtViewer::toggleAux(bool check) {
869 if (check) {
870 fVP.SetAuxEdgeVisible(false);
871 } else {
872 fVP.SetAuxEdgeVisible(true);
873 }
874 SetNeedKernelVisit (true);
875 updateQWidget();
876
877 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
878}
879
880/**
881 SLOT Activate by a click on the full screen menu
882@param check : 1 , 0
883*/
884void G4OpenGLQtViewer::toggleFullScreen(bool check) {
885 GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
886
887 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
888}
889
890/**
891 SLOT Activate by a click on the mouse action menu
892 @param check : 1 , 0
893*/
894void G4OpenGLQtViewer::toggleMouseAction(bool check) {
895 if (check) { // rotate scene
896 fMouseAction = true;
897 } else { // move scene
898 fMouseAction = false;
899 }
900
901 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
902}
903
904
905void G4OpenGLQtViewer::actionControlPanels() {
906 printf("G4OpenGLQtViewer::actionControlPanels \n");
907}
908
909void G4OpenGLQtViewer::actionExitG4() {
910 printf("G4OpenGLQtViewer::actionExitG4() \n");
911}
912
913void G4OpenGLQtViewer::actionCreateEPS() {
914 QString filters;
915#if QT_VERSION < 0x040000
916 QStrList listFormat=QImageIO::outputFormats();
917 char *tmp=listFormat.first();
918 while (tmp!=0) {
919 filters += QString(tmp) + ";;";
920 tmp=listFormat.next();
921 }
922#else
923 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
924 for (int i = 0; i < formats.size(); ++i) {
925 filters +=formats.at(i) + ";;";
926 }
927#endif
928 filters += "eps;;";
929 filters += "ps;;";
930 filters += "pdf";
931 QString* selectedFilter = new QString();
932#if QT_VERSION < 0x040000
933 QString nomFich = QFileDialog::getSaveFileName ( ".",
934 filters,
935 GLWindow,
936 "Save file dialog",
937 tr("Save as ..."),
938 selectedFilter );
939#else
940 QString nomFich = QFileDialog::getSaveFileName ( GLWindow,
941 tr("Save as ..."),
942 ".",
943 filters,
944 selectedFilter );
945#endif
946 // bmp jpg jpeg png ppm xbm xpm
947 if (nomFich == "") {
948 return;
949 }
950#if QT_VERSION < 0x040000
951 nomFich += "."+selectedFilter->lower();
952 printf("G4OpenGLQtViewer::name %s\n",nomFich.ascii());
953#else
954 nomFich += "."+selectedFilter->toLower();
955 printf("G4OpenGLQtViewer::name %s\n",nomFich.toStdString().c_str());
956#endif
957 G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,fWindow->height(),fWindow->width());
958 if( exportDialog->exec()) {
959
960 QImage image;
961 // if ((exportDialog->getWidth() !=fWindow->width()) ||
962 // (exportDialog->getHeight() !=fWindow->height())) {
963
964 // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
965 printf("rescaling\n");
966 QGLWidget* glResized = fWindow;
967 fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2 ).save("/Users/laurentgarnier/Desktop/zzz.jpg","jpg");
968 QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;
969 // image = pixmap.toImage();
970 // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
971 printf("rescaling after\n");
972 // image = glResized->grabFrameBuffer();
973
974 // } else {
975 // image = fWindow->grabFrameBuffer();
976 // }
977 // jpeg format
978 if (nomFich.endsWith(".jpg") ||
979 nomFich.endsWith(".jpeg")) {
980 // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
981 image.save(nomFich,0,exportDialog->getSliderValue());
982 printf("saving jpeg quality : %d\n",exportDialog->getSliderValue());
983 } else if (nomFich.endsWith(".eps")) {
984 generateEPS(nomFich,exportDialog->getNbColor(),image);
985 } else if (nomFich.endsWith(".ps") ||nomFich.endsWith(".pdf")) {
986 generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
987 } else if (nomFich.endsWith(".tif") ||
988 nomFich.endsWith(".tiff") ||
989 nomFich.endsWith(".jpg") ||
990 nomFich.endsWith(".png") ||
991 nomFich.endsWith(".bmp") ||
992 nomFich.endsWith(".xpm")) {
993 image.save(nomFich,0,exportDialog->getSliderValue());
994 printf("saving ELSE\n");
995 } else {
996 G4cerr << "This version of G4UI Could not generate the selected format" << G4endl;
997 }
998
999 } else { // cancel selected
1000 return;
1001 }
1002
1003 printf("G4OpenGLQtViewer::actionCreateEPS() \n");
1004}
1005
1006/*
1007// http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0
1008
1009void Graph::exportToSVG(const QString& fname)
1010{
1011 // enable workaround for Qt3 misalignments
1012 QwtPainter::setSVGMode(true);
1013 QPicture picture;
1014 QPainter p(&picture);
1015 d_plot->print(&p, d_plot->rect());
1016 p.end();
1017
1018 picture.save(fname, "svg");
1019}
1020*/
1021
1022
1023
1024
1025/**
1026 Save the current mouse press point
1027 @param p mouse click point
1028*/
1029void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
1030{
1031 lastPos = p;
1032}
1033
1034/**
1035 @param pos_x mouse x position
1036 @param pos_y mouse y position
1037 @param mButtons mouse button active
1038*/
1039
1040#if QT_VERSION < 0x040000
1041void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
1042#else
1043void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
1044#endif
1045{
1046 int dx = pos_x - lastPos.x();
1047 int dy = pos_y - lastPos.y();
1048
1049 if (fMouseAction) { // rotate
1050 if (mButtons & Qt::LeftButton) {
1051 //phi spin stuff here
1052
1053 G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1054 G4Vector3D up = fVP.GetUpVector ().unit ();
1055
1056 G4Vector3D yprime = (up.cross(vp)).unit();
1057 G4Vector3D zprime = (vp.cross(yprime)).unit();
1058
1059 G4double delta_alpha;
1060 G4double delta_theta;
1061
1062 if (fVP.GetLightsMoveWithCamera()) {
1063 delta_alpha = dy;
1064 delta_theta = -dx;
1065 } else {
1066 delta_alpha = -dy;
1067 delta_theta = dx;
1068 }
1069
1070 delta_alpha *= deg;
1071 delta_theta *= deg;
1072
1073 G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1074
1075 G4Vector3D new_up;
1076 if (fVP.GetLightsMoveWithCamera()) {
1077 new_up = (new_vp.cross(yprime)).unit();
1078 fVP.SetUpVector(new_up);
1079 } else {
1080 new_up = up;
1081 }
1082 ////////////////
1083 // Rotates by fixed azimuthal angle delta_theta.
1084
1085 G4double cosalpha = new_up.dot (new_vp.unit());
1086 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1087 yprime = (new_up.cross (new_vp.unit())).unit ();
1088 G4Vector3D xprime = yprime.cross (new_up);
1089 // Projection of vp on plane perpendicular to up...
1090 G4Vector3D a1 = sinalpha * xprime;
1091 // Required new projection...
1092 G4Vector3D a2 =
1093 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1094 // Required Increment vector...
1095 G4Vector3D delta = a2 - a1;
1096 // So new viewpoint is...
1097 G4Vector3D viewPoint = new_vp.unit() + delta;
1098
1099 fVP.SetViewAndLights (viewPoint);
1100 updateQWidget();
1101
1102 } else if (mButtons & Qt::RightButton) {
1103 // NEVER DONE BECAUSE OF MOUSE MENU
1104 // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
1105 // setXRotation(xRot + dy/2);
1106 // setZRotation(zRot + dx/2);
1107 // updateQWidget();
1108 }
1109 } else { // move
1110
1111 float dx = pos_x - lastPos.x();
1112 float dy = pos_y - lastPos.y();
1113
1114 G4Point3D stp
1115 = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
1116
1117 G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
1118
1119 const G4Vector3D& upVector = fVP.GetUpVector ();
1120 const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
1121
1122 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
1123 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
1124
1125 tp += -dx * unitRight + dy * unitUp;
1126 fVP.SetCurrentTargetPoint (tp - stp);
1127
1128 updateQWidget();
1129 }
1130 lastPos = QPoint(pos_x, pos_y);
1131}
1132
1133void G4OpenGLQtViewer::rescaleImage(
1134 int aWidth
1135,int aHeight
1136){
1137 printf("should rescale \n");
1138}
1139
1140/**
1141 Generate Postscript form image
1142 @param aFilename : name of file
1143 @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1144 @param aImage : Image to print
1145*/
1146bool G4OpenGLQtViewer::generateEPS (
1147 QString aFilename
1148,int aInColor
1149,QImage aImage
1150)
1151{
1152 // FIXME
1153 printf("saving EPS\n");
1154
1155 FILE* fp;
1156
1157 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1158#if QT_VERSION < 0x040000
1159 aImage.convertDepth(1,Qt::MonoOnly);
1160#else
1161 aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1162#endif
1163 }
1164 const uchar * pixels = aImage.bits ();
1165
1166 if (pixels == NULL)
1167 return false;
1168
1169#if QT_VERSION < 0x040000
1170 fp = fopen (aFilename.ascii(), "w");
1171#else
1172 fp = fopen (aFilename.toStdString().c_str(), "w");
1173#endif
1174 if (fp == NULL) {
1175 return false;
1176 }
1177
1178 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
1179#if QT_VERSION < 0x040000
1180 fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1181#else
1182 fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
1183#endif
1184 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
1185 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
1186 fprintf (fp, "%%%%EndComments\n");
1187 fprintf (fp, "gsave\n");
1188 fprintf (fp, "/bwproc {\n");
1189 fprintf (fp, " rgbproc\n");
1190 fprintf (fp, " dup length 3 idiv string 0 3 0 \n");
1191 fprintf (fp, " 5 -1 roll {\n");
1192 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");
1193 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1194 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1195 fprintf (fp, " { 2 1 roll } ifelse\n");
1196 fprintf (fp, " }forall\n");
1197 fprintf (fp, " pop pop pop\n");
1198 fprintf (fp, "} def\n");
1199 fprintf (fp, "systemdict /colorimage known not {\n");
1200 fprintf (fp, " /colorimage {\n");
1201 fprintf (fp, " pop\n");
1202 fprintf (fp, " pop\n");
1203 fprintf (fp, " /rgbproc exch def\n");
1204 fprintf (fp, " { bwproc } image\n");
1205 fprintf (fp, " } def\n");
1206 fprintf (fp, "} if\n");
1207 fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1208 fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1209 fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1210 fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
1211 fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1212 fprintf (fp, "false %d\n", aInColor);
1213 fprintf (fp, "colorimage\n");
1214
1215
1216 int width = aImage.width();
1217 int height = aImage.height();
1218 int depth = aImage.depth();
1219 int size = width*height;
1220
1221 if (depth == 1)
1222 size = (width+7)/8*height;
1223 else if (aInColor == 1)
1224 size = size*3;
1225
1226 int i = 0;
1227 if (depth == 1) {
1228 // To be implemented
1229 // QImage::Endian bitOrder = aImage.bitOrder();
1230 /* for(int y=0; y < height; y++) {
1231 const uchar * s = aImage.scanLine(y);
1232 for(int x=0; x < width; x++) {
1233 // need to copy bit for bit...
1234 bool b = (bitOrder == QImage::LittleEndian) ?
1235 (*(s + (x >> 3)) >> (x & 7)) & 1 :
1236 (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
1237 if (b)
1238 pixel[i >> 3] ^= (0x80 >> (i & 7));
1239 i++;
1240 }
1241 // we need to align to 8 bit here
1242 i = (i+7) & 0xffffff8;
1243 }
1244 */
1245 } else if (depth == 8) {
1246 printf("has 8 bit\n");
1247 for(int y=height-1; y >=0 ; y--) {
1248 const uchar * s = aImage.scanLine(y);
1249 for(int x=0; x <width; x++) {
1250 QRgb rgb = aImage.color(s[x]);
1251 if (aInColor == 1) {
1252 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1253 i++;
1254 } else {
1255 fprintf (fp, " %02hx %02hx %02hx",
1256 (unsigned char) qRed(rgb),
1257 (unsigned char) qGreen(rgb),
1258 (unsigned char) qBlue(rgb));
1259 i += 3;
1260 }
1261 }
1262 fprintf (fp, "\n");
1263 }
1264 } else {
1265#if QT_VERSION < 0x040000
1266 G4cerr << "GenerateEPS:: No alpha channel image with Qt3. This is only supported with Qt4" << G4endl;
1267#else
1268 bool alpha = aImage.hasAlphaChannel();
1269 printf("has else %d alpha %d\n",depth,alpha);
1270 for(int y=height-1; y >=0 ; y--) {
1271 QRgb * s = (QRgb*)(aImage.scanLine(y));
1272 for(int x=0; x <width; x++) {
1273 QRgb rgb = (*s++);
1274 if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1275 rgb = qRgb(0xff, 0xff, 0xff);
1276 if (aInColor == 1) {
1277 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1278 i++;
1279 } else {
1280 fprintf (fp, " %02hx %02hx %02hx",
1281 (unsigned char) qRed(rgb),
1282 (unsigned char) qGreen(rgb),
1283 (unsigned char) qBlue(rgb));
1284 i += 3;
1285 }
1286 }
1287 fprintf (fp, "\n");
1288 }
1289#endif
1290
1291 }
1292
1293 fprintf (fp, "grestore\n");
1294 fprintf (fp, "showpage\n");
1295 fclose (fp);
1296
1297 return true;
1298}
1299/**
1300 Generate Postscript or PDF form image
1301 @param aFilename : name of file
1302 @param aInColor : numbers of colors : 1->BW 2->RGB
1303 @param aImage : Image to print
1304*/
1305bool G4OpenGLQtViewer::generatePS_PDF (
1306 QString aFilename
1307,int aInColor
1308,QImage aImage
1309)
1310{
1311#if QT_VERSION < 0x040000
1312#ifdef Q_WS_MAC || Q_WS_X11
1313 QPrinter printer;
1314 // printer.setPageSize(pageSize);
1315 if (aInColor == 1) {
1316 printer.setColorMode(QPrinter::GrayScale);
1317 } else {
1318 printer.setColorMode(QPrinter::Color);
1319 }
1320
1321 /* FIXME : I don't know which format it will save...
1322 if (aFilename.endsWith(".ps")) {
1323 printer.setOutputFormat(QPrinter::PostScriptFormat);
1324 } else {
1325 printer.setOutputFormat(QPrinter::PdfFormat);
1326 }
1327 */
1328 printer.setOutputFileName(aFilename);
1329 // printer.setFullPage ( true);
1330 QPainter paint(&printer);
1331 paint.drawImage (0,0,aImage );
1332 paint.end();
1333#else
1334 G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4" << G4endl;
1335#endif
1336#else
1337 QPrinter printer;
1338 // printer.setPageSize(pageSize);
1339 if (aInColor == 1) {
1340 printer.setColorMode(QPrinter::GrayScale);
1341 } else {
1342 printer.setColorMode(QPrinter::Color);
1343 }
1344
1345 if (aFilename.endsWith(".ps")) {
1346#if QT_VERSION > 0x040200
1347 printer.setOutputFormat(QPrinter::PostScriptFormat);
1348#endif
1349 } else {
1350#if QT_VERSION > 0x040100
1351 printer.setOutputFormat(QPrinter::PdfFormat);
1352#endif
1353 }
1354#if QT_VERSION > 0x040100
1355 printer.setOutputFileName(aFilename);
1356#endif
1357 // printer.setFullPage ( true);
1358 QPainter paint(&printer);
1359 paint.drawImage (0,0,aImage );
1360 paint.end();
1361#endif
1362 return true;
1363}
1364
1365#endif
1366
1367/*
1368
1369void MultiLayer::exportToSVG(const QString& fname)
1370{
1371 QPicture picture;
1372 QPainter p(&picture);
1373 for (int i=0;i<(int)graphsList->count();i++)
1374 {
1375 Graph *gr=(Graph *)graphsList->at(i);
1376 Plot *myPlot= (Plot *)gr->plotWidget();
1377
1378 QPoint pos=gr->pos();
1379
1380 int width=int(myPlot->frameGeometry().width());
1381 int height=int(myPlot->frameGeometry().height());
1382
1383 myPlot->print(&p, QRect(pos,QSize(width,height)));
1384 }
1385
1386 p.end();
1387 picture.save(fname, "svg");
1388}
1389*/
Note: See TracBrowser for help on using the repository browser.