From a5c09fe65f77ff721bcd8820373475aaac966480 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 14 Jul 2010 21:44:23 +0200 Subject: Added some test qml file. --- declarativeviewtexture.cpp | 6 +----- example.qml | 16 ++++++++++++++++ ogrewidget.cpp | 18 +++++------------- qmlogre.pro | 3 +++ 4 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 example.qml diff --git a/declarativeviewtexture.cpp b/declarativeviewtexture.cpp index 2af4879..951c1e3 100644 --- a/declarativeviewtexture.cpp +++ b/declarativeviewtexture.cpp @@ -44,19 +44,15 @@ DeclarativeViewTexture::~DeclarativeViewTexture() void DeclarativeViewTexture::paintEvent(QPaintEvent *event) { // Render the view in an offscreen image - if (m_bufferPainter) - delete m_bufferPainter; + delete m_bufferPainter; m_bufferPainter = new QPainter; - QRegion exposedRegion = event->region(); QImage im(exposedRegion.boundingRect().size(), QImage::Format_ARGB32_Premultiplied); im.fill(Qt::transparent); m_bufferPainter->begin(&im); m_bufferPainter->translate(-exposedRegion.boundingRect().topLeft()); m_bufferPainter->setClipRegion(exposedRegion); - QDeclarativeView::paintEvent(event); - m_bufferPainter->end(); // Upload the image in graphics memory diff --git a/example.qml b/example.qml new file mode 100644 index 0000000..1d008bd --- /dev/null +++ b/example.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +Item { + width: 1024 + height: 768 + + Rectangle { + id: rectangle1 + x: 51 + y: 200 + width: 208 + height: 410 + color: "#96444444" + radius: 20 + } +} diff --git a/ogrewidget.cpp b/ogrewidget.cpp index 991bf2a..dfe1b5a 100644 --- a/ogrewidget.cpp +++ b/ogrewidget.cpp @@ -79,25 +79,12 @@ void OgreWidget::paintGL() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /*float top = qMax(-1.f, qMin(1.f, (rect().center().y() - m_QmlUI->pos().y()) / float(rect().center().y()))); - float left = qMax(-1.f, qMin(1.f, (rect().center().x() - m_QmlUI->pos().x()) / float(-rect().center().x()))); - float bottom = qMax(-1.f, qMin(1.f, (rect().center().y() - m_QmlUI->pos().y() - m_QmlUI->height()) / float(rect().center().y()))); - float right = qMax(-1.f, qMin(1.f, (rect().center().x() - m_QmlUI->pos().x() - m_QmlUI->width()) / float(-rect().center().x()))); - float texTop = qMin(1.f, qMax(-m_QmlUI->pos().y() / float(m_QmlUI->height()), 0.f)); - float texLeft = qMin(1.f, qMax(-m_QmlUI->pos().x() / float(m_QmlUI->width()), 0.f)); - float texBottom = qMax(0.f, qMin(height() - m_QmlUI->pos().y() / float(m_QmlUI->height()), 1.f)); - float texRight = qMax(0.f, qMin(width() - m_QmlUI->pos().x() / float(m_QmlUI->width()), 1.f));*/ - float top = (rect().center().y() - m_QmlUI->pos().y()) / float(rect().center().y()); float left = (rect().center().x() - m_QmlUI->pos().x()) / float(-rect().center().x()); float bottom = (rect().center().y() - m_QmlUI->pos().y() - m_QmlUI->height()) / float(rect().center().y()); float right = (rect().center().x() - m_QmlUI->pos().x() - m_QmlUI->width()) / float(-rect().center().x()); glBegin(GL_QUADS); - /*glTexCoord2f(texLeft, texTop); glVertex3f(left, top, -1.0f); // Top Left - glTexCoord2f(texLeft, texBottom); glVertex3f(left, bottom, -1.0f); // Bottom Left - glTexCoord2f(texRight, texBottom); glVertex3f(right, bottom, -1.0f); // Bottom Right - glTexCoord2f(texRight, texTop); glVertex3f(right, top, -1.0f); // Top Right*/ glTexCoord2f(0, 0); glVertex3f(left, top, -1.0f); // Top Left glTexCoord2f(0, 1); glVertex3f(left, bottom, -1.0f); // Bottom Left glTexCoord2f(1, 1); glVertex3f(right, bottom, -1.0f); // Bottom Right @@ -119,6 +106,8 @@ void OgreWidget::initializeGL() initOgre(); m_QmlUI = new DeclarativeViewTexture(this); + m_QmlUI->setResizeMode(QDeclarativeView::SizeRootObjectToView); + m_QmlUI->setSource(QUrl("example.qml")); } void OgreWidget::resizeGL(int w, int h) @@ -131,6 +120,9 @@ void OgreWidget::resizeGL(int w, int h) Ogre::Real aspectRatio = Ogre::Real(w) / Ogre::Real(h); m_camera->setAspectRatio(aspectRatio); } + if (m_QmlUI) { + m_QmlUI->resize(w, h); + } } diff --git a/qmlogre.pro b/qmlogre.pro index e0308a0..62527c3 100644 --- a/qmlogre.pro +++ b/qmlogre.pro @@ -46,3 +46,6 @@ SOURCES += main.cpp \ HEADERS += \ ogrewidget.h \ declarativeviewtexture.h + +OTHER_FILES += \ + example.qml -- cgit v1.2.3