/***************************************************************************
 *   Copyright (C) 2008 by Peter Dahlberg   *
 *   pdahlberg@gmail.com   *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifndef LSIM_H
#define LSIM_H

#include <QMainWindow>
#include <QCloseEvent>
#include <graphicsview.h>

//Hauptfenster

/**
	@author Peter Dahlberg <pdahlberg@gmail.com>
*/

class QAction;
class QMenu;
class QTextEdit;
class QDockWidget;
class SimulScene;
class QActionGroup;

class lsim: public QMainWindow {
		Q_OBJECT

	public:
		enum WindowMode {EditMode,SimulationMode};
		lsim();
		~lsim();

		void setMode ( const WindowMode& theValue );
	

		lsim::WindowMode getMode() const;
	

	protected:
		void closeEvent (QCloseEvent *event);
	public slots:
		void goToFullscreen(bool yesno);

	private slots:
		void about();
		void actModeSwitcher(QAction *action);
		void actWindowModeSwitcher(QAction *action);
		void setSceneMode(int mode);
    		void updateDockFieldWidget();
		void startCalculation();
		void startTimer();
		void handleDockLocationChange();
		void handleUpDownActionChanges();
		void initWindowMode(WindowMode newMode);
		void clearAnyFocus();
		void resetAll();
		void resetAllActionSlot();

		void timeLineDurationChangeWrapperToSec(int length);
		void timeLineDurationSetWrapperToMsec(double length);

		void saveFileAs();
		void openFile();

	private:
		void createActions();
		void createMenus();
		void createToolBars();
		void createStatusBar();
		void createDocks();
		void createScene();

		void displayOpenFailedBox();

		GraphicsView *gview;

		QMenu *fileMenu;
		QMenu *editMenu;
		QMenu *helpMenu;
		QMenu *viewMenu;

		QToolBar *timerControlBar;
		QToolBar *sceneModeBar;
		QToolBar *upDownBar;
		QToolBar *windowModeBar;

		struct Actions {
			QAction *aboutAct;
			QAction *exitAct;
			QAction *aboutQtAct;
			QAction *oglEnable;
			QAction *oglDisable;
			QAction *calculate;
			QAction *timerStart;
			QAction *timerStop;
			QAction *timerPause;

			QAction *fileSaveAsAct;
			QAction *fileOpenAct;

			QAction *moveItemDown;
			QAction *moveItemUp;
			QAction *moveItemOnTop;
			QAction *moveItemOnBottom;

			QAction *editModeAct;
			QAction *simulationModeAct;

			QAction *itemEditModeAct;
			QAction *insertEFieldItemAct;
			QAction *insertBFieldItemAct;
			QAction *insertStopperItemAct;
			QAction *probeChargeItemPlaceAct;

			QAction *resetAct;
			QAction *fullScreenAct;
			QAction *centerOnProbeAct;
		};
		Actions acts;

		QActionGroup *modeChangeActGroup;
		QActionGroup *windowModeActGroup;



		QDockWidget *fieldItemEditDock;	
		QDockWidget *probeItemDock;
		QDockWidget *sceneDock;
		QDockWidget *simulOptDock;
		QDockWidget *simulDataDock;


		SimulScene *simulscene;
		
		WindowMode myMode;
	signals:
		void windowModeChanged(WindowMode mode);
		void timeLineDurationChangedSec(double duration);
		void fullScreenModeChanged(bool mode);
};

#endif
