예제 #1
0
QGraphicsViewAdapter::QGraphicsViewAdapter(osg::Image* image, QWidget* widget):
    _image(image),
    _previousQtMouseX(-1),
    _previousQtMouseY(-1),
    _previousSentEvent(false),
    _qtKeyModifiers(Qt::NoModifier),
    _backgroundColor(255, 255, 255),
    _widget(widget)
{
    // make sure we have a valid QApplication before we start creating widgets.
    getOrCreateQApplication();


    setUpKeyMap();

    _graphicsScene = new QGraphicsScene;
    _graphicsScene->addWidget(widget);

    _graphicsView = new QGraphicsView;
    _graphicsView->setScene(_graphicsScene);
    _graphicsView->viewport()->setParent(0);

#if (QT_VERSION_CHECK(4, 5, 0) <= QT_VERSION)
    _graphicsScene->setStickyFocus(true);
#endif

    _width = _graphicsScene->width();
    _height = _graphicsScene->height();

    _qimages[0] = QImage(QSize(_width, _height), s_imageFormat);
    _qimages[1] = QImage(QSize(_width, _height), s_imageFormat);
    _qimages[2] = QImage(QSize(_width, _height), s_imageFormat);

    _currentRead = 0;
    _currentWrite = 1;
    _previousWrite = 2;
    _previousFrameNumber = 0;
    _newImageAvailable = false;

    connect(_graphicsScene, SIGNAL(changed(const QList<QRectF> &)),
            this, SLOT(repaintRequestedSlot(const QList<QRectF> &)));
    connect(_graphicsScene, SIGNAL(sceneRectChanged(const QRectF &)),
            this, SLOT(repaintRequestedSlot(const QRectF &)));

    assignImage(0);
}
QGraphicsViewAdapter::QGraphicsViewAdapter(osg::Image* image, QWidget* widget):
	_image(image),

	_qtKeyModifiers(Qt::NoModifier),
	_backgroundColor(255,255,255)
{
	// make sure we have a valid QApplication before we start creating widgets.
	getOrCreateQApplication();


	setUpKeyMap();

	_graphicsScene = new QGraphicsScene();
	_graphicsView = new QGraphicsView;
	_graphicsScene->addWidget(widget);
	_graphicsView->setScene(_graphicsScene);
#if (QT_VERSION_CHECK(4, 5, 0) <= QT_VERSION)
	_graphicsScene->setStickyFocus(true);
#endif
	_graphicsView->viewport()->setParent(0);


	int width = (int) _graphicsScene->width();
	int height = (int) _graphicsScene->height();

	_qimages[0] = QImage(QSize(width, height), QImage::Format_ARGB32);
	_qimages[0].fill(_backgroundColor.rgba());
	_qimages[0] = QGLWidget::convertToGLFormat(_qimages[0]);

	_qimages[1] = QImage(QSize(width, height), QImage::Format_ARGB32);
	_qimages[1].fill(_backgroundColor.rgba());

	_qimages[2] = QImage(QSize(width, height), QImage::Format_ARGB32);
	_qimages[2].fill(_backgroundColor.rgba());

	_currentRead = 0;
	_currentWrite = 1;
	_previousWrite = 2;
	_previousFrameNumber = 0;
	_newImageAvailable = false;

	connect(_graphicsScene, SIGNAL(changed(const QList<QRectF> &)),
			this, SLOT(repaintRequestedSlot(const QList<QRectF> &)));

	assignImage(0);
}