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