def paint(self, painter, option, widget): if self._source is None or self._dest is None: return # Get level of detail lod = option.levelOfDetailFromTransform(painter.worldTransform()) if lod < 0.1: return scene = self.scene() if scene is None: return line = QLineF(self.source_point, self.dest_point) if self._source != self._dest and qFuzzyCompare(line.length(), 0.): return # If selected, change color to red if option.state & QStyle.State_Selected: pen = scene.networkStyle().edgePen(selected=True) pen.setWidthF(self.pen().widthF()) painter.setPen(pen) else: painter.setPen(self.pen()) painter.drawPath(self.path())
def setPlaybackRate(self, rate): for i in range(self.rateBox.count()): if qFuzzyCompare(rate, self.rateBox.itemData(i)): self.rateBox.setCurrentIndex(i) return self.rateBox.addItem("%dx" % rate, rate) self.rateBox.setCurrentIndex(self.rateBox.count() - 1)
def setVideoSettings(self, settings): self.selectComboBoxItem(self.ui.videoCodecBox, settings.codec()) self.selectComboBoxItem(self.ui.videoResolutionBox, settings.resolution()) self.ui.videoQualitySlider.setValue(settings.quality()) for i in range(1, self.ui.videoFramerateBox.count()): itemRate = self.ui.videoFramerateBox.itemData(i) if qFuzzyCompare(itemRate, settings.frameRate()): self.ui.videoFramerateBox.setCurrentIndex(i) break
def paint(self, painter, option, widget): """ Customize line adding an arrow head :param QPainter painter: Painter instance of the item :param option: Painter option of the item :param widget: Widget instance """ if not self.source or not self.destination: return line = QLineF(self.source_point, self.destination_point) if qFuzzyCompare(line.length(), 0): return # Draw the line itself color = QColor() color.setHsv(120 - 60 / self.steps_max * self.steps, 180 + 50 / self.steps_max * self.steps, 150 + 80 / self.steps_max * self.steps) if self.highlighted: color.setHsv(0, 0, 0) style = self.line_style painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(line) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # Draw the arrows angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = (2.0 * math.pi) - angle # arrow in the middle of the arc hpx = line.p1().x() + (line.dx() / 2.0) hpy = line.p1().y() + (line.dy() / 2.0) head_point = QPointF(hpx, hpy) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) destination_arrow_p1 = head_point + QPointF( math.sin(angle - math.pi / 3) * self.arrow_size, math.cos(angle - math.pi / 3) * self.arrow_size) destination_arrow_p2 = head_point + QPointF( math.sin(angle - math.pi + math.pi / 3) * self.arrow_size, math.cos(angle - math.pi + math.pi / 3) * self.arrow_size) painter.setBrush(color) painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2])) if self.metadata["confirmation_text"]: painter.drawText(head_point, self.metadata["confirmation_text"])
def set_playback_rate(self, rate): """ :param rate: :return: """ for i in range(self.rateBox.count()): if qFuzzyCompare(rate, self.rateBox.itemData(i)): self.rateBox.setCurrentIndex(i) return # self.rateBox.addItem("%dx" % rate, rate) self.rateBox.setCurrentIndex(self.rateBox.count() - 1)
def paint(self, painter, option, widget): """ Customize line adding an arrow head :param QPainter painter: Painter instance of the item :param option: Painter option of the item :param widget: Widget instance """ if not self.source or not self.destination: return line = QLineF(self.source_point, self.destination_point) if qFuzzyCompare(line.length(), 0): return # Draw the line itself color = QColor() style = Qt.SolidLine if self.status == ARC_STATUS_STRONG: color.setNamedColor('blue') if self.status == ARC_STATUS_WEAK: color.setNamedColor('salmon') style = Qt.DashLine painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(line) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # Draw the arrows angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = (2.0 * math.pi) - angle # arrow in the middle of the arc hpx = line.p1().x() + (line.dx() / 2.0) hpy = line.p1().y() + (line.dy() / 2.0) head_point = QPointF(hpx, hpy) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) destination_arrow_p1 = head_point + QPointF( math.sin(angle - math.pi / 3) * self.arrow_size, math.cos(angle - math.pi / 3) * self.arrow_size) destination_arrow_p2 = head_point + QPointF( math.sin(angle - math.pi + math.pi / 3) * self.arrow_size, math.cos(angle - math.pi + math.pi / 3) * self.arrow_size) painter.setBrush(color) painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2])) if self.metadata["confirmation_text"]: painter.drawText(head_point, self.metadata["confirmation_text"])
def paint(self, painter, option, widget): """ Customize line adding an arrow head :param QPainter painter: Painter instance of the item :param option: Painter option of the item :param widget: Widget instance """ if not self.source or not self.destination: return line = QLineF(self.source_point, self.destination_point) if qFuzzyCompare(line.length(), 0): return # Draw the line itself color = QColor() style = Qt.SolidLine if self.status == ARC_STATUS_STRONG: color.setNamedColor('blue') if self.status == ARC_STATUS_WEAK: color.setNamedColor('salmon') style = Qt.DashLine painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(line) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # Draw the arrows angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = (2.0 * math.pi) - angle # arrow in the middle of the arc hpx = line.p1().x() + (line.dx() / 2.0) hpy = line.p1().y() + (line.dy() / 2.0) head_point = QPointF(hpx, hpy) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) destination_arrow_p1 = head_point + QPointF( math.sin(angle - math.pi / 3) * self.arrow_size, math.cos(angle - math.pi / 3) * self.arrow_size) destination_arrow_p2 = head_point + QPointF( math.sin(angle - math.pi + math.pi / 3) * self.arrow_size, math.cos(angle - math.pi + math.pi / 3) * self.arrow_size) painter.setBrush(color) painter.drawPolygon( QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2]))
def angle(self, angle): if not qFuzzyCompare(self.m_angle, angle): self.m_angle = angle self.updateMatrix() self.angleChanged.emit()
def radius(self, radius): if not qFuzzyCompare(self.m_radius, radius): self.m_radius = radius self.updateMatrix() self.radiusChanged.emit()