1
/****************************************************************************
2
3
This file is part of the wolfenqt project on http://qt.gitorious.org.
4
5
Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).*
6
All rights reserved.
7
8
Contact:  Nokia Corporation (qt-info@nokia.com)**
9
10
You may use this file under the terms of the BSD license as follows:
11
12
"Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
14
* Redistributions of source code must retain the above copyright notice,
15
* this list of conditions and the following disclaimer.
16
* Redistributions in binary form must reproduce the above copyright notice,
17
* this list of conditions and the following disclaimer in the documentation
18
* and/or other materials provided with the distribution.
19
* Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
20
* names of its contributors may be used to endorse or promote products
21
* derived from this software without specific prior written permission.
22
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
POSSIBILITY OF SUCH DAMAGE."
33
34
****************************************************************************/
35
#ifndef OPENGLSCENE_H
36
#define OPENGLSCENE_H
37
38
#include <QVector3D>
39
40
#include <QCheckBox>
41
#include <QWidget>
42
#include <QTime>
43
44
#ifndef QT_NO_CONCURRENT
45
#include <QFutureWatcher>
46
#endif
47
48
#include "mazescene.h"
49
50
QT_BEGIN_NAMESPACE
51
class QGLShaderProgram;
52
QT_END_NAMESPACE
53
54
class Model;
55
56
class ModelItem : public QWidget, public ProjectedItem
57
{
58
    Q_OBJECT
59
60
public:
61
    ModelItem();
62
63
    void updateTransform(const Camera &camera);
64
65
    QRectF boundingRect() const;
66
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
67
68
public slots:
69
    void enableWireframe(bool enabled);
70
    void enableNormals(bool enabled);
71
    void setModelColor();
72
    void loadModel();
73
    void loadModel(const QString &filePath);
74
    void modelLoaded();
75
    void updateItem();
76
77
private:
78
    void setModel(Model *model);
79
80
    bool m_wireframeEnabled;
81
    bool m_normalsEnabled;
82
    bool m_useQPainter;
83
84
    QColor m_modelColor;
85
86
    Model *m_model;
87
88
    QTime m_time;
89
    int m_lastTime;
90
    int m_mouseEventTime;
91
92
    float m_distance;
93
    QVector3D m_rotation;
94
    QVector3D m_angularMomentum;
95
    QVector3D m_accumulatedMomentum;
96
97
    QWidget *m_modelButton;
98
    QCheckBox *m_wireframe;
99
100
#ifndef QT_NO_CONCURRENT
101
    QFutureWatcher<Model *> m_modelLoader;
102
#endif
103
    QMatrix4x4 m_matrix;
104
105
#ifndef QT_NO_OPENGL
106
    mutable QGLShaderProgram *m_program;
107
#endif
108
};
109
110
#endif