playgroundscene.cpp

00001 //
00002 // C++ Implementation: playgroundscene
00003 //
00004 // Description: 
00005 //
00006 //
00007 // Author: Martin Zidek,,, <martin@martin-laptop>, (C) 2007
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #include "playgroundscene.h"
00013 #include <QPointF>
00014 #include <QGraphicsSceneMouseEvent>
00015 #include <QGraphicsScene>
00016 #include <QGraphicsRectItem>
00017 #include "robomon.h"
00018 
00019 PlaygroundScene::PlaygroundScene(QObject *parent)
00020  : QGraphicsScene(parent)
00021 {
00022     QGraphicsRectItem *tempRect;
00023     setSceneRect(0,0,615,430);
00024 
00025         //Okraj hriste
00026     addLine(QLineF(TOP_LEFT,TOP_MIDDLE),QPen(QBrush(Qt::red),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00027     addLine(QLineF(TOP_MIDDLE,TOP_RIGHT),QPen(QBrush(Qt::blue),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00028     addLine(QLineF(TOP_LEFT,BOTTOM_LEFT),QPen(QBrush(Qt::red),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00029     addLine(QLineF(BOTTOM_LEFT,BOTTOM_MIDDLE),QPen(QBrush(Qt::red),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00030     addLine(QLineF(BOTTOM_MIDDLE,BOTTOM_RIGHT),QPen(QBrush(Qt::blue),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00031     addLine(QLineF(BOTTOM_RIGHT,TOP_RIGHT),QPen(QBrush(Qt::blue),2,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00032 
00033         //Kose vlevo dole
00034     addLine(QLineF(BIN_LEFT_BOTTLE_START,BIN_LEFT_BOTTLE_END),QPen(QBrush(Qt::red),10,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00035     addLine(QLineF(BIN_LEFT_CAN_START,BIN_LEFT_CAN_END),QPen(QBrush(Qt::red),10,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00036 
00037         //Kose vpravo dole
00038     addLine(QLineF(BIN_RIGHT_BOTTLE_START,BIN_RIGHT_BOTTLE_END),QPen(QBrush(Qt::blue),10,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00039     addLine(QLineF(BIN_RIGHT_CAN_START,BIN_RIGHT_CAN_END),QPen(QBrush(Qt::blue),10,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin));
00040 
00041         //Plocha
00042     tempRect = addRect(QRectF(11,1,597,417),QPen(QBrush(Qt::lightGray),1,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin),QBrush(Qt::lightGray));
00043     tempRect->setZValue(1);
00044 
00045         //Modre startovni pole
00046     tempRect = addRect(QRectF(11,1,100,100),QPen(QBrush(Qt::blue),1,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin),QBrush(Qt::blue));
00047     tempRect->setZValue(3);
00048 
00049         //Cervene startovni pole
00050     tempRect = addRect(QRectF(508,1,100,100),QPen(QBrush(Qt::red),1,Qt::SolidLine,Qt::FlatCap,Qt::BevelJoin),QBrush(Qt::red));
00051     tempRect->setZValue(3);
00052 
00053     obstacle = new QGraphicsEllipseItem(0, 0, 10, 10);
00054     obstacle->setZValue(5);
00055     obstacle->setBrush(QBrush(Qt::blue));
00056     obstacle->setVisible(false);
00057     this->addItem(obstacle);
00058 }
00059 
00060 
00061 PlaygroundScene::~PlaygroundScene()
00062 {
00063 }
00064 
00065 void PlaygroundScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
00066 {
00067     QGraphicsScene::mousePressEvent(mouseEvent);
00068     QPointF pos = scene2world(mouseEvent->scenePos());
00069     obstacle->setPos(mouseEvent->scenePos().x()-5, mouseEvent->scenePos().y()-5);
00070     obstacleChanged(pos);
00071 }
00072 
00073 
00074 
00078 QPointF PlaygroundScene::scene2world(QPointF scenePos)
00079 {
00080     return QPointF((scenePos.x()-10)/200.0, (420-scenePos.y()+1)/200.0);
00081 }
00082 
00083 
00087 QPointF PlaygroundScene::world2scene(QPointF worldPos)
00088 {
00089     return QPointF(worldPos.x()*200+10, 1+420-worldPos.y());
00090 }
00091 
00092 
00096 void PlaygroundScene::showObstacle(int val)
00097 {
00098     if (val)
00099         obstacle->setVisible(true);
00100     else
00101         obstacle->setVisible(false);
00102 
00103 }

Generated on Thu Sep 13 11:28:28 2007 for DCE-Eurobot by  doxygen 1.5.3