view.h 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef _VIEW_H_
#define _VIEW_H_

#include <iostream>

#include "types.h"
#include "viewButtonArea.h"

# include <QKeyEvent>
#include <QList>
#include <QWidget>

#include "Utils/gl_matrices.h"

//forward declaration
class Scene;
class Camera;
class Context;

class View : public QGLViewer
{
	Q_OBJECT

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
25
	View(Scene* s, const QString& name, Camera* c, QGLWidget* shareWidget = NULL, Context* context = NULL, QWidget* parent = NULL);
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	~View();

	virtual void updateGL();
	virtual void draw();
	virtual void init();

	void drawCameras(View* view);
	void drawText();
	void drawButtons();

	void keyPressEvent(QKeyEvent* event);
	void keyReleaseEvent(QKeyEvent *e);
	void mousePressEvent(QMouseEvent* event);
	void mouseReleaseEvent(QMouseEvent* event);
	void mouseMoveEvent(QMouseEvent* event);
	void wheelEvent(QWheelEvent* event);

	virtual void resizeGL(int width, int height);

	void drawOverpaint(QPainter *painter);

//	virtual void paintGL() { update(); }
//	virtual void paintEvent(QPaintEvent *event);

	Scene* getScene() { return m_scene; }

Pierre Kraemer's avatar
Pierre Kraemer committed
52 53
	void setName(const QString& name) { m_name = name; }
	const QString& getName() { return m_name; }
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

	void enableLinking(bool b = true);
	void enableUnlinking(bool b = true);
	void enableCameraGesture(bool b = true);
	void enableSceneCameraGesture(bool b = true);
	void enableViewClose(bool b = true);

	Camera* currentCamera() { return m_currentCamera; }
	void setCurrentCamera(Camera* c);
	QList<Camera*> cameras() { return l_camera; }
	int countCameras() { return l_camera.size(); }

	void removeCamera(Camera* c);
	Camera* takeCamera(Camera* c);
	Camera* addCamera();
	void insertCamera(int index, Camera* c);
	void shareCamera(Camera* c, int index = 0);

//	void addUnlinkButton();
//	void removeUnlinkButton();

	void updateTextInfo();

	glm::mat4 getCurrentModelViewMatrix();
	glm::mat4 getCurrentProjectionMatrix();
	glm::mat4 getCurrentModelViewProjectionMatrix();

	void setCurrentModelViewMatrix(glm::mat4 mvm);
	void setCurrentProjectionMatrix(glm::mat4 pm);

	void addCustomViewButton(ViewButton* viewButton);
	void removeCustomViewButton(ViewButton* viewButton);

	void setShowButtons(bool b) { b_showButtons = b; }

protected:
	QString m_name;
Pierre Kraemer's avatar
Pierre Kraemer committed
91
	Scene* m_scene;
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

	QList<Camera*> l_camera;
	Camera* m_currentCamera;

	ViewButtonArea* m_buttonArea;

	ViewButton* m_linkButton;
	bool m_linkViewEnabled;
	ViewButton* m_unlinkButton;
	bool m_unlinkViewEnabled;
	ViewButton* m_cameraButton;
	bool m_cameraEnabled;
	ViewButton* m_cameraSceneButton;
	bool m_cameraSceneEnabled;
	ViewButton* m_closeViewButton;
	bool m_closeViewEnabled;

	QString m_textInfo;

	Context* m_context;

	bool b_showButtons;

public slots:
	void linkView();
	void unlinkView();
	void cameraGesture();
	void cameraSceneGesture();
	void closeView();

	void clickButton(ViewButton* viewButton);

private:
	bool b_destroyView;

signals:
	void currentCameraChanged(Camera* camera);
	void viewButtonClicked(ViewButton* viewButton);
};

#endif