| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QTBOX_H
|
|---|
| 43 | #define QTBOX_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui>
|
|---|
| 46 |
|
|---|
| 47 | #include "vector.h"
|
|---|
| 48 | #include "glbuffers.h"
|
|---|
| 49 |
|
|---|
| 50 | class ItemBase : public QObject, public QGraphicsItem
|
|---|
| 51 | {
|
|---|
| 52 | Q_OBJECT
|
|---|
| 53 | public:
|
|---|
| 54 | ItemBase(int size, int x, int y);
|
|---|
| 55 | virtual ~ItemBase();
|
|---|
| 56 | virtual QRectF boundingRect() const;
|
|---|
| 57 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|---|
| 58 | protected:
|
|---|
| 59 | virtual ItemBase *createNew(int size, int x, int y) = 0;
|
|---|
| 60 | virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
|---|
| 61 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 62 | virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
|---|
| 63 | virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 64 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 65 | virtual void keyPressEvent(QKeyEvent *event);
|
|---|
| 66 | virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
|
|---|
| 67 | bool isInResizeArea(const QPointF &pos);
|
|---|
| 68 |
|
|---|
| 69 | static void duplicateSelectedItems(QGraphicsScene *scene);
|
|---|
| 70 | static void deleteSelectedItems(QGraphicsScene *scene);
|
|---|
| 71 | static void growSelectedItems(QGraphicsScene *scene);
|
|---|
| 72 | static void shrinkSelectedItems(QGraphicsScene *scene);
|
|---|
| 73 |
|
|---|
| 74 | int m_size;
|
|---|
| 75 | QTime m_startTime;
|
|---|
| 76 | bool m_isResizing;
|
|---|
| 77 | };
|
|---|
| 78 |
|
|---|
| 79 | class QtBox : public ItemBase
|
|---|
| 80 | {
|
|---|
| 81 | public:
|
|---|
| 82 | QtBox(int size, int x, int y);
|
|---|
| 83 | virtual ~QtBox();
|
|---|
| 84 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|---|
| 85 | protected:
|
|---|
| 86 | virtual ItemBase *createNew(int size, int x, int y);
|
|---|
| 87 | private:
|
|---|
| 88 | gfx::Vector3f m_vertices[8];
|
|---|
| 89 | gfx::Vector2f m_texCoords[4];
|
|---|
| 90 | gfx::Vector3f m_normals[6];
|
|---|
| 91 | GLTexture *m_texture;
|
|---|
| 92 | };
|
|---|
| 93 |
|
|---|
| 94 | class CircleItem : public ItemBase
|
|---|
| 95 | {
|
|---|
| 96 | public:
|
|---|
| 97 | CircleItem(int size, int x, int y);
|
|---|
| 98 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|---|
| 99 | protected:
|
|---|
| 100 | virtual ItemBase *createNew(int size, int x, int y);
|
|---|
| 101 |
|
|---|
| 102 | QColor m_color;
|
|---|
| 103 | };
|
|---|
| 104 |
|
|---|
| 105 | class SquareItem : public ItemBase
|
|---|
| 106 | {
|
|---|
| 107 | public:
|
|---|
| 108 | SquareItem(int size, int x, int y);
|
|---|
| 109 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|---|
| 110 | protected:
|
|---|
| 111 | virtual ItemBase *createNew(int size, int x, int y);
|
|---|
| 112 |
|
|---|
| 113 | QPixmap m_image;
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | #endif
|
|---|