/***************************************************************************
                          kfreerings.h  -  description
                             -------------------
    begin                : Mon Dec  3 13:47:14 CET 2001
    copyright            : (C) 2001 by Christian Hubinger
    email                : e9806056@student.tuwien.ac.at
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KFRMAIN_H
#define KFRMAIN_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
//QT Includes
#include <qlcdnumber.h>
//KDE Includes
#include <kmainwindow.h>
#include <kapp.h>
#include <qwidget.h>
#include <kaction.h>
#include <kfbutton.h>
#include <kpixmap.h>

// Project includes
#include "kfgame.h"
#include "kfhighscore.h"
class QPixmap;
class KPixmap;
class QPainter;
class QLabel;
class KPushButton;
class KHelpMenu;
class KFDialog;
class QTimer;
class QTimerEvent;
class KFHighscore;
class KFRMain : public QWidget {
	Q_OBJECT

public:
	/** construtor */
	KFRMain(QWidget* parent=0, const char *name=0);
	/** destructor */
	~KFRMain();

public slots:
	void slotFixImage();
	void crushImage();
	void slotSetImage();

private slots:
	void r1moveLeft();
	void r1moveRight();
	void r2moveLeft();
	void r2moveRight();
	void r3moveLeft();
	void r3moveRight();
	void incrementCount();
	void resetCounter();
	void slotNewGame();
	void slotStartNewGame();
	void slotNewTrainingGame();
	void slotStartTrainingGame();

/* 	void slotStartNewGame(); */
	void slotSolveGame();
	void slotQuitGame();
	void slotAbout();
	void slotAboutKDE();
	void slotHelp();
	void slotShowHelpMenu();
	void slotShowFileMenu();
	void slotShowSettingsMenu();
	void slotSetTrainingsLevel();
	void slotSetLevel();
	void slotNextLevel();
	void slotGameOver();
	void slotQuit();
	void setImage( QString file = QString::null );
	void checkForHighscore();
	void slotShowHighscores();
	void slotHideHighscores();
	void slotToggleShowHighscores();
	void slotRefreshHighscroes();
	
// 	void slotStartAnimation();
// 	void slotEndAnimation();

signals:
	void reset();

private:
	bool testFinished();
	void refreshHighscores();
	KFDialog* showKFDialog( int, const QString& );
	void drawCycle( int m_x, int m_y, int r, QPainter *, int );
	void drawCyclePie( int m_x, int m_y, int r, int angle, int length, QPainter *p, int );
	void finished();
	void paintPieces( QPainter *,int rot);
	void paintEvent( QPaintEvent * );
	void timerEvent( QTimerEvent *e );
	void paintCycles( QPainter * = 0 );
	void paintPiece ( QPixmap *, QPoint *,int, QPainter *);
	void showCycles(QPainter *);
	void paintLevelString(QPainter *);
	void paintMovesString(QPainter *);
// 	void paintGameOver(QPainter *painter);
	void fadeRings( bool );
	void startGameAnimation();
	void endGameAnimation();
	void showGameButtons( bool );
	QPixmap* getBackgroundPicScaled();
	KHelpMenu* m_helpMenu;
	KPopupMenu* m_fileMenu, *m_settingsMenu;
	QLabel* m_highscoreLabel;
	
	
	QRect cycleRect(int x,int y,int w, int h) const;
	QPixmap m,cycles, mid, midu, midl, midr;
	QPixmap r1qu1,r1qu2,r1qu3,r1qu4,r1tr1,r1tr2,r1tr3,r1tr4 ;
	QPixmap r2qu1,r2qu2,r2qu3,r2qu4,r2tr1,r2tr2,r2tr3,r2tr4;
	QPixmap r3qu1,r3qu2,r3qu3,r3qu4,r3tr1,r3tr2,r3tr3,r3tr4;
	QPixmap bg, bg_unchanged;
	QBitmap *mask;
	QTimer *m_timer;
	int m_animationStep;
	bool startUp;
	bool Repaint;
	bool m_inGame, m_wasInGame, m_inTrainigGame;
	QString bg_filename;
	QString tri_mask_filename, tri_mask_180_filename,
				qu_mask_filename, qu_mask_60_filename, qu_mask_120_filename,
				mask_ring1_filename, mask_ring2_filename, mask_ring3_filename;
	QRegion changed, m_regionRing1, m_regionRing2, m_regionRing3;
	QPoint pm_t, pm_ql,pm_qr,pm_qu; //defining the centerpoints for the pieces
	QPoint pr1_q1,pr1_q2,pr1_q3,pr1_q4,pr1_t1,pr1_t2,pr1_t3,pr1_t4;
	QPoint pr2_q1,pr2_q2,pr2_q3,pr2_q4,pr2_t1,pr2_t2,pr2_t3,pr2_t4;
	QPoint pr3_q1,pr3_q2,pr3_q3,pr3_q4,pr3_t1,pr3_t2,pr3_t3,pr3_t4;

	QPoint*	pos[28];
	QPixmap* pix[28];
	int ang[28];

	QPoint*	pos_orig[28];
	QPixmap* pix_orig[28];
	KPixmap bg_fx_chain[10];
	int ang_orig[28];
	bool m_isCrushig;
	bool m_gameOver;
	
	KFButton* r1kfl;
	KFButton* r1kfr;
	KFButton* r2kfl;
	KFButton* r2kfr;
	KFButton* r3kfl;
	KFButton* r3kfr;
	KFButton *m_newGame, *m_settings, *m_quitGame, *m_help;
	KFGame m_game;
// 	QLCDNumber* count;
	int m_neededMoves;
	int m_timerID;
	int m_currLevel;
	KFHighscore* m_highScore;
};

#endif
