roxdokuview.h 3.77 KB
Newer Older
1 2 3
/***************************************************************************
 *   Copyright 2005-2007 Francesco Rossi <redsh@email.it>                  *
 *   Copyright 2006-2007 Mick Kappenburg <ksudoku@kappendburg.net>         *
4
 *   Copyright 2006-2008 Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *                                                                         *
 *   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.,                                       *
Johannes Bergmeier's avatar
Johannes Bergmeier committed
19
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20 21
 ***************************************************************************/

Laurent Montel's avatar
Laurent Montel committed
22 23
#ifndef ROXDOKUVIEW_h
#define ROXDOKUVIEW_h
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

#include <qgl.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qimage.h>
//Added by qt3to4:
#include <QWheelEvent>
#include <QMouseEvent>
#include "sudoku_solver.h"
#include "ArcBall.h"

#include "ksudokugame.h"
#include "ksview.h"



namespace ksudoku{

class Game;
Johannes Bergmeier's avatar
Johannes Bergmeier committed
43
class Symbols;
44 45 46 47 48

/**
 * Gui for a roxdoku puzzle
 * @TODO hide private members (now public)
 */
49
class RoxdokuView : public QGLWidget, public ViewInterface
50 51 52
{
Q_OBJECT
public:
53
	RoxdokuView(ksudoku::Game game, Symbols* symbols, QWidget *parent = 0);
54 55 56
	~RoxdokuView();
public:
	///(re)implemented from KsView
57
	virtual void setGame(const ksudoku::Game& /* game*/) { /* ///@todo fixme */ }
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

	///(re)implemented from KsView
	virtual QString status() const;

	int base;
	int order;
	int size;
	char selected_number;

	bool isClicked;
	bool isRClicked;	
	bool isDragging;	
	ArcBallT*    ArcBall;	
	int selection;

	float dist;
	float wheelmove;

	GLuint  texture[2][26];
Johannes Bergmeier's avatar
Johannes Bergmeier committed
77 78
	
	bool m_guidedMode;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

public:
	void initializeGL();

	void resizeGL( int w, int h ){ //hm this won't be compiled inline I think ..??
		if(w==0)w=1;	
		if(h==0)h=1;
		ArcBall = new ArcBallT((GLfloat)w,(GLfloat)h);

		glViewport( 0, 0, (GLint)w, (GLint)h );
		glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
		glLoadIdentity();            // Reset The Projection Matrix

		gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);

		glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
		glLoadIdentity();
	}
97 98
	
	QWidget* widget() { return this; }
99
	
100
public slots:
101
	void selectValue(int value);
102
	void settingsChanged();
103 104 105 106
	
signals:
	void valueSelected(int value); // Never used but connected to
	
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
protected:
	void paintGL();
protected:
	void Selection(int mouse_x, int mouse_y);
	void mouseReleaseEvent ( QMouseEvent * e ){
		if(e->button() == Qt::LeftButton) isClicked = false;
	}
	void mousePressEvent ( QMouseEvent * e ){
		if(e->button() == Qt::LeftButton) isClicked = true;
	}	
protected:
	void myDrawCube(int n, GLfloat x, GLfloat y, GLfloat z, int texture);
	void mouseMoveEvent(QMouseEvent* e) ;
	void mouseDoubleClickEvent(QMouseEvent* e);
	void wheelEvent (QWheelEvent* e){
		wheelmove += e->delta() * .02;
		updateGL();
	}
125 126 127

private:
	void loadSettings();
Johannes Bergmeier's avatar
Johannes Bergmeier committed
128 129 130
	
private:
	Symbols* m_symbols;
Johannes Bergmeier's avatar
Johannes Bergmeier committed
131
	Game m_game;
132 133 134 135 136
};

}

#endif