view.h 2.49 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public
 *   License as published by the Free Software Foundation; either
 *   version 2 of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/

#ifndef PALAPELI_VIEW_H
#define PALAPELI_VIEW_H

#include <QGraphicsView>

namespace Palapeli
{
26
	class ConstraintVisualizer;
27
	class InteractorManager;
28
	class Scene;
29
	class TextureHelper;
30 31 32 33

	class View : public QGraphicsView
	{
		Q_OBJECT
34
			Q_PROPERTY(QRectF viewportRect READ viewportRect WRITE setViewportRect)
35 36 37
		public:
			View();

38
			Palapeli::InteractorManager* interactorManager() const;
39
			Palapeli::Scene* scene() const;
40
			Palapeli::TextureHelper* textureHelper() const;
Stefan Majewsky's avatar
Stefan Majewsky committed
41

42 43 44
			QRectF viewportRect() const;
			void setViewportRect(const QRectF& viewportRect);

Stefan Majewsky's avatar
Stefan Majewsky committed
45 46
			static const int MinimumZoomLevel;
			static const int MaximumZoomLevel;
47
		public Q_SLOTS:
48 49
			void setScene(Palapeli::Scene* scene);

50 51 52
			void zoomIn();
			void zoomOut();
			void zoomBy(int delta); //delta = 0 -> no change, delta < 0 -> zoom out, delta > 0 -> zoom in
Stefan Majewsky's avatar
Stefan Majewsky committed
53
			void zoomTo(int level); //level = 100 -> actual size
54
		protected:
55 56
			virtual void keyPressEvent(QKeyEvent* event);
			virtual void keyReleaseEvent(QKeyEvent* event);
57
			virtual void mouseMoveEvent(QMouseEvent* event);
58
			virtual void mousePressEvent(QMouseEvent* event);
59
			virtual void mouseReleaseEvent(QMouseEvent* event);
60
			virtual void wheelEvent(QWheelEvent* event);
61
		Q_SIGNALS:
Stefan Majewsky's avatar
Stefan Majewsky committed
62
			void zoomLevelChanged(int level);
63
			void zoomAdjustable(bool adjustable);
64
		private Q_SLOTS:
Stefan Majewsky's avatar
Stefan Majewsky committed
65
			void puzzleStarted();
66
			void startVictoryAnimation();
67
		private:
68
			Palapeli::InteractorManager* m_interactorManager;
69
			Palapeli::Scene* m_scene;
70
			Palapeli::TextureHelper* m_txHelper;
71
			QPointF m_dragPrevPos;
Stefan Majewsky's avatar
Stefan Majewsky committed
72
			int m_zoomLevel;
73 74 75 76
	};
}

#endif // PALAPELI_VIEW_H