diff --git a/beeref/items.py b/beeref/items.py index 699a98c..91ed85b 100644 --- a/beeref/items.py +++ b/beeref/items.py @@ -43,6 +43,8 @@ class BeePixmapItem(QtWidgets.QGraphicsPixmapItem): | QtWidgets.QGraphicsItem.GraphicsItemFlags.ItemIsSelectable) def setScale(self, factor): + if factor <= 0: + return self.scale_factor = factor logger.debug(f'Setting scale for image "{self.filename}" to {factor}') super().setScale(factor) diff --git a/beeref/selection.py b/beeref/selection.py index ac1a491..372cafc 100644 --- a/beeref/selection.py +++ b/beeref/selection.py @@ -40,6 +40,7 @@ class SelectionItem(QtWidgets.QGraphicsItem): | QtWidgets.QGraphicsItem.GraphicsItemFlags.ItemIsMovable) bounds = self.parentItem().boundingRect() pos = bounds.bottomRight() + self.scale_active = False # The intercatable shape of the bottom right scale handle: self.bottom_right_scale_bounds = QtCore.QRectF( @@ -100,10 +101,21 @@ class SelectionItem(QtWidgets.QGraphicsItem): self.setCursor(Qt.CursorShape.ArrowCursor) def mousePressEvent(self, event): - print('********mousepress') + if event.button() == Qt.MouseButtons.LeftButton: + self.scale_active = True + self.orig_scale_factor = self.parentItem().scale() + self.scale_start = event.scenePos() def mouseMoveEvent(self, event): - print('*******mousemove') + if self.scale_active: + imgsize = self.parentItem().width + self.parentItem().height + p = event.scenePos() - self.scale_start + mousemove = p.x() + p.y() + scale = self.orig_scale_factor + mousemove / imgsize + self.parentItem().setScale(scale) + + def mouseReleaseEvent(self, event): + self.scale_active = False @classmethod def activate_selection(cls, item):