/******************************************************/
/*                                                    */
/*  this class creates the application windows :      */
/*  - the main window where composants are drawn,     */
/*  - the parameters window,                          */
/*  - and the informations window.                    */
/*                                                    */
/******************************************************/


#ifndef WINDOW_H
#define WINDOW_H


#include <iostream>
#include <cmath>
#include <sstream>
#include <qstring.h>
#include <qapplication.h>
#include <qmetaobject.h>
#include <qmenu.h>
#include <qmenubar.h>
#include <qmainwindow.h>
#include <qwidget.h>
#include <qboxlayout.h> 
#include <qpainter.h>
#include <qcolor.h>
#include <qlabel.h>
#include <qstatusbar.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qlineedit.h>
#include <qwindowsstyle.h>
#include <qplastiquestyle.h>
#include <qlist.h>
#include <qrect.h>
#include <string.h>
#include <qtreeview.h>
#include <qdirmodel.h>
#include <qevent.h>


#include "Tools/Viewer/Parser/include/parser.h"


#define NORTH 0
#define SOUTH 1
#define EAST 2
#define WEST 3

#define MARGEX 50
#define MARGEY 70

using namespace morpheo::tools::viewer::parser;
using namespace morpheo::tools::viewer::bdd;
using namespace std;

namespace morpheo{
  namespace tools{
    namespace viewer{
      namespace graphics{

class Window : public QMainWindow
{
  
  Q_OBJECT

 public:

  Window(QString name);
  void _setParse(Parse *p);  //parse the base
  void _init_file();    //search component and port before drawing
 private slots:
    
  void _open(); //open a file
  void _open_end();
  void _open_error();

  void _save(); //save a file
  void _saveAs();
  void _saveAsOk();

  void _close(); //close a file

  void _quit(); //quit a file
  void _quit2();

  void _zoomIn(); //zoom for the architecture view
  void _zoomOut();
  void _defautZoom();

  void _level();  
  void _informations(); //show or hide informations window
  void _parameters(); //show or hide parameters window
  void _about(); //about the programm
  void _component_name(); //show or hide the components name
  void _signal_name(); //show or hide the signals name

  void _back();

 protected :
  void mousePressEvent (QMouseEvent *); //mouse handler
 
 private :
  void wparameters(); // parameters window builder
  void winformations(); //informations window builder
  void paintEvent( QPaintEvent * ); //drawing panel
  void repaint(); //repaint the panel with current parameters
  void drawPort(int x,int y,int pos,string dir); //draw the components ports
  void write_name(string name); //write the name of the component clicked name in the informations window
  void write_position(int x, int y);//write the position of the position clicked in the informations window
  void write_size(int x, int y);//write the size of the component clicked in the informations window
  void write_ports(int x);//write the number of the component clicked in the informations window

  QList <Port> port_east; //ports lists
  QList <Port> port_west;
  QList <Port> port_north;
  QList <Port> port_south;
  QList <Component> *compo;

  QWidget *wparam;//windows widget (informations, parameters, open, save ...)
  QWidget *winfo;
  QWidget *ws;
  QWidget *wq;
  QWidget *wo;
  QWidget *wa;

  QWidget *mess_charg;
  QWidget *mess;
  QBoxLayout *informations; //informations box
  QBoxLayout *parameters; //parameters box

  Parse *parse; //the parser
  BaseV *base; //the current BaseV
  BaseP p; //the current BaseP
  Entity *entity; //entity of current base
  Coord *c; 
 
  QPainter painter;

  QStatusBar *status;

  QLineEdit *file_name; //retrieve the name user wants to open from the open window
  QString current_name; //name of the current file opened

  /*items of the informations window*/
  QLabel *lname; //name of the component clicked
  QLineEdit *positionX; //x position
  QLineEdit *positionY;//y position
  QLineEdit *sizeX;//x size
  QLineEdit *sizeY;//y size
  QLineEdit *nb_ports;

  int cpt_ports;//nb ports of component clicked

  int mouseX; //mouse position
  int mouseY;

  int window_height; //main window size
  int window_width;
  int margeX;//size of the marge
  int margeY;
  int portX;//port size, position and size of components, used when drawing the architecture
  int portY;
  int posX;
  int posY;
  int tailleX;
  int tailleY;

  QString father;//father name
  QString current;//name of the current architecture visible

  bool save_as; 
  bool first_save;
  bool info_open; //know if the informations window opened or not
  bool param_open; //know if the parameters window opened or not
  bool is_save; //know if the file has been saved
  bool paint; //(re)paint or not
  bool wq_open; //know if Quit/Open ( 2 windows possible)/Save window is open
  bool wo_open;
  bool ws_open;
  bool wa_open;
  bool quit_demand;//know if user clicked on "quit" (used for saving file before quit)
  bool file_open;//know if a file is still open (used if user wants to open another file)
  bool is_parse;//know is the base has been created
  bool signalName;//show or hide signals name
  bool componentName;//show or hide components name
  bool charg_open;//back chargement message box opened or not
  bool mess_open;//chargment message box opened or not

};
      };
    };
  };
};

#endif
