00001 #ifndef __GUI_SCENE_HPP__
00002 #define __GUI_SCENE_HPP__
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <QWidget>
00007 #include <QPolygonF>
00008 #include <QRectF>
00009 #include <QVector>
00010 #include <QImage>
00011 #include <QTextStream>
00012 #include <QGraphicsView>
00013 #include <vector>
00014 #include <QGridLayout>
00015 #include <QSpinBox>
00016 #include <QPushButton>
00017 #include <QLabel>
00018 #include <QDialog>
00019 #include <QMouseEvent>
00020 #include <QPoint>
00021 #include <QComboBox>
00022 #include "gui_animal.hpp"
00023 #include "obstacle.hpp"
00024 #include "vector2D.hpp"
00025
00026
00027 class GUI_Scene : public QGraphicsView {
00028 Q_OBJECT
00029
00030
00031 public:
00032 enum mode{NONE, ADDOBSTACLE, ADDANIMAL, REMOVE};
00033
00034 GUI_Scene(QWidget *parent = 0, qreal w=500, qreal h=500);
00035 ~GUI_Scene();
00036
00037
00038 void setEditMode(mode);
00039
00043 QWidget* getParamBox();
00044
00045 vector<GUI_Animal*> getAnimals() const;
00046
00047 GUI_Animal* getCurrAnimal() ;
00048
00049 void addToFile(ostream &F);
00050
00051
00055 void addAnimal(const Vector2D &origin = Vector2D(0,0));
00056
00057
00058 friend ostream& operator<< (ostream &Strm, const GUI_Scene &scene);
00059 friend ostream& operator<< (ostream &Strm, const vector<GUI_Animal*> &anim);
00060 friend istream & operator>> (istream &Strm, GUI_Scene &scene);
00061
00062 signals:
00063 void changed();
00064
00065 protected:
00066 mode _currMode;
00067
00068 void drawBackground(QPainter *, const QRectF &);
00069
00073 bool isSelectedAnimal(QPoint point);
00074
00075 virtual void mouseDoubleClickEvent(QMouseEvent *);
00076
00080 virtual void mousePressEvent(QMouseEvent *);
00081
00082 virtual void mouseMoveEvent(QMouseEvent *);
00083 virtual void mouseReleaseEvent(QMouseEvent *);
00084 virtual void keyPressEvent(QKeyEvent *);
00085
00086 void createPotentialMap();
00087 void clearPolygon();
00088 bool selectSheep(QPoint);
00089
00090 vector<GUI_Animal*> _animals;
00091 vector<Obstacle> _obstacle;
00092
00093 qreal _width;
00094 qreal _height;
00095 qreal _scale;
00096
00097 private:
00098 QImage image;
00099
00100 QWidget *_paramBox;
00101 GUI_Animal *_currAnimal;
00102 int _currObstacle;
00103
00104
00105 bool potentialMap;
00106 bool antiAliased;
00107
00108
00109 QGraphicsPolygonItem *newObstacle;
00110
00111
00115 void getParamBoxAnimal(QWidget *widget);
00116
00117
00118 };
00119
00120 ostream& operator<< (ostream &Strm, const GUI_Scene &scene);
00121 ostream& operator<< (ostream &Strm, const vector<GUI_Animal*> &anim);
00122 istream & operator>> (istream &Strm, GUI_Scene &scene);
00123
00124
00125 #endif
00126