124 @param change the item's change (QGraphicsItem.GraphicsItemChange) |
124 @param change the item's change (QGraphicsItem.GraphicsItemChange) |
125 @param value the value of the change |
125 @param value the value of the change |
126 @return adjusted values |
126 @return adjusted values |
127 """ |
127 """ |
128 if change == QGraphicsItem.ItemPositionChange: |
128 if change == QGraphicsItem.ItemPositionChange: |
|
129 # 1. remember to adjust associations |
129 self.shouldAdjustAssociations = True |
130 self.shouldAdjustAssociations = True |
|
131 |
|
132 # 2. ensure the new position is inside the scene |
|
133 rect = self.scene().sceneRect() |
|
134 if not rect.contains(value): |
|
135 # keep the item inside the scene |
|
136 value.setX(min(rect.right(), max(value.x(), rect.left()))) |
|
137 value.setY(min(rect.bottom(), max(value.y(), rect.top()))) |
|
138 return value |
|
139 |
130 return QGraphicsItem.itemChange(self, change, value) |
140 return QGraphicsItem.itemChange(self, change, value) |
131 |
141 |
132 def paint(self, painter, option, widget=None): |
142 def paint(self, painter, option, widget=None): |
133 """ |
143 """ |
134 Public method to paint the item in local coordinates. |
144 Public method to paint the item in local coordinates. |