Exemplo n.º 1
0
 def _adjustCheciItem(self, textItem: QtWidgets.QGraphicsSimpleTextItem,
                      startPoint: QtCore.QPointF, endPoint: QtCore.QPointF):
     """
     沿着斜线向endPoint方向调整车次标签的位置。必须保证垂直方向不越界。
     """
     minY = min((startPoint.y(), endPoint.y()))
     maxY = max((startPoint.y(), endPoint.y()))
     w, h = textItem.boundingRect().width(), textItem.boundingRect().height(
     )
     if endPoint.x() == startPoint.x():
         # 斜率不存在的特殊情况
         dx = 0
         dy = h
     elif endPoint.y() == startPoint.y():
         # k=0的特殊情况
         dy = h
         dx = w
     else:
         k = (endPoint.y() - startPoint.y()) / (endPoint.x() -
                                                startPoint.x())
         dy = h
         dx = dy / k
     if endPoint.y() < startPoint.y():
         dy = -dy
         dx = -dx
     x, y = textItem.x(), textItem.y()
     while minY <= y <= maxY:
         for item in textItem.collidingItems():
             if isinstance(item, QtWidgets.QGraphicsSimpleTextItem):
                 x += dx
                 y += dy
                 textItem.setPos(x, y)
                 break
         else:
             break
Exemplo n.º 2
0
 def _adjustTimeItem(self, textItem: QtWidgets.QGraphicsSimpleTextItem,
                     scale: int):
     """
     向远离运行线的方向调整冲突的始发终到时刻标签的位置。scale为正负1,表示移动方向。
     """
     w, h = textItem.boundingRect().width(), textItem.boundingRect().height(
     )
     y = textItem.y()
     dy = h * scale
     while 0 <= y <= self.sizes["height"] - h:
         for item in textItem.collidingItems():
             if isinstance(item, QtWidgets.QGraphicsSimpleTextItem):
                 y += dy
                 textItem.setY(y)
                 break
         else:
             break