summaryrefslogtreecommitdiffstats
path: root/demos/boxes/qtbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'demos/boxes/qtbox.cpp')
-rw-r--r--demos/boxes/qtbox.cpp59
1 files changed, 35 insertions, 24 deletions
diff --git a/demos/boxes/qtbox.cpp b/demos/boxes/qtbox.cpp
index 17566e9..7134d63 100644
--- a/demos/boxes/qtbox.cpp
+++ b/demos/boxes/qtbox.cpp
@@ -1,7 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the demonstration applications of the Qt Toolkit.
@@ -21,9 +20,10 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
@@ -122,7 +122,7 @@ void ItemBase::duplicateSelectedItems(QGraphicsScene *scene)
selected = scene->selectedItems();
foreach (QGraphicsItem *item, selected) {
- ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
if (itemBase)
scene->addItem(itemBase->createNew(itemBase->m_size, itemBase->pos().x() + itemBase->m_size, itemBase->pos().y()));
}
@@ -137,7 +137,7 @@ void ItemBase::deleteSelectedItems(QGraphicsScene *scene)
selected = scene->selectedItems();
foreach (QGraphicsItem *item, selected) {
- ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
if (itemBase)
delete itemBase;
}
@@ -152,7 +152,7 @@ void ItemBase::growSelectedItems(QGraphicsScene *scene)
selected = scene->selectedItems();
foreach (QGraphicsItem *item, selected) {
- ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
if (itemBase) {
itemBase->prepareGeometryChange();
itemBase->m_size *= 2;
@@ -171,7 +171,7 @@ void ItemBase::shrinkSelectedItems(QGraphicsScene *scene)
selected = scene->selectedItems();
foreach (QGraphicsItem *item, selected) {
- ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
if (itemBase) {
itemBase->prepareGeometryChange();
itemBase->m_size /= 2;
@@ -257,6 +257,12 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
m_size = MIN_ITEM_SIZE;
}
+int ItemBase::type() const
+{
+ return Type;
+}
+
+
bool ItemBase::isInResizeArea(const QPointF &pos)
{
return (-pos.y() < pos.x() - m_size + 9);
@@ -269,19 +275,20 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
{
for (int i = 0; i < 8; ++i) {
- m_vertices[i][0] = (i & 1 ? 0.5f : -0.5f);
- m_vertices[i][1] = (i & 2 ? 0.5f : -0.5f);
- m_vertices[i][2] = (i & 4 ? 0.5f : -0.5f);
+ m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
+ m_vertices[i].setY(i & 2 ? 0.5f : -0.5f);
+ m_vertices[i].setZ(i & 4 ? 0.5f : -0.5f);
}
for (int i = 0; i < 4; ++i) {
- m_texCoords[i][0] = (i & 1 ? 1.0f : 0.0f);
- m_texCoords[i][1] = (i & 2 ? 1.0f : 0.0f);
- }
- memset(m_normals, 0, sizeof(m_normals));
- for (int i = 0; i < 3; ++i) {
- m_normals[2 * i + 0][i] = -1.0f;
- m_normals[2 * i + 1][i] = 1.0f;
+ m_texCoords[i].setX(i & 1 ? 1.0f : 0.0f);
+ m_texCoords[i].setY(i & 2 ? 1.0f : 0.0f);
}
+ m_normals[0] = QVector3D(-1.0f, 0.0f, 0.0f);
+ m_normals[1] = QVector3D(1.0f, 0.0f, 0.0f);
+ m_normals[2] = QVector3D(0.0f, -1.0f, 0.0f);
+ m_normals[3] = QVector3D(0.0f, 1.0f, 0.0f);
+ m_normals[4] = QVector3D(0.0f, 0.0f, -1.0f);
+ m_normals[5] = QVector3D(0.0f, 0.0f, 1.0f);
}
QtBox::~QtBox()
@@ -312,6 +319,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
0.5f * (right + left), 0.5f * (bottom + top), 0.0f, 1.0f
};
+ painter->beginNativePainting();
+
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(moveToRectMatrix);
@@ -351,21 +360,21 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glColor4f(1.0f, 1.0f, 1.0f, 1.0);
glBegin(GL_TRIANGLE_STRIP);
- glNormal3fv(m_normals[2 * dir + 0].bits());
+ glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 0]));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
- glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
- glVertex3fv(m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))].bits());
+ glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
+ glVertex3fv(reinterpret_cast<float *>(&m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))]));
}
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
- glNormal3fv(m_normals[2 * dir + 1].bits());
+ glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 1]));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
- glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
- glVertex3fv(m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))].bits());
+ glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
+ glVertex3fv(reinterpret_cast<float *>(&m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))]));
}
}
glEnd();
@@ -385,6 +394,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glMatrixMode(GL_PROJECTION);
glPopMatrix();
+ painter->endNativePainting();
+
ItemBase::paint(painter, option, widget);
}