def itemRegion(self, index): if not index.isValid() or not self.model(): return QRegion() return QRegion() # TODO: what to do with this code? if index.column != 1: return self.itemRect(index) if self.model().data(index).toDouble()[0] <= 0.0: return QRegion() startAngle = 0.0 for row in xrange(self.model().rowCount(self.rootIndex())): sliceIndex = self.model().index(row, 1, self.rootIndex()) value = self.model().data(sliceIndex).toDouble()[0] if value > 0.0: angle = 360*value/self.totalValue if sliceIndex == index: slicePath = QPainterPath() slicePath.moveTo(self.totalSize/2, self.totalSize/2) slicePath.arcTo(self.margin, self.margin, self.margin+self.histogramSize, self.margin+self.histogramSize, startAngle, angle) slicePath.closeSubpath() return QRegion(slicePath.toFillPolygon().toPolygon()) startAngle += angle return QRegion()
def __init_corner(self): path = QPainterPath() path.moveTo(-Block.padding, -15 - Block.padding) path.lineTo(-15 - Block.padding, -Block.padding) path.lineTo(-Block.padding, -Block.padding) path.closeSubpath() self.__corner_path = path
def __call__(o, gridfunc, piece_count, image_width, image_height): p = QPainterPath(QPointF(0.0, 0.0)) p.lineTo(QPointF(image_width, 0.0)) p.lineTo(QPointF(image_width, image_height)) p.lineTo(QPointF(0.0, image_height)) p.closeSubpath() o._boundary_path = p gridfunc(o, piece_count, image_width, image_height)
def __init_corner(self): path = QPainterPath() dpi = Info.dpi path.moveTo(-OIBlock.padding * 1.2 * dpi, (-.15 - OIBlock.padding * 1.2) * dpi) path.lineTo((-.15 - OIBlock.padding * 1.2) * dpi, -OIBlock.padding * 1.2 * dpi) path.lineTo(-OIBlock.padding * 1.2 * dpi, -OIBlock.padding * 1.2 * dpi) path.closeSubpath() self.__corner_path = path
class RobotView(QGraphicsItem): def __init__(self, robot): super(RobotView, self).__init__() self.robot = robot self.outline = QPainterPath() self.cut_angle = 0.0 self.setFlags(QGraphicsItem.ItemIsSelectable) @property def uuid(self): return self.robot.uuid @property def color(self): if self.isSelected(): return GREEN elif self.robot.is_blue: return BLUE elif self.robot.is_yellow: return YELLOW else: return BLACK def position(self): x, y, width, height = s(self.robot.x, self.robot.y, self.robot.world.length, self.robot.world.width) radius = s(self.robot.radius) self.cut_angle = acos(self.robot.front_cut / self.robot.radius) self.outline = QPainterPath() self.outline.moveTo(radius, 0) self.outline.arcTo(-radius, -radius, 2 * radius, 2 * radius, 0, 360 - 2 * self.cut_angle) self.outline.closeSubpath() self.setPos(x, -y) def boundingRect(self): radius = s(self.robot.radius) return QRectF(-radius, -radius, 2 * radius, 2 * radius) def paint(self, painter, option, widget=None): # Save transformation: painter.save() color = self.color # Change position painter.setBrush(color) painter.setPen(color) robot_rotation = self.robot.angle or 0.0 # Draw robot shape painter.rotate(-self.cut_angle - robot_rotation) painter.drawPath(self.outline) painter.rotate(self.cut_angle + robot_rotation) # Reset transformation painter.restore()
def tile_path(self, cx, cy): path = QPainterPath() path.moveTo((cx - self.r_hex), cy) for i in range(1, 6): x = cx + (self.r_hex * cos(((3 - i) * pi) / 3)) y = cy + (self.r_hex * sin(((3 - i) * pi) / 3)) path.lineTo(x, y) path.closeSubpath() return path
def draw_arc(x, y, radius_in, radius_out, angle_init, angle_end, painter): path = QPainterPath() path.moveTo(x + radius_in * cos(angle_init), y + radius_in * sin(angle_init)) path.arcTo(x - radius_out, y - radius_out, 2 * radius_out, 2 * radius_out, angle_init, angle_end - angle_init) path.arcTo(x - radius_in, y - radius_in, 2 * radius_in, 2 * radius_in, angle_end, angle_init - angle_end) path.closeSubpath() painter.drawPath(path)
def make_painter_path(self): """Return a new QPainterPath used for drawing the shape.""" path = QPainterPath() points = self._points if points: point = points[0] path.moveTo(point[0], point[1]) for i in range(1, len(self._points)): point = points[i] path.lineTo(point[0], point[1]) path.closeSubpath() return path;
def __init__(self, id, title='', title_above=False, title_location=AxisMiddle, line=None, arrows=0, plot=None, bounds=None): QGraphicsItem.__init__(self) self.setFlag(QGraphicsItem.ItemHasNoContents) self.setZValue(AxisZValue) self.id = id self.title = title self.title_location = title_location self.data_line = line self.plot = plot self.graph_line = None self.size = None self.scale = None self.tick_length = (10, 5, 0) self.arrows = arrows self.title_above = title_above self.line_item = QGraphicsLineItem(self) self.title_item = QGraphicsTextItem(self) self.end_arrow_item = None self.start_arrow_item = None self.show_title = False self.scale = None path = QPainterPath() path.setFillRule(Qt.WindingFill) path.moveTo(0, 3.09) path.lineTo(0, -3.09) path.lineTo(9.51, 0) path.closeSubpath() self.arrow_path = path self.label_items = [] self.label_bg_items = [] self.tick_items = [] self._ticks = [] self.zoom_transform = QTransform() self.labels = None self.values = None self._bounds = bounds self.auto_range = None self.auto_scale = True self.zoomable = False self.update_callback = None self.max_text_width = 50 self.text_margin = 5 self.always_horizontal_text = False
def updateShape(self, point=None, pos=None): # Main arrow direction params = parameters.instance scale = self.scale ms = min(scale) head_size = params.arrow_head_size * ms width = params.arrow_line_size * ms self.prepareGeometryChange() if point == self.source: p1 = pos else: p1 = self.source.pos() self.setPos(p1) if point == self.target: p2 = pos else: p2 = self.target.pos() tip = p2 - p1 if abs(tip.x()) > 0.001 or abs(tip.y()) > 0.001: # Normalised #ntip = tip/stip ntip = tip # Arrow head base orth = QPointF(ntip.y(), -ntip.x()) * (head_size * 0.5) base_center = tip * (1 - 2 * head_size) base1 = base_center + orth base2 = base_center - orth base_center = tip * (1 - head_size * 1.50) else: ntip = tip base_center = tip base1 = tip base2 = tip self.tip = tip self.base_center = base_center self.base1 = base1 self.base2 = base2 path = QPainterPath() path.lineTo(base_center) path.addPolygon(QPolygonF([base_center, base1, tip, base2])) path.closeSubpath() self.rect = path.controlPointRect().adjusted(-width, -width, 2 * width, 2 * width) self.path = path self.update()
def arrow_path_concave(line, width): """ Return a :class:`QPainterPath` of a pretty looking arrow. """ path = QPainterPath() p1, p2 = line.p1(), line.p2() if p1 == p2: return path baseline = QLineF(line) # Require some minimum length. baseline.setLength(max(line.length() - width * 3, width * 3)) start, end = baseline.p1(), baseline.p2() mid = (start + end) / 2.0 normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2() path.moveTo(start) path.lineTo(start + (normal * width / 4.0)) path.quadTo(mid + (normal * width / 4.0), end + (normal * width / 1.5)) path.lineTo(end - (normal * width / 1.5)) path.quadTo(mid - (normal * width / 4.0), start - (normal * width / 4.0)) path.closeSubpath() arrow_head_len = width * 4 arrow_head_angle = 50 line_angle = line.angle() - 180 angle_1 = line_angle - arrow_head_angle / 2.0 angle_2 = line_angle + arrow_head_angle / 2.0 points = [p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(), baseline.p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2] poly = QPolygonF(points) path_head = QPainterPath() path_head.addPolygon(poly) path = path.united(path_head) return path
def updateShape(self, point=None, pos=None): # Main arrow direction params = parameters.instance scale = self.scale ms = min(scale) head_size = params.arrow_head_size*ms width = params.arrow_line_size*ms self.prepareGeometryChange() if point == self.source: p1 = pos else: p1 = self.source.pos() self.setPos(p1) if point == self.target: p2 = pos else: p2 = self.target.pos() tip = p2-p1 if abs(tip.x()) > 0.001 or abs(tip.y()) > 0.001: # Normalised #ntip = tip/stip ntip = tip # Arrow head base orth = QPointF(ntip.y(), -ntip.x())*(head_size*0.5) base_center = tip*(1-2*head_size) base1 = base_center + orth base2 = base_center - orth base_center = tip*(1-head_size*1.50) else: ntip = tip base_center = tip base1 = tip base2 = tip self.tip = tip self.base_center = base_center self.base1 = base1 self.base2 = base2 path = QPainterPath() path.lineTo(base_center) path.addPolygon(QPolygonF([base_center, base1, tip, base2])) path.closeSubpath() self.rect = path.controlPointRect().adjusted(-width, -width, 2*width, 2*width) self.path = path self.update()
def arrow_path_concave(line, width): """ Return a :class:`QPainterPath` of a pretty looking arrow. """ path = QPainterPath() p1, p2 = line.p1(), line.p2() if p1 == p2: return path baseline = QLineF(line) # Require some minimum length. baseline.setLength(max(line.length() - width * 3, width * 3)) start, end = baseline.p1(), baseline.p2() mid = (start + end) / 2.0 normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2() path.moveTo(start) path.lineTo(start + (normal * width / 4.0)) path.quadTo(mid + (normal * width / 4.0), end + (normal * width / 1.5)) path.lineTo(end - (normal * width / 1.5)) path.quadTo(mid - (normal * width / 4.0), start - (normal * width / 4.0)) path.closeSubpath() arrow_head_len = width * 4 arrow_head_angle = 50 line_angle = line.angle() - 180 angle_1 = line_angle - arrow_head_angle / 2.0 angle_2 = line_angle + arrow_head_angle / 2.0 points = [ p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(), baseline.p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2 ] poly = QPolygonF(points) path_head = QPainterPath() path_head.addPolygon(poly) path = path.united(path_head) return path
def paintEvent(self,event): painter = QPainter(self) if self.hasUnderLine: rect = self.tabRect(self.hoveredTab) linesPath = QPainterPath() linesPath.moveTo(QPoint(rect.x()+10,rect.height()-5)) linesPath.lineTo(QPoint(rect.x()-10+rect.width(),rect.height()-5)) linesPath.closeSubpath() painter.setPen(QPen(QColor(170,200,200),6)) painter.drawPath(linesPath) # 如果不是当前选中的页,在页标签下画线 if self.hoveredTab != self.currentIndex (): if self.isTabEnabled(self.hoveredTab): rect = self.tabRect(self.hoveredTab) linesPath = QPainterPath() linesPath.moveTo(QPoint(rect.x()+10,rect.height()-5)) linesPath.lineTo(QPoint(rect.x()-10+rect.width(),rect.height()-5)) linesPath.closeSubpath() painter.setPen(QPen(QColor(170,200,200),6)) painter.drawPath(linesPath) QTabBar.paintEvent(self,event)
class CustomWidget(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) self.path = QPainterPath() angle = 2*math.pi/5 self.path.moveTo(50, 0) for step in range(1, 6): self.path.lineTo(20 * math.cos((step - 0.5) * angle), 20 * math.sin((step - 0.5) * angle)) self.path.lineTo(50 * math.cos(step * angle), 50 * math.sin(step * angle)) self.path.closeSubpath() start = QPointF(0, 100) stop = QPointF(100, 0) self.gradient = QLinearGradient(start, stop) self.gradient.setColorAt(0.15, QColor(255, 0, 128)) self.gradient.setColorAt(0.4, QColor(255, 255, 128)) self.gradient.setColorAt(0.5, QColor(255, 255, 255)) self.gradient.setColorAt(0.6, QColor(255, 255, 128)) self.gradient.setColorAt(0.85, QColor(255, 0, 128)) def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.setBrush(QBrush(QColor(192, 192, 255))) painter.drawRect(event.rect()) painter.translate(self.width()/2.0, self.height()/2.0) painter.scale(self.width()*0.75/100.0, self.height()*0.75/100.0) painter.setBrush(QBrush(self.gradient)) painter.drawPath(self.path) painter.end() def sizeHint(self): return QSize(200, 200)
def selectionShape(self): """ Return the current selection shape. This is the area selected/drawn by the user. Returns ------- shape : QPainterPath The selection shape in view coordinates. """ if self.__path is not None: shape = QPainterPath(self.__path) shape.closeSubpath() else: shape = QPainterPath() viewbox = self.viewBox() if viewbox is None: return QPainterPath() return viewbox.childGroup.mapFromParent(shape)
def polygonToCurvedPath(polygon, radius): path = QPainterPath() for i, pt in enumerate(polygon): # TODO: if two points are too close to draw the desired radius, either remove those points or draw at smaller radius px, py = polygon[i - 1] if i > 0 else polygon[-1] nx, ny = polygon[i + 1] if i < len(polygon) - 1 else polygon[0] x, y = pt if px == x: dy = y - py r = radius if dy < 0 else -radius p1 = QPointF(x, y + r) else: dx = x - px r = radius if dx < 0 else -radius p1 = QPointF(x + r, y) if x == nx: dy = y - ny r = radius if dy < 0 else -radius p2 = QPointF(x, y + r) else: dx = x - nx r = radius if dx < 0 else -radius p2 = QPointF(x + r, y) if i == 0: path.moveTo(p1) else: path.lineTo(p1) path.cubicTo(pt, pt, p2) path.closeSubpath() return path
def polygonToCurvedPath(polygon, radius): path = QPainterPath() for i, pt in enumerate(polygon): # TODO: if two points are too close to draw the desired radius, either remove those points or draw at smaller radius px, py = polygon[i-1] if i > 0 else polygon[-1] nx, ny = polygon[i+1] if i < len(polygon) - 1 else polygon[0] x, y = pt if px == x: dy = y - py r = radius if dy < 0 else -radius p1 = QPointF(x, y + r) else: dx = x - px r = radius if dx < 0 else -radius p1 = QPointF(x + r, y) if x == nx: dy = y - ny r = radius if dy < 0 else -radius p2 = QPointF(x, y + r) else: dx = x - nx r = radius if dx < 0 else -radius p2 = QPointF(x + r, y) if i == 0: path.moveTo(p1) else: path.lineTo(p1) path.cubicTo(pt, pt, p2) path.closeSubpath() return path
def paintEvent(self, pe): p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) # p.setBrush(QColor(0xf0, 0xf0, 0xf0)) # color of the border # p.drawRect(-1, -1, 800, 800) pen = QPen() pen.setWidth(1) pen.setColor(QColor(0x58, 0x58, 0x58)) # color of the borders of the keys p.setPen(pen) p.setBrush(QColor(0x58, 0x58, 0x58)) # color of the keys p.setBackgroundMode(Qt.TransparentMode) rx = 3 space = self.space w = self.usable_width kw = self.key_w def drawRow(row, sx, sy, last_end=False): x = sx y = sy keys = row rw = w - sx i = 0 for k in keys: rect = QRectF(x, y, kw, kw) if i == len(keys) - 1 and last_end: rect.setWidth(rw) p.drawRoundedRect(rect, rx, rx) rect.adjust(5, 1, 0, 0) p.setPen(QColor(0xff, 0xff, 0xff)) p.setFont(self.lowerFont) p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom, self.regular_text(k)) p.setPen(QColor(0x9e, 0xde, 0x00)) p.setFont(self.upperFont) p.drawText(rect, Qt.AlignLeft | Qt.AlignTop, self.shift_text(k)) rw = rw - space - kw x = x + space + kw i = i + 1 p.setPen(pen) return (x, rw) x = 6 y = 6 keys = self.kb["keys"] ext_return = self.kb["extended_return"] first_key_w = 0 rows = 4 remaining_x = [0, 0, 0, 0] remaining_widths = [0, 0, 0, 0] for i in range(0, rows): if first_key_w > 0: first_key_w = first_key_w * 1.375 if self.kb == self.kb_105 and i == 3: first_key_w = kw * 1.275 rect = QRectF(6, y, first_key_w, kw) p.drawRoundedRect(rect, rx, rx) x = 6 + first_key_w + space else: first_key_w = kw x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return) remaining_x[i] = x remaining_widths[i] = rw if i != 1 and i != 2: rect = QRectF(x, y, rw, kw) p.drawRoundedRect(rect, rx, rx) x = .5 y = y + space + kw if ext_return: rx = rx * 2 x1 = remaining_x[1] y1 = 6 + kw * 1 + space * 1 w1 = remaining_widths[1] x2 = remaining_x[2] y2 = 6 + kw * 2 + space * 2 # this is some serious crap... but it has to be so # maybe one day keyboards won't look like this... # one can only hope pp = QPainterPath() pp.moveTo(x1, y1 + rx) pp.arcTo(x1, y1, rx, rx, 180, -90) pp.lineTo(x1 + w1 - rx, y1) pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90) pp.lineTo(x1 + w1, y2 + kw - rx) pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90) pp.lineTo(x2 + rx, y2 + kw) pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90) pp.lineTo(x2, y1 + kw) pp.lineTo(x1 + rx, y1 + kw) pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90) pp.closeSubpath() p.drawPath(pp) else: x = remaining_x[2] y = .5 + kw * 2 + space * 2 rect = QRectF(x, y, remaining_widths[2], kw) p.drawRoundedRect(rect, rx, rx) QWidget.paintEvent(self, pe)
def paintEvent(self, pe): p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) pen = QPen() pen.setWidth(1) pen.setColor(QColor(0x8C, 0xA3, 0xB0)) p.setPen(pen) p.setBrush(QColor(0xE4, 0xEC, 0xF4)) rx = 6 space = self.space w = self.usable_width kw = self.key_w def drawRow(row, sx, sy, last_end=False): x = sx y = sy keys = row rw = w - sx i = 0 for k in keys: rect = QRectF(x, y, kw, kw) if i == len(keys) - 1 and last_end: rect.setWidth(rw) p.drawRoundedRect(rect, rx, rx) p.setPen(Qt.black) rect.adjust(5, 1, 0, 0) p.setFont(self.lowerFont) p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom, self.regular_text(k)) p.setFont(self.upperFont) p.drawText(rect, Qt.AlignLeft | Qt.AlignTop, self.shift_text(k)) rw = rw - space - kw x = x + space + kw i = i + 1 p.setPen(pen) return (x, rw) x = 0.5 y = 0.5 keys = self.kb["keys"] ext_return = self.kb["extended_return"] first_key_w = 0 rows = 4 remaining_x = [0, 0, 0, 0] remaining_widths = [0, 0, 0, 0] for i in range(0, rows): if first_key_w > 0: first_key_w = first_key_w * 1.375 if self.kb == self.kb_105 and i == 3: first_key_w = kw * 1.275 rect = QRectF(x, y, first_key_w, kw) p.drawRoundedRect(rect, rx, rx) x = x + first_key_w + space else: first_key_w = kw x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return) remaining_x[i] = x remaining_widths[i] = rw if i != 1 and i != 2: rect = QRectF(x, y, rw, kw) p.drawRoundedRect(rect, rx, rx) x = 0.5 y = y + space + kw if ext_return: rx = rx * 2 x1 = remaining_x[1] y1 = 0.5 + kw * 1 + space * 1 w1 = remaining_widths[1] x2 = remaining_x[2] y2 = 0.5 + kw * 2 + space * 2 w2 = remaining_widths[2] # this is some serious crap... but it has to be so # maybe one day keyboards won't look like this... # one can only hope pp = QPainterPath() pp.moveTo(x1, y1 + rx) pp.arcTo(x1, y1, rx, rx, 180, -90) pp.lineTo(x1 + w1 - rx, y1) pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90) pp.lineTo(x1 + w1, y2 + kw - rx) pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90) pp.lineTo(x2 + rx, y2 + kw) pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90) pp.lineTo(x2, y1 + kw) pp.lineTo(x1 + rx, y1 + kw) pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90) pp.closeSubpath() p.drawPath(pp) else: x = remaining_x[2] y = 0.5 + kw * 2 + space * 2 rect = QRectF(x, y, remaining_widths[2], kw) p.drawRoundedRect(rect, rx, rx) QWidget.paintEvent(self, pe)
def _generate_popup_path(rect, xRadius, yRadius, arrowSize, anchor): """ Generate the QPainterPath used to draw the outline of the popup. Parameters ---------- rect : QRect Bounding rect for the popup. xRadius, yRadius : int x and y radius of the popup. arrowSize : QSize Width and height of the popup anchor arrow. anchor : int Positioning of the popup relative to the parent. Determines the position of the arrow. Returns ------- result : QPainterPath Path that can be passed to QPainter.drawPath to render popup. """ awidth, aheight = arrowSize.width(), arrowSize.height() draw_arrow = (awidth > 0 and aheight > 0) if anchor == QBubbleView.AnchorRight: rect.adjust(aheight, 0, 0, 0) elif anchor == QBubbleView.AnchorLeft: rect.adjust(0, 0, -aheight, 0) elif anchor == QBubbleView.AnchorBottom: rect.adjust(0, aheight, 0, 0) else: rect.adjust(0, 0, 0, -aheight) r = rect.normalized() if r.isNull(): return hw = r.width() / 2 hh = r.height() / 2 xRadius = 100 * min(xRadius, hw) / hw yRadius = 100 * min(yRadius, hh) / hh # The starting point of the path is the top left corner x = r.x() y = r.y() w = r.width() h = r.height() rxx2 = w * xRadius / 100 ryy2 = h * yRadius / 100 center = r.center() path = QPainterPath() path.arcMoveTo(x, y, rxx2, ryy2, 180) path.arcTo(x, y, rxx2, ryy2, 180, -90) if anchor == QBubbleView.AnchorBottom and draw_arrow: path.lineTo(center.x() - awidth, y) path.lineTo(center.x(), y - aheight) path.lineTo(center.x() + awidth, y) path.arcTo(x + w - rxx2, y, rxx2, ryy2, 90, -90) if anchor == QBubbleView.AnchorLeft and draw_arrow: path.lineTo(x + w, center.y() - awidth) path.lineTo(x + w + aheight, center.y()) path.lineTo(x + w, center.y() + awidth) path.arcTo(x + w - rxx2, y + h - ryy2, rxx2, ryy2, 0, -90) if anchor == QBubbleView.AnchorTop and draw_arrow: path.lineTo(center.x() + awidth, y + h) path.lineTo(center.x(), y + h + aheight) path.lineTo(center.x() - awidth, y + h) path.arcTo(x, y + h - ryy2, rxx2, ryy2, 270, -90) if anchor == QBubbleView.AnchorRight and draw_arrow: path.lineTo(x, center.y() + awidth) path.lineTo(x - aheight, center.y()) path.lineTo(x, center.y() - awidth) path.closeSubpath() return path
def drawCorner(self, painter, position, cornerType, maxRadius=None): #logging.debug(self.__class__.__name__ +": drawCorner() "+ self.cornerTypeString(cornerType)) thickness = self.CONNECTION_THICKNESS * self.zoomFactor() halfthick = thickness / 2 cornerRoundness = halfthick ** 0.5 cornerOffset = halfthick * (cornerRoundness) innerCorner = halfthick * (cornerRoundness - 1) outerCorner = halfthick * (cornerRoundness + 1) innerWidth = halfthick * (cornerRoundness - 1) radius = halfthick * (cornerRoundness + 1) if maxRadius: maxRadius = max(maxRadius, thickness) radius = min(radius, maxRadius) if cornerType == self.CornerType.TOP_RIGHT: startAngle = 0 outerCorner = QPointF(position.x() + halfthick - 2 * radius, position.y() - halfthick) innerCorner = QPointF(outerCorner.x(), outerCorner.y() + (thickness)) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF(innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + 2 * radius, outerCorner.y() + (radius + halfthick)) innerStart = QPointF(outerCorner.x() + (radius - halfthick), outerCorner.y()) elif cornerType == self.CornerType.TOP_LEFT: startAngle = 90 outerCorner = QPointF(position.x() - halfthick, position.y() - halfthick) innerCorner = QPointF(outerCorner.x() + (thickness), outerCorner.y() + (thickness)) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF(innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + (radius + halfthick), outerCorner.y()) innerStart = QPointF(outerCorner.x(), outerCorner.y() + (radius + halfthick)) elif cornerType == self.CornerType.BOTTOM_LEFT: startAngle = 180 outerCorner = QPointF(position.x() - halfthick, position.y() + halfthick - 2 * radius) innerCorner = QPointF(outerCorner.x() + (thickness), outerCorner.y()) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF(innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x(), outerCorner.y() + (radius - halfthick)) innerStart = QPointF(outerCorner.x() + (radius + halfthick), outerCorner.y() + (2 * radius)) elif cornerType == self.CornerType.BOTTOM_RIGHT: startAngle = 270 outerCorner = QPointF(position.x() + halfthick - 2 * radius, position.y() + halfthick - 2 * radius) innerCorner = QPointF(outerCorner.x(), outerCorner.y()) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF(innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + (radius - halfthick), outerCorner.y() + 2 * radius) innerStart = QPointF(outerCorner.x() + 2 * radius, outerCorner.y() + (radius - halfthick)) else: # No defined corner, so nothing to draw. #print "PointToPointConnection.drawCorner() - No valid corner, aborting..." return if painter.redirected(painter.device()): # e.q. QPixmap.grabWidget() painter.setBrush(self.FILL_COLOR1) else: brush = QRadialGradient(center, radius) if radius >= thickness: brush.setColorAt((radius - thickness) / radius, self.FILL_COLOR1) # inner border brush.setColorAt((radius - halfthick + 1) / radius, self.FILL_COLOR2) # center of line else: # If zoom is too small use single color brush.setColorAt(0, self.FILL_COLOR1) brush.setColorAt(1, self.FILL_COLOR1) # outer border painter.setBrush(brush) path = QPainterPath() path.moveTo(outerStart) path.arcTo(outerRect, startAngle, 90) path.lineTo(innerStart) path.arcTo(innerRect, startAngle + 90, - 90) path.closeSubpath() #painter.setPen(Qt.NoPen) painter.drawPath(path)
def getSymbolFromCmnd(self, symbol): ''' Returns a SymbolPath of the specified symbol. Recognized symbols are: '.' (period): filled circle 'o' (lowercase oh): unfilled circle '+': plus mark 'x' (lowercase ex): x mark '*': asterisk '^': triangle "#": square The path is drawn for a 100 x 100 unit square where the origin is in the center of the square. ''' # check if this symbol has already been created try: sympath = self.__symbolpaths[symbol] return sympath except KeyError: pass # new symbol - create a SymbolPath for it if symbol == '.': path = QPainterPath() path.addEllipse(-10.0, -10.0, 20.0, 20.0) sympath = SymbolPath(path, True) elif symbol == 'o': path = QPainterPath() path.addEllipse(-40.0, -40.0, 80.0, 80.0) sympath = SymbolPath(path, False) elif symbol == 'x': path = QPainterPath(QPointF(-30.0, -30.0)) path.lineTo(30.0, 30.0) path.moveTo(-30.0, 30.0) path.lineTo(30.0, -30.0) sympath = SymbolPath(path, False) elif symbol == '+': path = QPainterPath(QPointF(0.0, -40.0)) path.lineTo(0.0, 40.0) path.moveTo(-40.0, 0.0) path.lineTo(40.0, 0.0) sympath = SymbolPath(path, False) elif symbol == '*': path = QPainterPath(QPointF(0.0, -40.0)) path.lineTo(0.0, 40.0) path.moveTo(-34.641, -20.0) path.lineTo(34.641, 20.0) path.moveTo(-34.641, 20.0) path.lineTo(34.641, -20.0) sympath = SymbolPath(path, False) elif symbol == '^': path = QPainterPath(QPointF(-40.0, 30.0)) path.lineTo(0.0, -39.282) path.lineTo(40.0, 30.0) path.closeSubpath() sympath = SymbolPath(path, False) elif symbol == '#': path = QPainterPath() path.addRect(-35.0, -35.0, 70.0, 70.0) sympath = SymbolPath(path, False) else: raise ValueError("Unrecognized symbol '%s'" % str(symbol)) # save and return the SymbolPath self.__symbolpaths[symbol] = sympath return sympath
def drawCyclePath(self, v1, sepInput, v2, sepOutput, delta, cl): """ Tracé d'un arc reliant le noeud node1 à lui même dans le plan. Attention, puisque dans le plan de l'interface, l'axe des ordonnées est inveré, mais pas l'axe des abscisses la rotation dans le sens trigonométrique et le sens horaire sont inversés. """ # Il est conseillé de prendre une feuille est un stylo pour dessiner en lisant les commentaires # de cette méthode # m1 et o sont des points définis plus loin, mais on peut calculer et on a besoin de calculer leur distance # dès maintenant m1omag = float(cl ** 2 - NodeItem.NodeWidth ** 2) / (2 * cl) # demi angle entre les tangentes de l'arc à ses deux extrêmités (entre l'arrivée et le départ). gamma = atan(m1omag / NodeItem.NodeWidth) # delta est l'angle qui existe entre l'horizontale est la droite coupant orthogonalement l'arc en son milieu u = Vector2(1, 0).rotate(delta) # vecteur normé orienté du centre du noeud vers le milieu de l'arc # m1 est le point du cercle node1 au milieu du départ de l'arc v1m1norm = (u.rotate(-gamma)) # m2 est la pointe de la flêche de l'arc v2m2norm = (u.rotate(gamma)) v1m1 = NodeItem.NodeWidth * v1m1norm # Point sur le cercle node1 à une distance angulaire -alpha de m1 m1m = v1 + v1m1.rotate(-ArcItem.endingsAlpha) # Point sur le cercle node1 à une distance angulaire alpha de m1 m1p = v1 + v1m1.rotate(ArcItem.endingsAlpha) v2m2 = NodeItem.NodeWidth * v2m2norm m2 = v2 + v2m2 # Point m2 a2 = v2 + 2 * v2m2 # a2 est le milieu du segment central de la pointe de la flêche de l'arc # a2m est l'extrêmité droite de la pointe de la flêche a2m = v2 + v2m2 + (NodeItem.NodeWidth / cos(ArcItem.arrowBeta)) * v2m2norm.rotate(-ArcItem.arrowBeta) # a2p est l'extrêmité gauche de la pointe de la flêche a2p = v2 + v2m2 + (NodeItem.NodeWidth / cos(ArcItem.arrowBeta)) * v2m2norm.rotate(ArcItem.arrowBeta) # m2m est le point sur le cercle node2 à une distance angulaire -alpha de m2 v2m2m = v2m2.rotate(-ArcItem.endingsAlpha) # Vecteur v2 m2m # m2p est le point sur le cercle node2 à une distance angulaire alpha de m2 v2m2p = v2m2.rotate(ArcItem.endingsAlpha) # Vecteur v2 m2p # m2mp est le point sur le segment central de la pointe de la flêche qui appartient à la droite passant # par m2m parallèle au vecteur v2m2, définit ici à l'aide d'un projeté orthogonal m2mp = a2 + v2m2m.project(a2m - a2) # m2pp est le point sur le segment central de la pointe de la flêche qui appartient à la droite passant # par m2p parallèle au vecteur v2m2, définit ici à l'aide d'un projeté orthogonal m2pp = a2 + v2m2p.project(a2p - a2) # o est le centre du cercle passant par les 3 points suivants : m1, m2 et c # où c est le point situé à une distance self.cl de v1, en suivant le vecteur u, cad le milieu de l'arc o = v1 + v1m1 + m1omag * v1m1norm.rotate(pi / 2) c1 = 0.5 * (m2pp + m1m) # c1 est le milieu de m2pp et m1m # o1 est le centre du cercle passant par m1m et m2pp le plus proche de o o1 = c1 + (o - c1).project((m1m - m2pp).rotate(pi / 2)) r1 = (o1 - m1m).magnitude() # le rayon du cercle en question sinstang1 = Vector2(0, 1).dot(m1m - o1) # sinus de l'angle entre l'horizontale et (o1,m1m) stang1 = -Vector2(1, 0).angle(m1m - o1) # opposé de la valeur absolue de cet angle if sinstang1 < 0: stang1 *= -1 sinendang1 = Vector2(0, 1).dot(m2pp - o1) # sinus de l'angle entre l'horizontale et (o1,m2pp) endang1 = -Vector2(1, 0).angle(m2pp - o1) # opposé de la valeur absolue de cet angle if sinendang1 < 0: endang1 *= -1 pathang1 = endang1 - stang1 while pathang1 > 0: # correctifs pour afficher un bel arc de cercle dans le bon sens pathang1 -= 2 * pi while pathang1 < -2 * pi: pathang1 += 2 * pi c2 = 0.5 * (m2mp + m1p) # c2 est le milieu de m2mp et m1p # o2 est le centre du cercle passant par m1p et m2mp le plus proche de o o2 = c2 + (o - c2).project((m1p - m2mp).rotate(pi / 2)) r2 = (o2 - m1p).magnitude() # le rayon du cercle en question sinstang2 = Vector2(0, 1).dot(m2mp - o2) # sinus de l'angle entre l'horizontale et (o2,m2mp) stang2 = -Vector2(1, 0).angle(m2mp - o2) # opposé de la valeur absolue de cet angle if sinstang2 < 0: stang2 *= -1 sinendang2 = Vector2(0, 1).dot(m1p - o2) # sinus de l'angle entre l'horizontale et (o2,m1p) endang2 = -Vector2(1, 0).angle(m1p - o2) # opposé de la valeur absolue de cet angle if sinendang2 < 0: endang2 *= -1 pathang2 = endang2 - stang2 while pathang2 > 2 * pi: # correctifs pour afficher un bel arc de cercle dans le bon sens pathang2 -= 2 * pi while pathang2 < 0: pathang2 += 2 * pi # Tracé du chemin path = QPainterPath() path.moveTo(m1m.x, m1m.y) path.arcTo(o1.x - r1, o1.y - r1, 2 * r1, 2 * r1, degrees(stang1), degrees(pathang1)) path.lineTo(m2pp.x, m2pp.y) path.lineTo(m2mp.x, m2mp.y) path.arcTo(o2.x - r2, o2.y - r2, 2 * r2, 2 * r2, degrees(stang2), degrees(pathang2)) path.lineTo(m1p.x, m1p.y) path.closeSubpath() path.moveTo(m2.x, m2.y) path.lineTo(a2p.x, a2p.y) path.lineTo(a2m.x, a2m.y) path.closeSubpath() self.setPath(path) textCenter = o # v1 + cl * u labelItem = self.getLabelItem() labelItem.setArcVectorCenterAndOffset(u, textCenter, Vector2(0, 0))
def drawClassicPath(self, v1, sepInput, v2, sepOutput, cl): """ Trace d'un arc reliant les noeuds node1 et node2 dans le plan. Attention, puisque dans le plan de l'interface, l'axe des ordonnees est invere, mais pas l'axe des abscisses la rotation dans le sens trigonometrique et le sens horaire sont inverses. """ # Il est conseille de prendre une feuille est un stylo pour dessiner en lisant les commentaires # de cette methode u = v2 - v1 # Vecteur reliant v1 à v2 n = (u.rotate(pi / 2)).normalize() # Vecteur unitaire perpendiculaire à u # Point sur la mediatrice de [v1,v2] situe a une distance cl # Il servira (presque) de point de controle pour les courbes de Beziers traçant les deux bords de l'arc. c = v1 + u / 2 + cl * n v1m1norm = (c - v1).normalize() # Vecteur unitaire de la droite (v1,c), de v1 vers c v2m2norm = (c - v2).normalize() # Vecteur unitaire de la droite (v2,c), de v2 vers c # m1 est le point du cercle node1 situé sur la droite (v1,c) entre ces deux points. # c'est également le milieu du départ de l'arc sur node1 v1m1 = NodeItem.NodeWidth * v1m1norm # Vecteur v1m1 # Point sur le cercle node1 à une distance angulaire -alpha de m1 m1m = v1 + v1m1.rotate(-ArcItem.endingsAlpha) # Point sur le cercle node1 à une distance angulaire alpha de m1 m1p = v1 + v1m1.rotate(ArcItem.endingsAlpha) # m2 est le point du cercle node2 situé sur la droite (v2,c) entre ces deux points. # c'est également la pointe de la flêche de l'arc v2m2 = NodeItem.NodeWidth * v2m2norm # Vecteur v2m2 m2 = v2 + v2m2 # Point m2 a2 = v2 + 2 * v2m2 # a2 est le milieu du segment central de la pointe de la flêche de l'arc # a2m est l'extrêmité droite de la pointe de la flêche a2m = v2 + v2m2 + (NodeItem.NodeWidth / cos(ArcItem.arrowBeta)) * v2m2norm.rotate(-ArcItem.arrowBeta) # a2p est l'extrêmité gauche de la pointe de la flêche a2p = v2 + v2m2 + (NodeItem.NodeWidth / cos(ArcItem.arrowBeta)) * v2m2norm.rotate(ArcItem.arrowBeta) # m2m est le point sur le cercle node2 à une distance angulaire -alpha de m2 v2m2m = v2m2.rotate(-ArcItem.endingsAlpha) # Vecteur v2 m2m # m2p est le point sur le cercle node2 à une distance angulaire alpha de m2 v2m2p = v2m2.rotate(ArcItem.endingsAlpha) # Vecteur v2 m2p # m2mp est le point sur le segment central de la pointe de la flêche qui appartient à la droite passant # par m2m parallèle au vecteur v2m2, définit ici à l'aide d'un projeté orthogonal m2mp = a2 + v2m2m.project(a2m - a2) # m2pp est le point sur le segment central de la pointe de la flêche qui appartient à la droite passant # par m2p parallèle au vecteur v2m2, définit ici à l'aide d'un projeté orthogonal m2pp = a2 + v2m2p.project(a2p - a2) w = (m1p - m1m).magnitude() / 2 # eviron la demi largeur de l'arc c1 = c - w * n # point de contrôle de la courbe de bézier du bord gauche de l'arc c2 = c + w * n # point de contrôle de la courbe de bézier du bord droit de l'arc # Tracé de l'arc path = QPainterPath() if sepInput: path.moveTo(v1.x + NodeItem.NodeWidth, v1.y) path.arcTo(v1.x - NodeItem.NodeWidth, v1.y - NodeItem.NodeWidth, 2 * NodeItem.NodeWidth, 2 * NodeItem.NodeWidth, 0, 360) path.moveTo(m1m.x, m1m.y) path.quadTo(c1.x, c1.y, m2pp.x, m2pp.y) path.lineTo(m2mp.x, m2mp.y) path.quadTo(c2.x, c2.y, m1p.x, m1p.y) path.closeSubpath() path.moveTo(m2.x, m2.y) path.lineTo(a2p.x, a2p.y) path.lineTo(a2m.x, a2m.y) path.closeSubpath() if sepOutput: path.moveTo(v2.x + NodeItem.NodeWidth, v2.y) path.arcTo(v2.x - NodeItem.NodeWidth, v2.y - NodeItem.NodeWidth, 2 * NodeItem.NodeWidth, 2 * NodeItem.NodeWidth, 0, 360) self.setPath(path) textCenter = v1 + u / 2 # position normale labelItem = self.getLabelItem() offset = 0.5 * cl * n labelItem.setArcVectorCenterAndOffset(u, textCenter, offset)
def drawCorner(self, painter, position, cornerType, maxRadius=None): #logging.debug(self.__class__.__name__ +": drawCorner() "+ self.cornerTypeString(cornerType)) thickness = self.CONNECTION_THICKNESS * self.zoomFactor() halfthick = thickness / 2 cornerRoundness = halfthick**0.5 cornerOffset = halfthick * (cornerRoundness) innerCorner = halfthick * (cornerRoundness - 1) outerCorner = halfthick * (cornerRoundness + 1) innerWidth = halfthick * (cornerRoundness - 1) radius = halfthick * (cornerRoundness + 1) if maxRadius: maxRadius = max(maxRadius, thickness) radius = min(radius, maxRadius) if cornerType == self.CornerType.TOP_RIGHT: startAngle = 0 outerCorner = QPointF(position.x() + halfthick - 2 * radius, position.y() - halfthick) innerCorner = QPointF(outerCorner.x(), outerCorner.y() + (thickness)) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF( innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + 2 * radius, outerCorner.y() + (radius + halfthick)) innerStart = QPointF(outerCorner.x() + (radius - halfthick), outerCorner.y()) elif cornerType == self.CornerType.TOP_LEFT: startAngle = 90 outerCorner = QPointF(position.x() - halfthick, position.y() - halfthick) innerCorner = QPointF(outerCorner.x() + (thickness), outerCorner.y() + (thickness)) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF( innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + (radius + halfthick), outerCorner.y()) innerStart = QPointF(outerCorner.x(), outerCorner.y() + (radius + halfthick)) elif cornerType == self.CornerType.BOTTOM_LEFT: startAngle = 180 outerCorner = QPointF(position.x() - halfthick, position.y() + halfthick - 2 * radius) innerCorner = QPointF(outerCorner.x() + (thickness), outerCorner.y()) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF( innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x(), outerCorner.y() + (radius - halfthick)) innerStart = QPointF(outerCorner.x() + (radius + halfthick), outerCorner.y() + (2 * radius)) elif cornerType == self.CornerType.BOTTOM_RIGHT: startAngle = 270 outerCorner = QPointF(position.x() + halfthick - 2 * radius, position.y() + halfthick - 2 * radius) innerCorner = QPointF(outerCorner.x(), outerCorner.y()) center = QPointF(outerCorner.x() + radius, outerCorner.y() + radius) outerRect = QRectF(outerCorner, QSizeF(2 * radius, 2 * radius)) innerRect = QRectF( innerCorner, QSizeF((2 * radius - thickness), (2 * radius - thickness))) outerStart = QPointF(outerCorner.x() + (radius - halfthick), outerCorner.y() + 2 * radius) innerStart = QPointF(outerCorner.x() + 2 * radius, outerCorner.y() + (radius - halfthick)) else: # No defined corner, so nothing to draw. #print "PointToPointConnection.drawCorner() - No valid corner, aborting..." return if painter.redirected(painter.device()): # e.q. QPixmap.grabWidget() painter.setBrush(self.FILL_COLOR1) else: brush = QRadialGradient(center, radius) if radius >= thickness: brush.setColorAt((radius - thickness) / radius, self.FILL_COLOR1) # inner border brush.setColorAt((radius - halfthick + 1) / radius, self.FILL_COLOR2) # center of line else: # If zoom is too small use single color brush.setColorAt(0, self.FILL_COLOR1) brush.setColorAt(1, self.FILL_COLOR1) # outer border painter.setBrush(brush) path = QPainterPath() path.moveTo(outerStart) path.arcTo(outerRect, startAngle, 90) path.lineTo(innerStart) path.arcTo(innerRect, startAngle + 90, -90) path.closeSubpath() #painter.setPen(Qt.NoPen) painter.drawPath(path)
class MainFrame(QWidget): def __init__(self,parent = None): super(MainFrame,self).__init__(parent) language = StoreInfoParser.instance().getLanguage() m_pTranslator = QTranslator() exePath = "./" if language == "chinese": QmName = "zh_CN.qm" StoreInfoParser.instance().setLanguage("chinese") else: QmName = "en_US.qm" if(m_pTranslator.load(QmName, exePath)): QCoreApplication.instance().installTranslator(m_pTranslator) #初始化子控件 self.initSubWidget() #绑定信号和槽 self.bandSignalSlot() self.setMinimumSize(800,600) self.showFullScreen() self.updateWidgetInfo() self.setPosition() #self.repaint() def initSubWidget(self): self.linesPath = None self.widthtwo = 0 self.widthseven = 0 self.heightone = 0 self.heightfive = 0 self.copyLabel = QLabel(self) self.copyLabel.setFixedWidth(400) self.copyLabel.setAlignment(Qt.AlignCenter) self.nameLabel = QLabel(self) self.nameLabel.setFixedWidth(400) self.nameLabel.setAlignment(Qt.AlignCenter) self.copyLabel.setFont(QFont("simhei",9)) self.nameLabel.setFont(QFont("simhei",15)) self.netLabel = QLabel(self) self.netLabel.setFixedWidth(800) self.netLabel.setFixedHeight(20) #self.netLabel.setAlignment(Qt.AlignLeft) self.netLabel.setAlignment(Qt.AlignCenter) self.netLabel.setText(self.tr("Can not connect to server, please check network and server address!")) self.netLabel.setFont(QFont("simhei",12,QFont.Bold)) pe = QPalette() pe.setColor(QPalette.WindowText,Qt.red) self.netLabel.setPalette(pe) self.netLabel.hide() #self.updateTimer = QTimer(self) #self.connect(self.updateTimer, SIGNAL("timeout"),self.updateWidgetInfo) #self.updateTimer.start(10) #主窗口 self.mainwindow = MainWindow(self) #关于对话框 self.aboutWidget = AboutWidget(self) self.aboutWidget.hide() #self.showDlg = SettingWidget(self.mainwindow) #日志窗口 #self.recordWidget = RecordWidget(self) #self.recordWidget.mythread.stop() #self.recordWidget.hide() #self.toolWidget = ToolWidget() #self.toolWidget.hide() #创建action #self.action_showRecord_A = QAction(self) #self.action_closeRecord_B = QAction(self) #self.action_showRecord_A.setShortcut(QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_B)) #self.action_closeRecord_B.setShortcut(QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_C)) #self.addAction(self.action_showRecord_A) #self.addAction(self.action_closeRecord_B) self.udpClient = UdpClient() self.connect(self.udpClient, SIGNAL("start"),self.startB) self.connect(self.udpClient, SIGNAL("stop"),self.stopB) def initLanguage(self): language = StoreInfoParser.instance().getLanguage() m_pTranslator = QTranslator() exePath = "./" if language == "chinese": QmName = "zh_CN.qm" else: QmName = "en_US.qm" if(m_pTranslator.load(QmName, exePath)): QCoreApplication.instance().installTranslator(m_pTranslator) def updateWindow(self,language): hintInfo = self.tr("MASSCLOUDS CO.,LTD. Copyright 2014-2018") self.copyLabel.setText(hintInfo) self.netLabel.setText(self.tr("Can not connect to server, please check network and server address!")) self.mainwindow.updateWindow(language) #self.recordWidget.updateWindow() self.aboutWidget.updateWindow() def startB(self): self.udpClient.show() self.setBroadSize() def setBroadSize(self,width=None,height=None): #if self.udpClient.isActiveWindow(): if width == None: widtht = self.getWidth() heightt = self.getHeight() self.udpClient.setFixedSize(QSize(widtht,heightt)) else: self.udpClient.setFixedSize(QSize(width,height)) self.udpClient.move(QPoint(0,0)) #self.udpClient.imgLabelTwo.setFixedSize(QSize(QApplication.desktop().width(),QApplication.desktop().height())) def stopB(self): self.udpClient.close() def bandSignalSlot(self): """绑定信号和槽""" self.connect(self.mainwindow, SIGNAL("showToolDialog"),self.slotShowToolDialog) self.connect(self.mainwindow, SIGNAL("update"),self.slotUpdate) self.connect(self.mainwindow, SIGNAL("terminalchange"),self.changeTerminalName) self.connect(self.mainwindow, SIGNAL("resetsolution"),self.setPosition) self.connect(self.mainwindow, SIGNAL("connectfailed"),self.showNetlabel) self.connect(self.mainwindow, SIGNAL("connectsuccess"),self.hideNetlabel) #self.connect(self.action_showRecord_A,SIGNAL("triggered()"),self.showRecord) #self.connect(self.action_closeRecord_B,SIGNAL("triggered()"),self.closeRecord) def showNetlabel(self): self.netLabel.show() def hideNetlabel(self): self.netLabel.hide() self.udpClient.bindUdpPort() def changeTerminalName(self): name = globalvariable.TERMINAL_NAME self.nameLabel.setText(name) self.setPosition() def showRecord(self): self.recordWidget.show() self.recordWidget.mythread.start() self.recordWidget.move((self.width()-self.recordWidget.width())/2,(self.height()-self.recordWidget.height())/2) def closeRecord(self): self.recordWidget.mythread.stop() self.recordWidget.close() def slotShowToolDialog(self, actionType): showDlg = None if actionType == "showSetting": if PasswordDialog().exec_() == QDialog.Accepted: showDlg = SettingWidget(self.mainwindow) #showDlg.updateWindow() showDlg.move(QPoint(self.geometry().width()/9*2,self.geometry().height()/6)) if self.geometry().width() < 1440: showDlg.resize(QSize(self.geometry().width()/9*5,self.geometry().height()/6*4)) else: showDlg.resize(QSize(self.geometry().width()/9*5,self.geometry().height()/6*4)) self.connect(showDlg, SIGNAL("resizePosition"),self.resizePostion) self.connect(showDlg, SIGNAL("languagechanged"),self.slotLanguageChange) showDlg.exec_() elif actionType == "showTerminalTools": showDlg = ToolWidget() showDlg.move(QPoint(self.geometry().width()/9*2,self.geometry().height()/6)) showDlg.resize(QSize(self.geometry().width()/9*5,self.geometry().height()/6*4)) showDlg.exec_() #self.toolWidget.show() #self.toolWidget.move(QPoint(self.geometry().width()/9*2,self.geometry().height()/6)) #self.toolWidget.resize(QSize(self.geometry().width()/9*5,self.geometry().height()/6*4)) elif actionType == "showAbout": self.aboutWidget.show() desktop = QApplication.desktop() self.aboutWidget.move((desktop.width() - self.aboutWidget.width())/2, (desktop.height() - self.aboutWidget.height())/2) # def updateWidgetInfo(self): self.widthtwo = self.getWidth()/9*2 self.widthseven = self.getWidth()/9*7 self.heightone = self.getHeight()/6 self.heightfive = self.getHeight()/6*5 def updateLinesPath(self): """获取四条线路径""" self.linesPath = QPainterPath() self.linesPath.moveTo(self.widthtwo,self.heightone) self.linesPath.lineTo(self.widthseven,self.heightone) self.linesPath.moveTo(self.widthtwo,self.heightfive) self.linesPath.lineTo(self.widthseven,self.heightfive) self.linesPath.moveTo(self.widthtwo,self.heightone) self.linesPath.lineTo(self.widthtwo,self.heightfive) self.linesPath.moveTo(self.widthseven,self.heightone) self.linesPath.lineTo(self.widthseven,self.heightfive) self.linesPath.closeSubpath() def slotUpdate(self): self.setPosition() self.setBroadSize() def getWidth(self): '''desktop = QApplication.desktop() width = desktop.width() height = desktop.height()''' width = "1024" resolution = StoreInfoParser.instance().getResolutionValue() if resolution == None or resolution == "" or len(resolution.split("x")) != 2: width = "1024" else: width = resolution.split("x")[0] return int(width) def getHeight(self): height = "768" resolution = StoreInfoParser.instance().getResolutionValue() if resolution == None or resolution == "" or len(resolution.split("x")) != 2: height = "768" else: height = resolution.split("x")[1] return int(height) def paintEvent(self,paintEvent): """设置背景图片,画线""" painter = QPainter(self) #设置背景图片 painter.drawPixmap(self.rect(),QPixmap("images/background.png")) #获取四条线路径 self.updateLinesPath() painter.setPen(QPen(QColor(Qt.lightGray),1)) painter.drawPath(self.linesPath) # painter.drawText(QPoint(self.geometry().width()*3/7,self.geometry().height()*21/24), self.tr("乾云启创信息科技有限公司\nCopyright 2014-2018")) #painter.drawText(QPoint((self.geometry().width() - infoWidth)*1/2, self.geometry().height()*21/24), hintInfo) #painter.drawText(QPoint((self.geometry().width() - infoWidth)*1/2,self.geometry().height()*1/24), globalvariable.TERMINAL_NAME) def resizePostion(self, widths, heights): #self.setPosition() #self.repaint() #return language = StoreInfoParser.instance().getLanguage() m_pTranslator = QTranslator() exePath = "./" if language == "chinese": QmName = "zh_CN.qm" else: QmName = "en_US.qm" if(m_pTranslator.load(QmName, exePath)): QCoreApplication.instance().installTranslator(m_pTranslator) width = int(widths) height = int(heights) self.mainwindow.move(QPoint(width/9*2,height/6)) self.mainwindow.resize(QSize(width/9*5,height/6*4)) self.mainwindow.setPosition() hintInfo = self.tr("MASSCLOUDS CO.,LTD. Copyright 2014-2018") self.copyLabel.setText(hintInfo) infoWidth = self.copyLabel.width() #self.copyLabel.move(QPoint(self.geometry().width()*3/7,self.geometry().height()*21/24)) self.copyLabel.move(QPoint((width-infoWidth)/2,height*22/24)) if globalvariable.TERMINAL_NAME: info = globalvariable.TERMINAL_NAME self.nameLabel.setText(info) infoWidth = self.nameLabel.width() self.nameLabel.move(QPoint((width - infoWidth)*1/2,height*1/24)) netlabelwidth = self.netLabel.width() self.netLabel.move(QPoint((width-netlabelwidth)/2,height*21/24)) #self.netLabel.move(QPoint(width/9*2,height/6 - 20)) self.widthtwo = width/9*2 self.widthseven = width/9*7 self.heightone = height/6 self.heightfive = height/6*5 self.update() self.setBroadSize(width,height) def slotLanguageChange(self,language1): m_pTranslator = QTranslator() exePath = "./" if language1 == "chinese": mainwindow.language = "chinese" QmName = "zh_CN.qm" else: mainwindow.language = "english" QmName = "en_US.qm" if(m_pTranslator.load(QmName, exePath)): QCoreApplication.instance().installTranslator(m_pTranslator) self.updateWindow(language1) def getDesktopWidth(self): pass def setPosition(self): self.setMainwindowPosition() #self.setTerminalNamePosition() #self.setTerminalCopyRight() self.updateWidgetInfo() #self.setBroadSize() self.repaint() def setMainwindowPosition(self): #调整主窗口的位置和大小 width = self.getWidth() height = self.getHeight() self.mainwindow.move(QPoint(width/9*2,height/6)) self.mainwindow.resize(QSize(width/9*5,height/6*4)) self.mainwindow.setPosition() def setTerminalCopyRight(self): #显示公司信息 language = StoreInfoParser.instance().getLanguage() m_pTranslator = QTranslator() exePath = "./" if language == "chinese": QmName = "zh_CN.qm" else: QmName = "en_US.qm" if(m_pTranslator.load(QmName, exePath)): QCoreApplication.instance().installTranslator(m_pTranslator) width = self.getWidth() height = self.getHeight() hintInfo = self.tr("MASSCLOUDS CO.,LTD. Copyright 2014-2018") self.copyLabel.setText(hintInfo) infoWidth = self.copyLabel.width() #self.copyLabel.move(QPoint(self.geometry().width()*3/7,self.geometry().height()*21/24)) self.copyLabel.move(QPoint((width-infoWidth)/2,height*22/24)) def setTerminalNamePosition(self): #显示学生机的名称 width = self.getWidth() height = self.getHeight() if globalvariable.TERMINAL_NAME: info = globalvariable.TERMINAL_NAME self.nameLabel.setText(info) infoWidth = self.nameLabel.width() self.nameLabel.move(QPoint((width - infoWidth)*1/2,height*1/24)) netlabelwidth = self.netLabel.width() self.netLabel.move(QPoint((width-netlabelwidth)/2,height*21/24)) def wheelEvent(self,event): """鼠标滚轮滚动事件""" self.mainwindow.wheelEvent(event)
def piece_circle_path(self, tile): path = QPainterPath() path.moveTo(tile.pos) path.addEllipse(tile.pos, 0.75 * self.r_hex, 0.75 * self.r_hex) path.closeSubpath() return path