def updatePath(self): """ TOWRITE """ path = QPainterPath() r = self.rect() # QRectF path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) # NOTE: Reverse the path so that the inside area isn't considered part of the ellipse path.arcTo(r, 0, -360) self.setObjectPath(path)
def _setupPainterPath(self): painter_path = QPainterPath() painter_path.moveTo(0, 15) #left painter_path.lineTo(0, 0) #up painter_path.lineTo(self.width() - 1, 0) # right painter_path.lineTo(self.width() - 1, 15) # down painter_path.arcTo(QRect(self.width() - 6, 15, 5, 4), 0, -90) # control point1, cp2, destPoint painter_path.lineTo(5, 19) # left painter_path.arcTo(QRect(1, 15, 5, 4), 270, -90) #arc left up painter_path.closeSubpath() self._painter_path = painter_path
def set_shape(self, width, height): ''' ANSWER has round, disjoint sides - does not fit in a polygon ''' self.width, self.height = width, height point = width / 2.85 path = QPainterPath() left = QRect(0, 0, point, height) right = QRect(width - point, 0, point, height) path.arcMoveTo(left, 125) path.arcTo(left, 125, 110) path.arcMoveTo(right, -55) path.arcTo(right, -55, 110) path.moveTo(width, height) self.setPath(path) super(DecisionAnswer, self).set_shape(width, height)
def set_shape(self, width, height): ''' ANSWER has round, disjoint sides - does not fit in a polygon ''' self.width, self.height = width, height point = 20 #width / 2.85 path = QPainterPath() left = QRect(0, 0, point, height) right = QRect(width - point, 0, point, height) path.arcMoveTo(left, 125) path.arcTo(left, 125, 110) path.arcMoveTo(right, -55) path.arcTo(right, -55, 110) path.moveTo(width, height) self.setPath(path) super(DecisionAnswer, self).set_shape(width, height)
def roundedRectPath(x,y,width,height, TLRX,TLRY, TRRX,TRRY, BLRX,BLRY, BRRX,BRRY): right = x + width bottom = y + height if TLRX <= 0: TLRX = 0.1 if TLRY <= 0: TLRY = 0.1 if TRRX <= 0: TRRX = 0.1 if TRRY <= 0: TRRY = 0.1 # path cannot handle 0 if BLRX <= 0: BLRX = 0.1 # as rounding values if BLRY <= 0: BLRY = 0.1 if BRRX <= 0: BRRX = 0.1 if BRRY <= 0: BRRY = 0.1 path = QPainterPath(QPointF(x,y)) path.arcTo(x, y, TLRX * 2.0, TLRY * 2.0, 180.0, -90.0); path.arcTo(right - TRRX * 2.0, y, TRRX * 2.0, TRRY * 2.0, 90.0, -90.0); path.arcTo(right - BRRX * 2.0, bottom - BRRY * 2.0, BRRX * 2.0, BRRY * 2.0, 0.0 , -90.0); path.arcTo(x, bottom - BLRY * 2.0, BLRX * 2.0, BLRY * 2.0, -90.0, -90.0); path.closeSubpath() return path
def updatePath(self): """ TOWRITE """ path = QPainterPath() r = self.rect() # QRectF # Add the center point. path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002) # Add the circle. path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) # NOTE: Reverse the path so that the inside area isn't considered part of the circle. path.arcTo(r, 0, -360) self.setObjectPath(path)
def objectSavePath(self): """ TOWRITE :rtype: `QPainterPath`_ """ path = QPainterPath() r = self.rect() # QRectF path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) s = self.scale() # qreal trans = QTransform() trans.rotate(self.rotation()) trans.scale(s, s) return trans.map(path)
def updatePath(self): """ TOWRITE """ startAngle = (self.objectStartAngle() + self.rotation()) # qreal spanAngle = self.objectIncludedAngle() # qreal if self.objectClockwise(): spanAngle = -spanAngle path = QPainterPath() path.arcMoveTo(self.rect(), startAngle) path.arcTo(self.rect(), startAngle, spanAngle) # NOTE: Reverse the path so that the inside area isn't considered part of the arc path.arcTo(self.rect(), startAngle + spanAngle, -spanAngle); self.setObjectPath(path)
def drawHb(self, hbDict): viewIndex = 1 if not hbDict.has_key(self.ijk[viewIndex]): return if hbDict[self.ijk[viewIndex]].insert < 4: return a, b, c, d = [ self.ij2point(viewIndex, i, j) for (i, j) in hbDict[self.ijk[viewIndex]].get_points() ] cp = hbDict[self.ijk[viewIndex]].cp cp = self.ij2point(viewIndex, cp[0], cp[1]) vA = (a[0] - cp[0], a[1] - cp[1]) vB = (b[0] - cp[0], b[1] - cp[1]) vD = (d[0] - cp[0], d[1] - cp[1]) arcAD = QPainterPath() arcDB = QPainterPath() if hbDict['name'] == 'HbRight': sign = 1 startAngle = 0 else: sign = -1 startAngle = 180 angleADlad = sign * angleBw2Vectors(vA, vD) angleAD = 180 / np.pi * angleADlad if vD[0] * vD[0] + vD[1] * vD[1] >= vA[0] * vA[0] + vA[1] * vA[1]: rotD = (np.sqrt(vD[0] * vD[0] + vD[1] * vD[1]), 0) coefA = rotD[0] rotA = rotateVector(vA, angleADlad) coefB = np.sqrt(coefA * coefA / (coefA * coefA - rotA[0] * rotA[0]) * rotA[1] * rotA[1]) eccentricAnomalyAD = -180 / np.pi * np.arctan( coefA / coefB * np.tan(angleADlad)) arcAD.moveTo(cp[0] + sign * coefA, cp[1]) arcAD.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB, startAngle, eccentricAnomalyAD) else: rotA = (np.sqrt(vA[0] * vA[0] + vA[1] * vA[1]), 0) coefA = rotA[0] angleDAlad = sign * angleBw2Vectors(vD, vA) angleDA = 180 / np.pi * angleDAlad rotD = vD coefB = np.sqrt(coefA * coefA / (coefA * coefA - rotD[0] * rotD[0]) * rotD[1] * rotD[1]) eccentricAnomalyDA = 180 / np.pi * np.arctan( coefA / coefB * np.tan(angleDAlad)) arcAD.moveTo(cp[0] + sign * coefA, cp[1]) arcAD.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB, startAngle, eccentricAnomalyDA) angleAD = 0.0 if vD[0] * vD[0] + vD[1] * vD[1] >= vB[0] * vB[0] + vB[1] * vB[1]: rotD = (np.sqrt(vD[0] * vD[0] + vD[1] * vD[1]), 0) coefA = rotD[0] angleBDlad = sign * angleBw2Vectors(vD, vB) angleBD = 180 / np.pi * angleBDlad rotB = rotateVector(vB, angleADlad) coefB = np.sqrt(coefA * coefA / (coefA * coefA - rotB[0] * rotB[0]) * rotB[1] * rotB[1]) eccentricAnomalyDB = 180 / np.pi * np.arctan( coefA / coefB * np.tan(angleBDlad)) arcDB.moveTo(cp[0] + sign * coefA, cp[1]) arcDB.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB, startAngle, eccentricAnomalyDB) angleAB = 180 / np.pi * sign * angleBw2Vectors(vA, vD) else: rotB = (np.sqrt(vB[0] * vB[0] + vB[1] * vB[1]), 0) coefA = rotB[0] angleABlad = sign * angleBw2Vectors(vA, vB) angleAB = 180 / np.pi * angleABlad angleDBlad = sign * angleBw2Vectors(vD, vB) angleDB = 180 / np.pi * angleDBlad rotD = rotateVector(vD, angleABlad) coefB = np.sqrt(coefA * coefA / (coefA * coefA - rotD[0] * rotD[0]) * rotD[1] * rotD[1]) eccentricAnomalyDB = -180 / np.pi * np.arctan( coefA / coefB * np.tan(angleDBlad)) arcDB.moveTo(cp[0] + sign * coefA, cp[1]) arcDB.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB, startAngle, eccentricAnomalyDB) imgAC = self.scenes[viewIndex].addLine(a[0], a[1], cp[0], cp[1], pen=QPen(QColor( hbDict['color']))) imgBC = self.scenes[viewIndex].addLine(b[0], b[1], c[0], c[1], pen=QPen(QColor( hbDict['color']))) imgAD = self.scenes[viewIndex].addPath(arcAD, pen=QPen(QColor( hbDict['color']))) imgAD.setTransform(QTransform().translate( cp[0], cp[1]).rotate(-angleAD).translate(-cp[0], -cp[1])) imgDB = self.scenes[viewIndex].addPath(arcDB, pen=QPen(QColor( hbDict['color']))) imgDB.setTransform(QTransform().translate( cp[0], cp[1]).rotate(-angleAB).translate(-cp[0], -cp[1])) hbDict['images'] = [imgAD, imgDB, imgBC, imgAC]
def paintEvent(self, event): # print self.height() s = (self.target_angle - self.angle) * 0.09 self.angle += s if math.fabs(self.angle - self.target_angle) < 0.001: self.angle = self.target_angle self.timer.stop() painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) qp = QPainterPath() width = min(self.height(), (self.width() / 2)) height = self.height() # center x = self.width() / 2 big_radius = 1000 y = big_radius + 10 small_radius = big_radius - 15 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) / math.pi * 180.0 * 0.95 qp.arcMoveTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 2 * ac) qp.arcTo(x - small_radius, y - small_radius, 2 * small_radius, 2 * small_radius, 90 + ac, -2 * ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 0) # qp.lineTo(x+big_radius,y) grange = ac * 2.0 / 360.0 # Centered on 0, starting at angle 90-ac, counterclockwise self.gradient = QConicalGradient(0, 0, 90 - ac - 1) if self.gradient_type == 1: self.gradient.setColorAt(0, Qt.GlobalColor.red) self.gradient.setColorAt(0.1, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.2, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) elif self.gradient_type == 2: self.gradient.setColorAt(0, Qt.GlobalColor.green) self.gradient.setColorAt(0.6 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(1 * grange, Qt.GlobalColor.red) elif self.gradient_type == 3: self.gradient.setColorAt(0 * grange, Qt.GlobalColor.red) self.gradient.setColorAt(0.05 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.1 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.4 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.45 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.5 * grange, Qt.GlobalColor.red) self.gradient.setCenter(x, y) painter.fillPath(qp, QBrush(self.gradient)) pen = QPen() pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(1, int(1 * self.width() / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() #qp.moveTo(0,0) #qp.lineTo(x,y) #qp.lineTo(self.width(),0) angle = 0 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) * 0.95 if self.direction == self.UNIDIRECTIONAL: angle = math.pi / 2 + ac * (1 - 2 * self.angle) elif self.direction == self.BIDIRECTIONAL: angle = math.pi / 2 - self.angle * ac length = big_radius + 10 short_length = small_radius - 10 qp.moveTo(x + math.cos(angle) * short_length, y - math.sin(angle) * short_length) qp.lineTo(x + math.cos(angle) * length, y - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() delta = self.width() * 0.025 # print "{}-{} {} c:{}".format(x,y,delta,math.cos(angle)) qp.moveTo(x + delta + math.cos(angle) * short_length, y + delta - math.sin(angle) * short_length) qp.lineTo(x + delta + math.cos(angle) * length, y + delta - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(QColor.fromRgbF(0, 0, 0, 0.3)) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() qp.addRect(0, 0, self.width(), self.height()) painter.drawPath(qp)