view.h 2.43 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 29 30 31 32
	class Scene;

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

37
			Palapeli::InteractorManager* interactorManager() const;
38
			Palapeli::Scene* scene() const;
Stefan Majewsky's avatar
Stefan Majewsky committed
39

40 41 42
			QRectF viewportRect() const;
			void setViewportRect(const QRectF& viewportRect);

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

48
			void moveViewportBy(const QPointF& sceneDelta);
49 50 51
			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
52
			void zoomTo(int level); //level = 100 -> actual size
53
		protected:
54 55
			virtual void keyPressEvent(QKeyEvent* event);
			virtual void keyReleaseEvent(QKeyEvent* event);
56
			virtual void mouseMoveEvent(QMouseEvent* event);
57
			virtual void mousePressEvent(QMouseEvent* event);
58
			virtual void mouseReleaseEvent(QMouseEvent* event);
59
			virtual void wheelEvent(QWheelEvent* event);
60
		Q_SIGNALS:
Stefan Majewsky's avatar
Stefan Majewsky committed
61
			void zoomLevelChanged(int level);
62
			void zoomAdjustable(bool adjustable);
63
		private Q_SLOTS:
Stefan Majewsky's avatar
Stefan Majewsky committed
64
			void puzzleStarted();
65
			void startVictoryAnimation();
66
		private:
67
			Palapeli::InteractorManager* m_interactorManager;
68
			Palapeli::Scene* m_scene;
69
			QPointF m_dragPrevPos;
Stefan Majewsky's avatar
Stefan Majewsky committed
70
			int m_zoomLevel;
71 72 73 74
	};
}

#endif // PALAPELI_VIEW_H