Adaptively adjust label size (#678)
* Adjust label font size based on image size * Adjust the upper boundary of the painted label * Set font size based on both image width & height
This commit is contained in:
parent
0a581ef7e9
commit
5d6557f994
@ -1141,6 +1141,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
||||
def paintCanvas(self):
|
||||
assert not self.image.isNull(), "cannot paint null image"
|
||||
self.canvas.scale = 0.01 * self.zoomWidget.value()
|
||||
self.canvas.labelFontSize = int(0.02 * max(self.image.width(), self.image.height()))
|
||||
self.canvas.adjustSize()
|
||||
self.canvas.update()
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ class Canvas(QWidget):
|
||||
self.prevPoint = QPointF()
|
||||
self.offsets = QPointF(), QPointF()
|
||||
self.scale = 1.0
|
||||
self.labelFontSize = 8
|
||||
self.pixmap = QPixmap()
|
||||
self.visible = {}
|
||||
self._hideBackround = False
|
||||
@ -478,6 +479,7 @@ class Canvas(QWidget):
|
||||
|
||||
p.drawPixmap(0, 0, self.pixmap)
|
||||
Shape.scale = self.scale
|
||||
Shape.labelFontSize = self.labelFontSize
|
||||
for shape in self.shapes:
|
||||
if (shape.selected or not self._hideBackround) and self.isVisible(shape):
|
||||
shape.fill = shape.selected or shape == self.hShape
|
||||
|
||||
@ -18,7 +18,6 @@ DEFAULT_SELECT_LINE_COLOR = QColor(255, 255, 255)
|
||||
DEFAULT_SELECT_FILL_COLOR = QColor(0, 128, 255, 155)
|
||||
DEFAULT_VERTEX_FILL_COLOR = QColor(0, 255, 0, 255)
|
||||
DEFAULT_HVERTEX_FILL_COLOR = QColor(255, 0, 0)
|
||||
MIN_Y_LABEL = 10
|
||||
|
||||
|
||||
class Shape(object):
|
||||
@ -37,6 +36,7 @@ class Shape(object):
|
||||
point_type = P_ROUND
|
||||
point_size = 8
|
||||
scale = 1.0
|
||||
labelFontSize = 8
|
||||
|
||||
def __init__(self, label=None, line_color=None, difficult=False, paintLabel=False):
|
||||
self.label = label
|
||||
@ -115,18 +115,19 @@ class Shape(object):
|
||||
if self.paintLabel:
|
||||
min_x = sys.maxsize
|
||||
min_y = sys.maxsize
|
||||
min_y_label = int(1.25 * self.labelFontSize)
|
||||
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.setPointSize(self.labelFontSize)
|
||||
font.setBold(True)
|
||||
painter.setFont(font)
|
||||
if(self.label == None):
|
||||
self.label = ""
|
||||
if(min_y < MIN_Y_LABEL):
|
||||
min_y += MIN_Y_LABEL
|
||||
if(min_y < min_y_label):
|
||||
min_y += min_y_label
|
||||
painter.drawText(min_x, min_y, self.label)
|
||||
|
||||
if self.fill:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user