2 * SmallRobot.cpp 07/12/04
4 * Draw a small robot on the playground.
6 * Copyright: (c) 2007 CTU Dragons
7 * CTU FEE - Department of Control Engineering
8 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
13 #include <QGraphicsScene>
15 #include <QStyleOption>
18 #include "SmallRobot.h"
20 SmallRobot::SmallRobot()
25 SmallRobot::SmallRobot(QColor color)
30 QRectF SmallRobot::boundingRect() const
33 return QRectF(-18 - adjust, -22 - adjust, 36 + adjust, 60 + adjust);
36 void SmallRobot::setParent(QWidget *parent)
38 /* used to update after the robot's replacement */
39 this->parent = parent;
40 connect(this, SIGNAL(robotMovedSignal()), parent, SLOT(robotMoved()));
43 void SmallRobot::paint(QPainter *painter,
44 const QStyleOptionGraphicsItem *, QWidget *)
46 painter->setBrush(color);
47 painter->drawEllipse((int)(5 + -10/2.0), (int)(-10/2.0),
49 painter->drawLine(5, 0, 25, 0);
52 void SmallRobot::init()
54 setFlag(ItemIsMovable);
58 void SmallRobot::move()
60 QPointF position = pos();
62 mclPart->x = (qreal)(position.x() /
63 widgetSize.width() * playgroundSize.width());
64 mclPart->y = (qreal)((widgetSize.height() - position.y()) /
65 widgetSize.height() * playgroundSize.height());
67 emit robotMovedSignal();
71 void SmallRobot::updateRobot()
74 rotate(RAD2DEG(-mclPart->angle));
75 setPos((qreal)(mclPart->x / playgroundSize.width() * widgetSize.width()),
76 (qreal)((playgroundSize.height() - mclPart->y)
77 / playgroundSize.height() * widgetSize.height()));
79 //FIXME: I do not know how calculate thetas here. Michal
80 //mcl_pos2ang(&mclPart, theta, mcl.beacon_cnt, mcl.beacon_color);
81 setToolTip(QString("X=%1 Y=%2\nangle=%3\n"
83 // "\nth1=%5\nth2=%6\nth3=%7\nth4=%8"
85 .arg(mclPart->x, 0, 'f', 3)
86 .arg(mclPart->y, 0, 'f', 3)
87 .arg(RAD2DEG(mclPart->angle), 0, 'f', 3)
88 // .arg(mclPart->weight, 0, 'f', 5)
89 // .arg(RAD2DEG(mclPart->theta[0]), 0, 'f', 3)
90 // .arg(RAD2DEG(mclPart->theta[1]), 0, 'f', 3)
91 // .arg(RAD2DEG(mclPart->theta[2]), 0, 'f', 3)
92 // .arg(RAD2DEG(mclPart->theta[3]), 0, 'f', 3)
95 // int col = (int)(mclPart->weight * 128 + 50);
96 // col = (col > 255) ? 255 : col;
97 // col = (col < 0) ? 0 : col;
99 color = QColor(col, 40, 40);
102 QPainterPath SmallRobot::shape() const
105 path.addEllipse((int)(5 + -10/2.0), (int)(-10/2.0),
110 void SmallRobot::mousePressEvent(QGraphicsSceneMouseEvent *event)
113 QGraphicsItem::mousePressEvent(event);
116 void SmallRobot::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
120 QGraphicsItem::mouseReleaseEvent(event);