Line.h
Go to the documentation of this file.
00001 #ifndef LINE_H
00002 #define LINE_H
00003 #include <QtGui>
00004 
00005 // Constants necessary for the position of the lines in the wrist widget
00006 const int WRIST_X = 48;
00007 const int WRIST_Y = 48;
00008 const int WRIST_CENTER_X = WRIST_X / 2;
00009 const int WRIST_CENTER_Y = WRIST_Y / 2;
00010 const int WRIST_CIRCLE_RADIUS = WRIST_X / 4;
00011 const int WRIST_WIDTH = WRIST_X * 9 / 10;
00012 const int WRIST_HEIGHT = WRIST_Y / 5;
00013 const int WRIST_LINE_WIDTH = 3;
00014 
00015 class Line : public QGraphicsLineItem
00016 {
00017 public:
00018     Line(int x1, int y1, int x2, int y2) : QGraphicsLineItem(x1,y1,x2,y2)
00019 
00020   {
00021     rotation = 0;
00022 
00023   }
00024 
00025   void mousePressEvent(QGraphicsSceneMouseEvent *event)
00026   {
00027     initialPos = mapToScene(event->pos());
00028     QGraphicsItem::mousePressEvent(event);
00029   }
00030 
00031   void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
00032         // calculate the rotation angle the user want the line to be at and draw the line with the new rotation angle
00033   {
00034 
00035       //rotate around the center of the line
00036 
00037     QPointF pos = mapToScene(event->pos());
00038 
00039     int x1 = initialPos.x()- WRIST_CENTER_X;
00040     int x2 = pos.x()- WRIST_CENTER_X;
00041     int y1 = initialPos.y()- WRIST_CENTER_Y;
00042     int y2 = pos.y()- WRIST_CENTER_Y;
00043 
00044     rotation +=  (atan2(y2,x2) - atan2(y1,x1))/M_PI*180;
00045 
00046 
00047     setRotation(rotation);
00048     initialPos = pos;
00049   }
00050   QPointF initialPos;
00051   qreal rotation;
00052 
00053 };
00054 #endif // LINE_H


corobot_teleop
Author(s):
autogenerated on Sun Oct 5 2014 23:18:16