def get_header_rect(self): header_height = 1.4 * self.title_label.boundingRect().height() # 35 * (self.parent_node.title.count('\n')+1) header_rect = QRectF() header_rect.setTopLeft(QPointF(-self.width/2, -self.height/2)) header_rect.setWidth(self.width) header_rect.setHeight(header_height) return header_rect
def boundingRect(self): # remember: (0, 0) shall be the NI's center! rect = QRectF() w = self.layout.geometry().width() h = self.layout.geometry().height() rect.setLeft(-w / 2) rect.setTop(-h / 2) rect.setWidth(w) rect.setHeight(h) return rect
def get_header_rect(w, h, title_rect): """ :param w: width :param h: height """ header_height = 1.4 * title_rect.height( ) # 35 * (self.parent_node.title.count('\n')+1) header_rect = QRectF() header_rect.setTopLeft(QPointF(-w / 2, -h / 2)) header_rect.setWidth(w) header_rect.setHeight(header_height) return header_rect
def get_title_rect(self): title_rect_offset_factor = 0.56 header_rect = self.get_header_rect() rect = QRectF() rect.setTop(header_rect.top() + (header_rect.height() / 2) * (1 - title_rect_offset_factor)) rect.setLeft(header_rect.left() + 10) rect.setHeight(header_rect.height() * title_rect_offset_factor) w = header_rect.width() * title_rect_offset_factor title_width = self.display_name_FM.width( get_longest_line(self.parent_node.title)) rect.setWidth(w if w > title_width else title_width) return rect
def show_all(self): # trick: # if user zoom in or zoom out too much view exceeds matrix limit # so need to set view's matrix to initial matrix self.setMatrix(self.initial_matrix) items = self.get_visible_items() rect = QRectF() for i in items: rect = rect.united(i.boundingRect()) # it is not working properly without updating the rect # need to set new position and edit rect's size rect.setX(rect.x() - 1) rect.setY(rect.y() - 1) rect.setWidth(rect.width() + 1) rect.setHeight(rect.height() + 1) self.fitInView(rect, Qt.KeepAspectRatio)
def paintPage(currentPage, totalpages, painter, doc, textrect, footerheight): painter.save() pagesize = QRectF(0, currentPage * doc.pageSize().height(), doc.pageSize().width(), doc.pageSize().height()) painter.setClipRect(textrect) painter.translate(0, -pagesize.top()) painter.translate(textrect.left(), textrect.top()) doc.drawContents(painter) painter.restore() footerrect = QRectF(textrect) footerrect.setTop(textrect.bottom()) footerrect.setHeight(footerheight) if doPageFooter: painter.drawText(footerrect, Qt.AlignVCenter | Qt.AlignRight, "Page {} of {}".format(currentPage + 1, totalpages))
def get_whole_scene_img(self): self.hide_proxies() img = QImage(self.sceneRect().width() / self.total_scale_div, self.sceneRect().height() / self.total_scale_div, QImage.Format_RGB32) img.fill(Qt.transparent) painter = QPainter(img) painter.setRenderHint(QPainter.Antialiasing) rect = QRectF() rect.setLeft(-self.viewport().pos().x()) rect.setTop(-self.viewport().pos().y()) rect.setWidth(img.rect().width()) rect.setHeight(img.rect().height()) # rect is right... but it only renders from the viewport's point down-and rightwards, not from topleft (0,0) ... self.render(painter, rect, rect.toRect()) self.show_proxies() return img
def paint(self, painter, option, widget=None): if Design.flow_theme == 'dark std': color = QColor( '#2E688C' ) if self.parent_port_instance.type_ == 'data' else QColor( '#3880ad') if option.state & QStyle.State_MouseOver: color = color.lighter() brush = QBrush(QColor(color)) painter.setBrush(brush) painter.setPen(Qt.NoPen) painter.drawEllipse( QRectF(self.padding, self.padding, self.painting_width, self.painting_height)) elif Design.flow_theme == 'dark tron': color = '' if self.parent_port_instance.type_ == 'exec': color = '#FFFFFF' elif self.parent_port_instance.type_ == 'data': color = self.parent_node_instance.parent_node.color pen = QPen(color) pen.setWidth(2) painter.setPen(pen) if len(self.parent_port_instance.connected_port_instances) > 0 or \ option.state & QStyle.State_MouseOver: # also fill when mouse hovers c = self.parent_node_instance.parent_node.color r = c.red() g = c.green() b = c.blue() brush = QBrush(QColor(r, g, b, 100)) painter.setBrush(brush) else: painter.setBrush(Qt.NoBrush) painter.drawEllipse( QRectF(self.padding, self.padding, self.painting_width, self.painting_height)) elif Design.flow_theme == 'ghostly' or Design.flow_theme == 'blender': color = '' if self.parent_port_instance.type_ == 'exec': color = '#FFFFFF' if len(self.parent_port_instance.connected_port_instances) > 0 or \ option.state & QStyle.State_MouseOver: # also fill when mouse hovers brush = QBrush(QColor(255, 255, 255, 100)) painter.setBrush(brush) else: painter.setBrush(Qt.NoBrush) elif self.parent_port_instance.type_ == 'data': color = self.parent_node_instance.parent_node.color if len(self.parent_port_instance.connected_port_instances) > 0 or \ option.state & QStyle.State_MouseOver: # also fill when mouse hovers c = self.parent_node_instance.parent_node.color r = c.red() g = c.green() b = c.blue() brush = QBrush(QColor(r, g, b, 100)) painter.setBrush(brush) else: painter.setBrush(Qt.NoBrush) pen = QPen(color) pen.setWidth(1) painter.setPen(pen) rect = QRectF() rect.moveCenter(QPointF(self.width / 2, self.height / 2)) rect.setWidth(self.painting_width) rect.setHeight(self.painting_height) painter.drawEllipse(QPointF(self.width / 2, self.height / 2), self.painting_width / 3, self.painting_height / 3)
def eventFilter(self, obj, event): if event.type() == QEvent.GraphicsSceneMousePress: if event.button() == Qt.MouseButton.LeftButton: self.mouse_pressed = True self.mouse_pressed_x, self.mouse_pressed_y = event.pos().x( ), event.pos().y() if self.draw_ellipse: ellipsis = QGraphicsEllipseItem(self.chart) ellipsis.setZValue(12) ellipsis.setBrush(QBrush(QColor(244, 67, 54, 50))) ellipsis.setPen(QPen(Qt.transparent)) self.ellipses.append(ellipsis) elif self.write_text: for t in self.texts: r = QRectF() r.setTopLeft(t.pos()) r.setWidth(t.boundingRect().width()) r.setHeight(t.boundingRect().height()) if r.contains(self.mouse_pressed_x, self.mouse_pressed_y): return True """ The user clicked over an area where there is no text. So we create one. """ text = QGraphicsTextItem(self.chart) text.setZValue(12) text.setPos( QPointF(self.mouse_pressed_x, self.mouse_pressed_y)) text.setPlainText("label") text.setAcceptHoverEvents(True) text.setTabChangesFocus(True) text.setFlags(QGraphicsTextItem.ItemIsMovable) text.installEventFilter(self.text_event_filter) self.texts.append(text) return True elif event.button() == Qt.MouseButton.RightButton: x, y = event.pos().x(), event.pos().y() for e in self.ellipses: if e.rect().contains(x, y): e.hide() self.ellipses.remove(e) for t in self.texts: r = QRectF() r.setTopLeft(t.pos()) r.setWidth(t.boundingRect().width()) r.setHeight(t.boundingRect().height()) if r.contains(x, y): t.hide() self.texts.remove(t) return True return QObject.eventFilter(self, obj, event) elif event.type() == QEvent.GraphicsSceneMouseRelease: self.mouse_pressed = False return True elif event.type() == QEvent.GraphicsSceneMouseMove: if self.mouse_pressed: if self.draw_ellipse: x, y = event.pos().x(), event.pos().y() width = x - self.mouse_pressed_x height = y - self.mouse_pressed_y self.ellipses[-1].setRect(self.mouse_pressed_x, self.mouse_pressed_y, width, height) return True return QObject.eventFilter(self, obj, event) return QObject.eventFilter(self, obj, event)