1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8 *                                                                         *
9 *   This program is free software; you can redistribute it and/or modify  *
10 *   it under the terms of the GNU General Public License as published by  *
11 *   the Free Software Foundation; either version 2 of the License, or     *
12 *   (at your option) any later version.                                   *
13 *                                                                         *
14 ***************************************************************************/
15 #ifndef ADAPTERWIDGET_H
16 #define ADAPTERWIDGET_H
17 
18 #include <QtCore>
19 #include <QtGui>
20 #include <QtOpenGL>
21 #include <osgViewer/Viewer>
22 #include <osg/Vec3>
23 
24 class AdapterWidget : public QGLWidget
25 {
26     Q_OBJECT
27 	public:
28 		AdapterWidget ( QWidget* parent = nullptr, const char * name = 0, const QGLWidget * shareWidget = 0);
29 
~AdapterWidget()30 		virtual ~AdapterWidget() {}
31 
getGraphicsWindow()32 		osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); }
getGraphicsWindow()33 		const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); }
34 
35 	signals:
36 		void mouseMoved();
37 	protected:
38 
39 		void init();
40 
41 		virtual void resizeGL ( int width, int height );
42 		virtual void keyPressEvent ( QKeyEvent* event );
43 		virtual void keyReleaseEvent ( QKeyEvent* event );
44 		virtual void mousePressEvent ( QMouseEvent* event );
45 		virtual void mouseReleaseEvent ( QMouseEvent* event );
46 		virtual void mouseMoveEvent ( QMouseEvent* event );
47 
48 		int button;
49 		osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw;
50 };
51 
52 
53 class ViewerQT : public osgViewer::Viewer, public AdapterWidget
54 {
55 	public:
AdapterWidget(parent,name,shareWidget)56 		ViewerQT ( QWidget* parent = nullptr, const char * name = 0, const QGLWidget * shareWidget = 0) : AdapterWidget ( parent, name, shareWidget)
57 		{
58 			getCamera()->setViewport ( new osg::Viewport ( 0,0,width(),height() ) );
59 			getCamera()->setProjectionMatrixAsPerspective ( 30.0f, static_cast<double> ( width() ) /static_cast<double> ( height() ), 1.0f, 10000.0f );
60 			QColor bg = palette().window().color();
61 			getCamera()->setClearColor(osg::Vec4(bg.redF(), bg.greenF(), bg.blueF(), 0.0));
62 			getCamera()->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
63 			getCamera()->setGraphicsContext ( getGraphicsWindow() );
64 
65 			setThreadingModel ( osgViewer::Viewer::SingleThreaded );
66 
67 			connect ( &_timer, SIGNAL ( timeout() ), this, SLOT ( updateGL() ) );
68 		}
69 
showEvent(QShowEvent *)70 		virtual void showEvent(QShowEvent *)
71 		{
72 			_timer.start(10);
73 		}
74 
paintGL()75 		virtual void paintGL()
76 		{
77 			frame();
78 		}
79 
80 	protected:
81 
82 		QTimer _timer;
83 };
84 #endif
85