1 | #include <QKeyEvent> |
---|
2 | #include "ProjectionModel.h" |
---|
3 | #include "Scene.h" |
---|
4 | #include "gui/QSceneViewerWindow.h" |
---|
5 | |
---|
6 | using namespace projection; |
---|
7 | using namespace gmtl; |
---|
8 | |
---|
9 | QSceneViewerWindow::QSceneViewerWindow(QWidget* pParent, const QGLWidget* pSharedWidget, Qt::WFlags flags) : |
---|
10 | QGLViewerWidget(pParent, pSharedWidget, flags|Qt::Window) |
---|
11 | { |
---|
12 | m_pModel = NULL; |
---|
13 | |
---|
14 | setWindowTitle("Scene Viewer"); |
---|
15 | setFocusPolicy(Qt::StrongFocus); |
---|
16 | resize(640, 480); |
---|
17 | } |
---|
18 | |
---|
19 | void QSceneViewerWindow::setModel(ProjectionModel* pModel) |
---|
20 | { |
---|
21 | m_pModel = pModel; |
---|
22 | setView(m_pModel->getScene()->getCameraCenter(), m_pModel->getScene()->getCameraRotation(), m_pModel->getScene()->getCameraDistance()); |
---|
23 | connect(this, SIGNAL(cameraChanged(const gmtl::Vec3f&, const gmtl::Quatf&, float)), |
---|
24 | m_pModel->getScene(), SLOT(setCameraViewpoint(const gmtl::Vec3f&, const gmtl::Quatf&, float))); |
---|
25 | } |
---|
26 | |
---|
27 | void QSceneViewerWindow::init() |
---|
28 | { |
---|
29 | } |
---|
30 | |
---|
31 | void QSceneViewerWindow::draw() |
---|
32 | { |
---|
33 | if (m_pModel) |
---|
34 | { |
---|
35 | m_pModel->setRenderContext(this); |
---|
36 | m_pModel->getScene()->draw(); |
---|
37 | |
---|
38 | m_bGridVisible = m_pModel->getScene()->getShowGrid(); |
---|
39 | m_gridSize = m_pModel->getScene()->getGridSize(); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | void QSceneViewerWindow::resetCamera() |
---|
44 | { |
---|
45 | setView(Vec3f(0.0f, 0.0f, 0.0f), Quatf(), 0.00001f); |
---|
46 | updateGL(); |
---|
47 | } |
---|
48 | |
---|
49 | void QSceneViewerWindow::keyReleaseEvent(QKeyEvent* pEvent) |
---|
50 | { |
---|
51 | QGLViewerWidget::keyReleaseEvent(pEvent); |
---|
52 | |
---|
53 | static bool bFullScreen = false; |
---|
54 | switch (pEvent->key()) |
---|
55 | { |
---|
56 | case Qt::Key_Return: |
---|
57 | if (pEvent->modifiers() & Qt::AltModifier) |
---|
58 | { |
---|
59 | if (!bFullScreen) { |
---|
60 | showFullScreen(); |
---|
61 | bFullScreen = true; |
---|
62 | } else { |
---|
63 | showNormal(); |
---|
64 | bFullScreen = false; |
---|
65 | } |
---|
66 | } |
---|
67 | break; |
---|
68 | default: |
---|
69 | return; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | void QSceneViewerWindow::initFromDOMElement(const QDomElement& element) |
---|
74 | { |
---|
75 | if (element.isNull()) |
---|
76 | return; |
---|
77 | |
---|
78 | QGLViewerWidget::initFromDOMElement(element); |
---|
79 | |
---|
80 | if (element.attribute("show")=="true") |
---|
81 | show(); |
---|
82 | else |
---|
83 | hide(); |
---|
84 | } |
---|
85 | |
---|
86 | QDomElement QSceneViewerWindow::domElement(const QString& name, QDomDocument& doc) const |
---|
87 | { |
---|
88 | QDomElement de = QGLViewerWidget::domElement(name, doc); |
---|
89 | if (isVisible()) |
---|
90 | de.setAttribute("show", "true"); |
---|
91 | else |
---|
92 | de.setAttribute("show", "false"); |
---|
93 | return de; |
---|
94 | } |
---|