71 |
71 |
72 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
72 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
73 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
73 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
74 |
74 |
75 if topToBottom: |
75 if topToBottom: |
76 self.calculateEndingPoints = self.__calculateEndingPoints_topToBottom |
76 self.calculateEndingPoints = \ |
|
77 self.__calculateEndingPoints_topToBottom |
77 else: |
78 else: |
78 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
79 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
79 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
80 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
80 |
81 |
81 self.itemA = itemA |
82 self.itemA = itemA |
91 self.itemA.addAssociation(self) |
92 self.itemA.addAssociation(self) |
92 self.itemB.addAssociation(self) |
93 self.itemB.addAssociation(self) |
93 |
94 |
94 def __mapRectFromItem(self, item): |
95 def __mapRectFromItem(self, item): |
95 """ |
96 """ |
96 Private method to map item's rectangle to this item's coordinate system. |
97 Private method to map item's rectangle to this item's coordinate |
|
98 system. |
97 |
99 |
98 @param item reference to the item to be mapped (QGraphicsRectItem) |
100 @param item reference to the item to be mapped (QGraphicsRectItem) |
99 @return item's rectangle in local coordinates (QRectF) |
101 @return item's rectangle in local coordinates (QRectF) |
100 """ |
102 """ |
101 rect = item.rect() |
103 rect = item.rect() |
235 |
237 |
236 self.__updateEndPoint(self.regionB, False) |
238 self.__updateEndPoint(self.regionB, False) |
237 |
239 |
238 def __findPointRegion(self, rect, posX, posY): |
240 def __findPointRegion(self, rect, posX, posY): |
239 """ |
241 """ |
240 Private method to find out, which region of rectangle rect contains the point |
242 Private method to find out, which region of rectangle rect contains |
241 (PosX, PosY) and returns the region number. |
243 the point (PosX, PosY) and returns the region number. |
242 |
244 |
243 @param rect rectangle to calculate the region for (QRectF) |
245 @param rect rectangle to calculate the region for (QRectF) |
244 @param posX x position of point (float) |
246 @param posX x position of point (float) |
245 @param posY y position of point (float) |
247 @param posY y position of point (float) |
246 @return the calculated region number<br /> |
248 @return the calculated region number<br /> |
348 else: |
350 else: |
349 self.setEndPoint(px, py) |
351 self.setEndPoint(px, py) |
350 |
352 |
351 def __findRectIntersectionPoint(self, item, p1, p2): |
353 def __findRectIntersectionPoint(self, item, p1, p2): |
352 """ |
354 """ |
353 Private method to find the intersetion point of a line with a rectangle. |
355 Private method to find the intersetion point of a line with a |
|
356 rectangle. |
354 |
357 |
355 @param item item to check against |
358 @param item item to check against |
356 @param p1 first point of the line (QPointF) |
359 @param p1 first point of the line (QPointF) |
357 @param p2 second point of the line (QPointF) |
360 @param p2 second point of the line (QPointF) |
358 @return the intersection point (QPointF) |
361 @return the intersection point (QPointF) |
477 |
480 |
478 pt.setY((b2 - b1) / (slope1 - slope2)) |
481 pt.setY((b2 - b1) / (slope1 - slope2)) |
479 pt.setX(slope1 * pt.y() + b1) |
482 pt.setX(slope1 * pt.y() + b1) |
480 # the intersection point must be inside the segment (x1, y1) (x2, y2) |
483 # the intersection point must be inside the segment (x1, y1) (x2, y2) |
481 if x2 >= x1 and y2 >= y1: |
484 if x2 >= x1 and y2 >= y1: |
482 if not ((x1 <= pt.y() and pt.y() <= x2) and (y1 <= pt.x() and pt.x() <= y2)): |
485 if not ((x1 <= pt.y() and pt.y() <= x2) and |
|
486 (y1 <= pt.x() and pt.x() <= y2)): |
483 pt.setX(-1.0) |
487 pt.setX(-1.0) |
484 pt.setY(-1.0) |
488 pt.setY(-1.0) |
485 elif x2 < x1 and y2 >= y1: |
489 elif x2 < x1 and y2 >= y1: |
486 if not ((x2 <= pt.y() and pt.y() <= x1) and (y1 <= pt.x() and pt.x() <= y2)): |
490 if not ((x2 <= pt.y() and pt.y() <= x1) and |
|
491 (y1 <= pt.x() and pt.x() <= y2)): |
487 pt.setX(-1.0) |
492 pt.setX(-1.0) |
488 pt.setY(-1.0) |
493 pt.setY(-1.0) |
489 elif x2 >= x1 and y2 < y1: |
494 elif x2 >= x1 and y2 < y1: |
490 if not ((x1 <= pt.y() and pt.y() <= x2) and (y2 <= pt.x() and pt.x() <= y1)): |
495 if not ((x1 <= pt.y() and pt.y() <= x2) and |
|
496 (y2 <= pt.x() and pt.x() <= y1)): |
491 pt.setX(-1.0) |
497 pt.setX(-1.0) |
492 pt.setY(-1.0) |
498 pt.setY(-1.0) |
493 else: |
499 else: |
494 if not ((x2 <= pt.y() and pt.y() <= x1) and (y2 <= pt.x() and pt.x() <= y1)): |
500 if not ((x2 <= pt.y() and pt.y() <= x1) and |
|
501 (y2 <= pt.x() and pt.x() <= y1)): |
495 pt.setX(-1.0) |
502 pt.setX(-1.0) |
496 pt.setY(-1.0) |
503 pt.setY(-1.0) |
497 |
504 |
498 return pt |
505 return pt |
499 |
506 |