|
@@ -2,7 +2,6 @@ from qtpy import QtCore
|
|
|
from qtpy import QtGui
|
|
|
from qtpy import QtWidgets
|
|
|
|
|
|
-from labelme.compat import QPoint
|
|
|
from labelme.compat import QT5
|
|
|
from labelme.lib import distance
|
|
|
from labelme.shape import Shape
|
|
@@ -21,7 +20,7 @@ CURSOR_GRAB = QtCore.Qt.OpenHandCursor
|
|
|
|
|
|
class Canvas(QtWidgets.QWidget):
|
|
|
|
|
|
- zoomRequest = QtCore.Signal(int, QPoint)
|
|
|
+ zoomRequest = QtCore.Signal(int, QtCore.QPoint)
|
|
|
scrollRequest = QtCore.Signal(int, int)
|
|
|
newShape = QtCore.Signal()
|
|
|
selectionChanged = QtCore.Signal(bool)
|
|
@@ -44,9 +43,9 @@ class Canvas(QtWidgets.QWidget):
|
|
|
self.selectedShapeCopy = None
|
|
|
self.lineColor = QtGui.QColor(0, 0, 255)
|
|
|
self.line = Shape(line_color=self.lineColor)
|
|
|
- self.prevPoint = QPoint()
|
|
|
- self.prevMovePoint = QPoint()
|
|
|
- self.offsets = QPoint(), QPoint()
|
|
|
+ self.prevPoint = QtCore.QPoint()
|
|
|
+ self.prevMovePoint = QtCore.QPoint()
|
|
|
+ self.offsets = QtCore.QPoint(), QtCore.QPoint()
|
|
|
self.scale = 1.0
|
|
|
self.pixmap = QtGui.QPixmap()
|
|
|
self.visible = {}
|
|
@@ -344,7 +343,7 @@ class Canvas(QtWidgets.QWidget):
|
|
|
y1 = rect.y() - point.y()
|
|
|
x2 = (rect.x() + rect.width()) - point.x()
|
|
|
y2 = (rect.y() + rect.height()) - point.y()
|
|
|
- self.offsets = QPoint(x1, y1), QPoint(x2, y2)
|
|
|
+ self.offsets = QtCore.QPoint(x1, y1), QtCore.QPoint(x2, y2)
|
|
|
|
|
|
def boundedMoveVertex(self, pos):
|
|
|
index, shape = self.hVertex, self.hShape
|
|
@@ -358,11 +357,11 @@ class Canvas(QtWidgets.QWidget):
|
|
|
return False # No need to move
|
|
|
o1 = pos + self.offsets[0]
|
|
|
if self.outOfPixmap(o1):
|
|
|
- pos -= QPoint(min(0, o1.x()), min(0, o1.y()))
|
|
|
+ pos -= QtCore.QPoint(min(0, o1.x()), min(0, o1.y()))
|
|
|
o2 = pos + self.offsets[1]
|
|
|
if self.outOfPixmap(o2):
|
|
|
- pos += QPoint(min(0, self.pixmap.width() - o2.x()),
|
|
|
- min(0, self.pixmap.height() - o2.y()))
|
|
|
+ pos += QtCore.QPoint(min(0, self.pixmap.width() - o2.x()),
|
|
|
+ min(0, self.pixmap.height() - o2.y()))
|
|
|
# XXX: The next line tracks the new position of the cursor
|
|
|
# relative to the shape, but also results in making it
|
|
|
# a bit "shaky" when nearing the border and allows it to
|
|
@@ -407,7 +406,7 @@ class Canvas(QtWidgets.QWidget):
|
|
|
# Try to move in one direction, and if it fails in another.
|
|
|
# Give up if both fail.
|
|
|
point = shape[0]
|
|
|
- offset = QPoint(2.0, 2.0)
|
|
|
+ offset = QtCore.QPoint(2.0, 2.0)
|
|
|
self.calculateOffsets(shape, point)
|
|
|
self.prevPoint = point
|
|
|
if not self.boundedMoveShape(shape, point - offset):
|
|
@@ -452,7 +451,7 @@ class Canvas(QtWidgets.QWidget):
|
|
|
aw, ah = area.width(), area.height()
|
|
|
x = (aw - w) / (2 * s) if aw > w else 0
|
|
|
y = (ah - h) / (2 * s) if ah > h else 0
|
|
|
- return QPoint(x, y)
|
|
|
+ return QtCore.QPoint(x, y)
|
|
|
|
|
|
def outOfPixmap(self, p):
|
|
|
w, h = self.pixmap.width(), self.pixmap.height()
|
|
@@ -491,10 +490,10 @@ class Canvas(QtWidgets.QWidget):
|
|
|
if (x, y) == (x1, y1):
|
|
|
# Handle cases where previous point is on one of the edges.
|
|
|
if x3 == x4:
|
|
|
- return QPoint(x3, min(max(0, y2), max(y3, y4)))
|
|
|
+ return QtCore.QPoint(x3, min(max(0, y2), max(y3, y4)))
|
|
|
else: # y3 == y4
|
|
|
- return QPoint(min(max(0, x2), max(x3, x4)), y3)
|
|
|
- return QPoint(x, y)
|
|
|
+ return QtCore.QPoint(min(max(0, x2), max(x3, x4)), y3)
|
|
|
+ return QtCore.QPoint(x, y)
|
|
|
|
|
|
def intersectingEdges(self, point1, point2, points):
|
|
|
"""Find intersecting edges.
|
|
@@ -521,8 +520,8 @@ class Canvas(QtWidgets.QWidget):
|
|
|
if 0 <= ua <= 1 and 0 <= ub <= 1:
|
|
|
x = x1 + ua * (x2 - x1)
|
|
|
y = y1 + ua * (y2 - y1)
|
|
|
- m = QPoint((x3 + x4) / 2, (y3 + y4) / 2)
|
|
|
- d = distance(m - QPoint(x2, y2))
|
|
|
+ m = QtCore.QPoint((x3 + x4) / 2, (y3 + y4) / 2)
|
|
|
+ d = distance(m - QtCore.QPoint(x2, y2))
|
|
|
yield d, i, (x, y)
|
|
|
|
|
|
# These two, along with a call to adjustSize are required for the
|