개정판 659c2065
issue #000: change zoom out with wheel to fit with mouse position
Change-Id: Ia1704975b8559e627c14a7f81d41bb95205a85cb
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
219 | 219 |
''' |
220 | 220 |
@history 2018.06.27 Jeongwoo Change zoom rule (Qt.KeepAspectRatioByExpanding → Qt.KeepAspectRatio) |
221 | 221 |
''' |
222 |
def updateViewer(self): |
|
222 |
def updateViewer(self, zoomNewRect=None):
|
|
223 | 223 |
""" Show current zoom (if showing entire image, apply current aspect ratio mode). |
224 | 224 |
""" |
225 | 225 |
if not self.hasImage(): |
226 | 226 |
return |
227 | 227 |
if len(self.zoomStack):# and self.sceneRect().contains(self.zoomStack[-1]): |
228 |
self.fitInView(self.zoomStack[-1], Qt.KeepAspectRatio) # Show zoomed rect (ignore aspect ratio). |
|
228 |
if zoomNewRect is None: |
|
229 |
self.fitInView(self.zoomStack[-1], Qt.KeepAspectRatio) # Show zoomed rect (ignore aspect ratio). |
|
230 |
else: |
|
231 |
self.fitInView(zoomNewRect, Qt.KeepAspectRatio) |
|
229 | 232 |
else: |
230 | 233 |
self.zoomStack = [] # Clear the zoom stack (in case we got here because of an invalid zoom). |
231 | 234 |
self.fitInView(self.sceneRect(), self.aspectRatioMode) # Show entire image (use current aspect ratio mode). |
... | ... | |
261 | 264 |
self.zoomStack.append(selectionBBox) |
262 | 265 |
self.updateViewer() |
263 | 266 |
else: |
267 |
zoomNewRect = None |
|
264 | 268 |
self.scene.setSelectionArea(QPainterPath()) # Clear current selection area. |
265 | 269 |
if len(self.zoomStack): |
266 | 270 |
self.zoomStack.pop() |
267 |
self.updateViewer() |
|
271 |
if len(self.zoomStack): |
|
272 |
newScenePos = self.mapToScene(clickPos.x(), clickPos.y()) |
|
273 |
newPosX1 = newScenePos.x() - self.zoomStack[-1].width() / 2 |
|
274 |
newPosY1 = newScenePos.y() - self.zoomStack[-1].height() / 2 |
|
275 |
zoomNewPos1 = QPointF(newPosX1 if newPosX1 > 0 else 0, newPosY1 if newPosY1 > 0 else 0) |
|
276 |
newPosX2 = newScenePos.x() + self.zoomStack[-1].width() / 2 |
|
277 |
newPosY2 = newScenePos.y() + self.zoomStack[-1].width() / 2 |
|
278 |
zoomNewPos2 = QPointF(newPosX2, newPosY2) |
|
279 |
zoomNewRect = QRectF(zoomNewPos1, zoomNewPos2) |
|
280 |
self.updateViewer(zoomNewRect) |
|
268 | 281 |
|
269 | 282 |
def resizeEvent(self, event): |
270 | 283 |
""" Maintain current zoom on resize. |
내보내기 Unified diff