diff --git a/libs/shape.py b/libs/shape.py index 165ef599..6b67687b 100644 --- a/libs/shape.py +++ b/libs/shape.py @@ -10,6 +10,7 @@ except ImportError: from PyQt4.QtCore import * from libs.lib import distance +import sys DEFAULT_LINE_COLOR = QColor(0, 255, 0, 128) DEFAULT_FILL_COLOR = QColor(255, 0, 0, 128) @@ -107,6 +108,20 @@ class Shape(object): painter.drawPath(line_path) painter.drawPath(vrtx_path) painter.fillPath(vrtx_path, self.vertex_fill_color) + + # Draw text at the top-left + min_x = sys.maxsize + min_y = sys.maxsize + for point in self.points: + min_x = min(min_x, point.x()) + min_y = min(min_y, point.y()) + if min_x != sys.maxsize and min_y != sys.maxsize: + font = QFont() + font.setPointSize(8) + font.setBold(True) + painter.setFont(font) + painter.drawText(min_x, min_y, self.label) + if self.fill: color = self.select_fill_color if self.selected else self.fill_color painter.fillPath(line_path, color) @@ -170,7 +185,7 @@ class Shape(object): shape.line_color = self.line_color if self.fill_color != Shape.fill_color: shape.fill_color = self.fill_color - shape.difficult = self.difficult + shape.difficult = self.difficult return shape def __len__(self):