def __init__(self, toolbox, x, y, w, h, name): """Importer icon for the Design View. Args: toolbox (ToolBoxUI): QMainWindow instance x (float): Icon x coordinate y (float): Icon y coordinate w (float): Width of master icon h (float): Height of master icon name (str): Item name """ super().__init__( toolbox, x, y, w, h, name, ":/icons/project_item_icons/database-import.svg", icon_color=QColor("#990000"), background_color=QColor("#ffcccc"), ) src_item = QGraphicsTextItem("\uf15c") src_item.setDefaultTextColor("#0000ff") dst_item = QGraphicsTextItem("\uf1c0") dst_item.setDefaultTextColor("#cc33ff") self.animation = ImportExportAnimation(self, src_item, dst_item) self.start_animation = self.animation.start self.stop_animation = self.animation.stop
def __init__(self, mask_scene, stage=1): super().__init__() self.mask_scene = mask_scene self.y_list = [300, 400] self.selected = 0 self.stage = stage self.one_play_text_item = QGraphicsTextItem() self.two_plays_text_item = QGraphicsTextItem() self.indicator_item = None self.start = False self.init()
def setPlayer(self): self.playerWidget = QGraphicsVideoItem() self.scene = QGraphicsScene() self.view = QGraphicsView(self.scene) self.view.resize(1280, 730) self.scene.addItem(self.playerWidget) self.stack.addWidget(self.view) self.player = QMediaPlayer(self, QMediaPlayer.VideoSurface) self.player.setVideoOutput(self.playerWidget) self.view.installEventFilter(self) self.view.show() self.srtTextItemDict = {0: QGraphicsTextItem(), 1: QGraphicsTextItem(), 2: QGraphicsTextItem(), 3: QGraphicsTextItem(), 4: QGraphicsTextItem()} for _, srtTextItem in self.srtTextItemDict.items(): self.scene.addItem(srtTextItem)
def __init__(self, graphWidget, state): super(AbstractNode, self).__init__() self.graph = weakref.ref(graphWidget) self.isAcceptable = state.isAcceptable self.isCurrent = state.isCurrent self.newPos = QPointF() self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setCacheMode(self.DeviceCoordinateCache) self.setZValue(-1) self.setAcceptHoverEvents(True) self._edges = [] self.currentFill = self.fillQColor self.border = QGraphicsEllipseItem(-self.radius, -self.radius, self.radius * 2, self.radius * 2) self.finalNodeBorder = QGraphicsEllipseItem(-self.radius + 5, -self.radius + 5, self.radius * 2 - 10, self.radius * 2 - 10) self.finalNodeBorder.mapToParent(self.border.pos()) if self.isAcceptable == False: pen = self.finalNodeBorder.pen() pen.setColor(QColor(25, 255, 5)) self.finalNodeBorder.update() if self.isCurrent == True: self.resolveFillColor() self.labelBox = QGraphicsTextItem(self) self.labelBox.setPos(-self.radius / 2, -self.radius / 2) self.labelBox.setDefaultTextColor(QColor(0, 0, 0))
def __init__(self, parent, color, text_color, text_start="", margins=(0, 0, 0, 0), dp=1, is_upload=False): self._parent = parent self._color = color self._text_color = text_color self._text_start = text_start self._left, self._top, self._right, self._bottom = margins self._dp = dp self._is_upload = is_upload self._line = QGraphicsLineItem(self._parent) self._line.setZValue(12) pen = QPen(self._color) pen.setWidth(1) pen.setStyle(Qt.DashLine) self._line.setPen(pen) if not self._is_upload: self._text_item = QGraphicsTextItem(self._parent) self._text_item.setZValue(11) self._text_item.setDefaultTextColor(self._text_color) font = self._text_item.font() font_size = 10 * self._dp if font_size > 0: self._text_item.setFont(QFont(font.family(), font_size))
def overlay_text( self, message: str, color: int, size: int, x: int, y: int, timeout: int, font_name: str, centered: bool, shadow: bool, ): gfx = QGraphicsTextItem(message) gfx.setDefaultTextColor(decode_color(color)) font = QFont(font_name, min(50, size)) font.setStyleHint(QFont.SansSerif) gfx.setFont(font) if shadow: effect = QGraphicsDropShadowEffect(gfx) effect.setBlurRadius(0) effect.setColor(Qt.GlobalColor.black) effect.setOffset(1, 1) gfx.setGraphicsEffect(effect) if centered: # The provided x, y is at the center of the text bound = gfx.boundingRect() gfx.setPos(x - (bound.width() / 2), y - (bound.height() / 2)) else: gfx.setPos(x, y) self._finalize_gfx(gfx, timeout)
def _complete_graph(self, x, y): """ Args: x (list): Horizontal coordinates y (list): Vertical coordinates """ if self.layout_gens: return self.hidden_items.clear() self.removed_items.clear() self.selected_items.clear() self.heat_map_items.clear() self.scene.clear() if not self._make_new_items(x, y): self._blank_item = QGraphicsTextItem("Nothing to show.") self.scene.addItem(self._blank_item) self.ui.actionExport_graph_as_pdf.setEnabled(False) else: self._add_new_items() # pylint: disable=no-value-for-parameter self.ui.actionExport_graph_as_pdf.setEnabled(True) if not self._persistent: self.ui.graphicsView.reset_zoom() else: self.ui.graphicsView.apply_zoom() self.graph_build_finished.emit()
def create_qr_scene(self, scene, qr_pixel_map, qr_text, backgound_pixmap) : pixmap_item = QGraphicsPixmapItem(qr_pixel_map) pixmap_item.setY(100) pixmap_item.setX(100) background_item = QGraphicsPixmapItem(backgound_pixmap) url_item = QGraphicsTextItem(qr_text) url_item.setFont(QFont('Arial', 50)) url_item.setTextWidth(820) url_item.setY(450) url_item.setX(1150) url_item.setZValue(1) pixmap_item.setZValue(1) background_item.setZValue(-1) scene.addItem(pixmap_item) scene.addItem(url_item) scene.addItem(background_item) return scene
def create_start_scene(self, scene, qr_pixel_map): text_item = QGraphicsTextItem("Wilkommen zur Photobox bitte den Start Button Drücken") text_item.setFont(QFont('Arial', 50)) pixmap_item = QGraphicsPixmapItem(qr_pixel_map) scene.addItem(pixmap_item) return scene
def __init__(self, port: 'Port', parent: QGraphicsItem = None, menuEnabled: bool = True): """ Constructs a portGraphics object for the given Port object. :param port: The port for which this graphics item represents. :type port: Port :param parent: A QGraphicsItem (probably an actionGraphics object) :type parent: QGraphicsItem :param menuEnabled: If true, a context menu will be shown on right-click. :type menuEnabled: bool """ QGraphicsItem.__init__(self, parent) self.setAcceptDrops(True) self.setFlag(QGraphicsItem.ItemIsSelectable) self._port = port self._menuEnabled = menuEnabled self.menu = PortMenu() # If port is required and it's an input, make the border thicker if not self._port.isOptional() and self._port in self._port.getAction( ).getInputPorts(): self.borderWidth = PortGraphics.REQUIRED_PEN_WIDTH else: self.borderWidth = PortGraphics.OPTIONAL_PEN_WIDTH # show port name and type if self._menuEnabled: fm = QFontMetricsF(PortGraphics.NAME_FONT) name = fm.elidedText(self._port.getName(), Qt.ElideRight, PortGraphics.SIDE_HEIGHT) self.nameItem = QGraphicsTextItem(name, self) self.nameItem.setFont(PortGraphics.NAME_FONT) self.nameItem.setRotation(90) self.nameItem.setPos(PortGraphics.WIDTH / 2 + 5, -PortGraphics.TOTAL_HEIGHT / 2) fm = QFontMetricsF(PortGraphics.TYPE_FONT) t = fm.elidedText(self._port.getDataType().__name__, Qt.ElideRight, PortGraphics.SIDE_HEIGHT) self.typeItem = QGraphicsTextItem(t, self) self.typeItem.setFont(PortGraphics.TYPE_FONT) self.typeItem.setRotation(90) self.typeItem.setPos(5, -PortGraphics.TOTAL_HEIGHT / 2)
def __init__(self, line: QLineF): super().__init__(line) self.setAcceptHoverEvents(True) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) pen = QPen() pen.setWidth(5) self.setPen(pen) self.__p1Ends = QGraphicsTextItem('1', self) self.__p2Ends = QGraphicsTextItem('2', self) self.__updateTextLinePos() self.__currentEndsMove = MoveLineEnds.NONE self.__currentEndsHover = MoveLineEnds.NONE self.__endsCapture = [None, None] self.__tryCapture = None self.__blockMove = False
def __init__(self, *a, **kw): data = kw.pop("data") self.name = kw.pop("name") self.window = kw.pop("window") super().__init__(0, 0, 0, 0) self.setAcceptedMouseButtons(Qt.LeftButton) self.label = QGraphicsTextItem("", self) self.bottom_edge = QGraphicsRectItem(0, 0, 0, 0, self) self.bottom_edge.setBrush(QBrush("red", Qt.SolidPattern)) self.update_visuals(data)
def add_human_by_pos(self, id, pos): x, y = pos human = QGraphicsEllipseItem(0, 0, 200, 200) self._scene.addItem(human) human.setBrush(QBrush(Qt.black, style=Qt.SolidPattern)) human_text = QGraphicsTextItem(str(pos)) font = QFont("Helvetica [Cronyx]", 40, QFont.Bold) human_text.setFont(font) human_text.setParentItem(human) human.setPos(pos[0], pos[1]) self._humans[id] = human human.setZValue(30)
def __init__(self, x, y, w, h, parent): super().__init__(x, y, w, h, parent) self._parent = parent color = QColor("slateblue") self.setBrush(qApp.palette().window()) # pylint: disable=undefined-variable self._text_item = QGraphicsTextItem(self) font = QFont('Font Awesome 5 Free Solid') self._text_item.setFont(font) self._text_item.setPos(0, 0) self._text_item.setPlainText("\uf0b0") self._text_item.setDefaultTextColor(color) self._text_item.setPos(self.sceneBoundingRect().center() - self._text_item.sceneBoundingRect().center()) self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
def __init__(self, main_window, stage=1): super().__init__() self.main_window = main_window self.stage = stage self.upper_mask = QGraphicsRectItem(0, 0, content_width, 0) self.lower_mask = QGraphicsRectItem(0, content_height, content_width, 0) self.stage_text_item = QGraphicsTextItem() self.mask_height = 0 self.animation_timer_1 = QTimer() self.animation_timer_2 = QTimer() self.animation_timer_3 = QTimer() self.selected = None self.init()
def __init__(self, x, y, w, h, parent): super().__init__(x, y, w, h, parent) self._parent = parent color = QColor("slateblue") self.setBrush(qApp.palette().window()) # pylint: disable=undefined-variable self._text_item = QGraphicsTextItem(self) font = QFont('Font Awesome 5 Free Solid') self._text_item.setFont(font) self._text_item.setDefaultTextColor(color) self._svg_item = QGraphicsSvgItem(self) self._datapkg_renderer = QSvgRenderer() self._datapkg_renderer.load(":/icons/datapkg.svg") self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False) self._block_updates = False
def __init__(self, name='node', parent=None): super(NodeItem, self).__init__(name, parent) pixmap = QtGui.QPixmap(ICON_NODE_BASE) if pixmap.size().height() > NODE_ICON_SIZE: pixmap = pixmap.scaledToHeight(NODE_ICON_SIZE, QtCore.Qt.SmoothTransformation) self._properties['icon'] = ICON_NODE_BASE self._icon_item = QGraphicsPixmapItem(pixmap, self) self._icon_item.setTransformationMode(QtCore.Qt.SmoothTransformation) self._text_item = QGraphicsTextItem(self.name, self) self._x_item = XDisabledItem(self, 'DISABLED') self._input_items = {} self._output_items = {} self._widgets = {}
def __init__(self, item, duration=2000, count=5, percentage_size=0.24, x_shift=0): """Initializes animation stuff. Args: item (QGraphicsItem): The item on top of which the animation should play. """ self._item = item self.cubes = [QGraphicsTextItem("\uf1b2", item) for i in range(count)] self.opacity_at_value_path = QPainterPath(QPointF(0.0, 0.0)) self.opacity_at_value_path.lineTo(QPointF(0.01, 1.0)) self.opacity_at_value_path.lineTo(QPointF(0.5, 1.0)) self.opacity_at_value_path.lineTo(QPointF(1.0, 0.0)) self.time_line = QTimeLine() self.time_line.setLoopCount(0) # loop forever self.time_line.setFrameRange(0, 10) self.time_line.setDuration(duration) self.time_line.setCurveShape(QTimeLine.LinearCurve) self.time_line.valueChanged.connect( self._handle_time_line_value_changed) self.time_line.stateChanged.connect( self._handle_time_line_state_changed) font = QFont('Font Awesome 5 Free Solid') item_rect = item.rect() cube_size = percentage_size * 0.875 * item_rect.height() font.setPixelSize(cube_size) rect = item_rect.translated(-0.5 * cube_size + x_shift, -cube_size) end = rect.center() ctrl = end - QPointF(0, 0.6 * rect.height()) lower, upper = 0.2, 0.8 starts = [lower + i * (upper - lower) / count for i in range(count)] starts = [ rect.topLeft() + QPointF(start * rect.width(), 0) for start in starts ] self.paths = [QPainterPath(start) for start in starts] for path in self.paths: path.quadTo(ctrl, end) self.offsets = [i / count for i in range(count)] for cube in self.cubes: cube.setFont(font) cube.setDefaultTextColor("#003333") cube.setTransformOriginPoint(cube.boundingRect().center()) cube.hide() cube.setOpacity(0)
def __init__(self, parent): """An icon to show information about the item's execution. Args: parent (ProjectItemIcon): the parent item """ super().__init__(parent) self._parent = parent self._execution_state = "not started" self._text_item = QGraphicsTextItem(self) font = QFont('Font Awesome 5 Free Solid') self._text_item.setFont(font) parent_rect = parent.rect() self.setRect(0, 0, 0.5 * parent_rect.width(), 0.5 * parent_rect.height()) self.setPen(Qt.NoPen) self.setBrush(qApp.palette().window()) # pylint: disable=undefined-variable self.setAcceptHoverEvents(True) self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False) self.hide()
def __init__(self, graphics_port: "GraphicsPort", port_name_position: "PortNamePosition"): self.__graphics_port = graphics_port self.__port_name = QGraphicsTextItem(parent=graphics_port) self.__port_name.setPlainText(graphics_port._port.name) self.__port_name.setDefaultTextColor("#FFFFFF") self.__port_name.setFlag(QGraphicsItem.ItemStacksBehindParent) self.port_name_position = port_name_position # Colors/Pens/Brushes self.__color = TypeColor.get_color_for(graphics_port._port.port_type) self.__outline_pen = QPen(self.__color.darker()) self.__outline_pen.setWidthF(2) self.__background_brush = QBrush(self.__color) self.__dashed_outline_pen = QPen(self.__color) self.__dashed_outline_pen.setStyle(Qt.DashLine) self.__dashed_outline_pen.setWidth(2)
def __init__(self, graphics_node: "GraphicsNode"): self.__graphics_node = graphics_node # Dimensions self.padding = 12 self.clickable_margin = 15 self.round_edge_size = 10 self.window_outline_width = 4 # Colors/Pens/Brushes self.__title_color = Qt.white self.__outline_selected_color = QColor("#FFA637") self.__outline_default_color = QColor("#000000") self.__outline_pen = QPen(self.__outline_default_color) self.__title_background_brush = QBrush(QColor("#FF313131")) self.__background_brush = QBrush(QColor("#E3212121")) self.__window_markers_pen = QPen(self.__outline_default_color) self.__window_markers_brush = QBrush(self.__outline_default_color) # Graphics Components self.__graphics_title = QGraphicsTextItem(parent=graphics_node) self.__graphics_title.setDefaultTextColor(self.__title_color) self.__graphics_title.setPlainText(self.__graphics_node.title) self.__graphics_title.setPos(self.padding, 0) # Position ProxyWidget self.repositionWidget() # position GraphicsPort objects def position_graphics_ports(x_offset, graphics_ports_dict): for i, graphics_port in enumerate(graphics_ports_dict.values()): graphics_port.setPos( x_offset, self.title_height() + (graphics_port.radius * 4) * (i + 1)) position_graphics_ports(0, self.__graphics_node.inputs) position_graphics_ports(self.boundingRect().width(), self.__graphics_node.outputs)
def dibujar(self): pen = QPen() brush = QBrush() pen.setWidth(3) for i in self.organizador: color = QColor(i.red, i.green, i.blue) brush.setStyle(Qt.SolidPattern) brush.setColor(color) pen.setColor(color) self.scene.addEllipse(i.or_x, i.or_y, 7, 7, pen, brush) self.scene.addEllipse(i.de_x, i.de_y, 7, 7, pen, brush) self.scene.addLine((i.or_x) + 3.5, (i.or_y) + 3.5, (i.de_x) + 3.5, (i.de_y) + 3.5, pen) for keys in self.organizador.grafo_dic: text = QGraphicsTextItem(str(keys)) text.setFlag(QGraphicsItem.ItemIsMovable) text.setFont(QFont("TimesNewRoman", 12, QFont.ExtraBold)) self.scene.addItem(text) text.setPos(keys[0], keys[1])
def add_output(self, name='output', multi_port=False, display_name=True): """ Args: name (str): name for the port. multi_port (bool): allow multiple connections. display_name (bool): display the port name. Returns: PortItem: output item widget """ port = PortItem(self) port.name = name port.port_type = OUT_PORT port.multi_connection = multi_port port.display_name = display_name text = QGraphicsTextItem(port.name, self) text.font().setPointSize(8) text.setFont(text.font()) text.setVisible(display_name) self._output_items[port] = text if self.scene(): self.post_init() return port
def __init__(self, parent: QWidget = None) -> None: """ Create a GraphicsView for Facile. :param parent: The widget to embed the graphics view into :type parent: QWidget :return: None :rtype: NoneType """ super(FacileGraphicsView, self).__init__(parent) # set flags self.setDragMode(QGraphicsView.ScrollHandDrag) self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) # show initial message scene = QGraphicsScene() box = QGraphicsRectItem(0, 0, 100, 100) box.setPen(QColor(Qt.transparent)) box.setBrush(QColor(Qt.transparent)) QGraphicsTextItem("Nothing to show here yet!", box) scene.addItem(box) self.setScene(scene)
def build_graph(self, timeit=False): """Builds the graph.""" tic = time.clock() new_items = self._get_new_items() wip_relationship_items = self._get_wip_relationship_items() scene = self.new_scene() if not new_items and not wip_relationship_items: item = QGraphicsTextItem("Nothing to show.") scene.addItem(item) else: if new_items: object_items = new_items[0] self._add_new_items(scene, *new_items) # pylint: disable=no-value-for-parameter else: object_items = [] if wip_relationship_items: self._add_wip_relationship_items(scene, wip_relationship_items, object_items) self.hidden_items.clear() self.extend_scene() toc = time.clock() _ = timeit and self.msg.emit( "Graph built in {} seconds\t".format(toc - tic)) self.graph_created.emit()
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)
def __init__(self, cModel, targetImage=None, axeSize=500, LUTSize=LUTSIZE, layer=None, parent=None, mainForm=None): """ @param cModel: color space used by colorPicker, slider2D and colorPicker @type cModel: cmConverter object @param axeSize: size of the color wheel @type axeSize: int @param targetImage: @type targetImage: imImage @param LUTSize: @type LUTSize: int @param layer: layer of targetImage linked to graphics form @type layer : QLayer @param parent: @type parent: """ super().__init__(parent=parent) self.mainForm = mainForm # used by saveLUT() # context help tag self.helpId = "LUT3DForm" self.cModel = cModel border = 20 self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.setMinimumSize(axeSize + 90, axeSize + 200) self.setAttribute(Qt.WA_DeleteOnClose) self.setBackgroundBrush(QBrush(Qt.black, Qt.SolidPattern)) self.currentHue, self.currentSat, self.currentPb = 0, 0, self.defaultColorWheelBr self.currentR, self.currentG, self.currentB = 0, 0, 0 self.size = axeSize # back links to image self.targetImage = weakProxy(targetImage) self.layer = weakProxy(layer) # currently selected grid node self.selected = None self.graphicsScene = QGraphicsScene() self.graphicsScene.options = None self.setScene(self.graphicsScene) # back to image layer self.graphicsScene.layer = weakProxy(layer) # init LUT freshLUT3D = LUT3D(None, size=LUTSize, alpha=True) self.graphicsScene.lut = freshLUT3D # init 2D slider QImg = hueSatPattern(axeSize, axeSize, cModel, bright=self.defaultColorWheelBr, border=border) self.graphicsScene.slider2D = colorChooser(cModel, QImg, target=self.targetImage, size=axeSize, border=border) self.graphicsScene.selectMarker = activeMarker.fromCross(parent=self.graphicsScene.slider2D) self.graphicsScene.selectMarker.setPos(axeSize / 2, axeSize / 2) # color wheel event handler def f1(p, r, g, b): h, s, br = self.cModel.rgb2cm(r, g, b) self.currentHue, self.currentSat, self.currentPb = h, s, br self.currentR, self.currentG, self.currentB = r, g, b self.bSliderUpdate() self.displayStatus() self.graphicsScene.slider2D.onMouseRelease = f1 self.graphicsScene.addItem(self.graphicsScene.slider2D) # Brightness slider self.bSliderHeight = 20 self.bSliderWidth = self.graphicsScene.slider2D.QImg.width() px = brightnessPattern(self.bSliderWidth, self.bSliderHeight, cModel, self.currentHue, self.currentSat).rPixmap self.graphicsScene.bSlider = QGraphicsPixmapItem(px, parent=self.graphicsScene.slider2D) self.graphicsScene.bSlider.setPos(QPointF(-border, self.graphicsScene.slider2D.QImg.height() - border)) bSliderCursor = activeMarker.fromTriangle(parent=self.graphicsScene.bSlider) bSliderCursor.setMoveRange(QRectF(0.0, bSliderCursor.size, self.graphicsScene.bSlider.pixmap().width(), 0.0)) bSliderCursor.setPos(self.graphicsScene.bSlider.pixmap().width() * self.defaultColorWheelBr, bSliderCursor.size) # cursor event handlers def f2(e, p, q): self.currentPb = p / float(self.bSliderWidth) QToolTip.showText(e.screenPos(), (str(int(self.currentPb * 100.0))), self) bSliderCursor.onMouseMove = f2 def f3(e, p, q): self.currentPb = p / float(self.bSliderWidth) self.graphicsScene.slider2D.QImg.setPb(self.currentPb) self.graphicsScene.slider2D.setPixmap(self.graphicsScene.slider2D.QImg.rPixmap) self.displayStatus() bSliderCursor.onMouseRelease = f3 # status bar offset = 60 self.graphicsScene.statusBar = QGraphicsTextItem() self.graphicsScene.statusBar.setPos(-20, axeSize + offset) self.graphicsScene.statusBar.setDefaultTextColor(QColor(255, 255, 255)) self.graphicsScene.statusBar.setPlainText('') self.graphicsScene.addItem(self.graphicsScene.statusBar) self.displayStatus() # self.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) # grid self.grid = activeGrid(self.graphicsScene.lut.size, self.cModel, parent=self.graphicsScene.slider2D) self.graphicsScene.grid = self.grid # buttons pushButton1 = QbLUePushButton("Reset Grid") pushButton1.clicked.connect(self.onReset) pushButton2 = QbLUePushButton("Save LUT") pushButton2.clicked.connect(self.saveLUT) pushButton3 = QbLUePushButton("Smooth Grid") pushButton3.clicked.connect(self.onSmoothGrid) pushButton4 = QbLUePushButton('Set Mask') pushButton4.clicked.connect(self.setMask) # pushButton4 needs enabling/disabling self.pushButton4 = pushButton4 # options options1, optionNames1 = ['use image', 'use selection'], ['Use Image', 'Use Selection'] self.listWidget1 = optionsWidget(options=options1, optionNames=optionNames1, exclusive=True) """ def onSelect1(item): self.graphicsScene.options['use selection'] = item is self.listWidget1.items['use selection'] self.listWidget1.onSelect = onSelect1 """ self.listWidget1.setFocusPolicy(Qt.NoFocus) # set initial selection to 'use image' self.listWidget1.checkOption(self.listWidget1.intNames[0]) options2, optionNames2 = ['add node', 'remove node'], ['Add Node', 'Remove Node'] self.listWidget2 = optionsWidget(options=options2, optionNames=optionNames2, exclusive=True) """ def onSelect2(item): self.graphicsScene.options['add node'] = item is self.listWidget2.items['add node'] self.listWidget2.onSelect = onSelect2 """ # set initial selection to add node' self.listWidget2.checkOption(self.listWidget2.intNames[0]) options3 = ['select neighbors', 'reset removed nodes', 'show histogram', 'keep alpha'] optionNames3 = ['Select Neighbors', 'Reset Removed', 'Show Histogram', 'Keep Alpha'] self.listWidget3 = optionsWidget(options=options3, optionNames=optionNames3, exclusive=False) self.listWidget3.checkOption(self.listWidget3.intNames[0]) self.listWidget3.checkOption(self.listWidget3.intNames[1]) def onSelect3(item): option = item.internalName if option == 'show histogram': self.graphicsScene.slider2D.showTargetHist = self.graphicsScene.options[option] # .isChecked() self.graphicsScene.slider2D.updatePixmap() return if option == 'keep alpha': self.enableButtons() self.layer.applyToStack() self.listWidget3.onSelect = onSelect3 # set initial selection to 'select naighbors' item = self.listWidget3.items[options3[0]] item.setCheckState(Qt.Checked) self.graphicsScene.options = UDict((self.listWidget1.options, self.listWidget2.options, self.listWidget3.options)) # layouts hlButtons = QHBoxLayout() hlButtons.addWidget(pushButton1) hlButtons.addWidget(pushButton3) hlButtons.addWidget(pushButton2) hl = QHBoxLayout() vl1 = QVBoxLayout() vl1.addWidget(self.listWidget1) vl1.addWidget(pushButton4) hl.addLayout(vl1) hl.addWidget(self.listWidget2) hl.addWidget(self.listWidget3) vl = QVBoxLayout() for l in [hlButtons, hl]: vl.addLayout(l) # Init QWidget container for adding buttons and options to graphicsScene container = QWidget() container.setObjectName("container") container.setLayout(vl) ss = """QWidget#container{background: black}\ QListWidget{background-color: black; selection-background-color: black; border: none; font-size: 7pt}\ QListWidget::item{color: white;}\ QListWidget::item::selected{background: black; border: none}""" container.setStyleSheet(ss) for wdg in [self.listWidget1, self.listWidget2, self.listWidget3]: wdg.setMinimumWidth(wdg.sizeHintForColumn(0)) wdg.setMinimumHeight(wdg.sizeHintForRow(0)*len(wdg.items)) container.setGeometry(-offset//2, axeSize + offset - 20, axeSize + offset, 20) self.graphicsScene.addWidget(container) #container.setStyleSheet("QPushButton {color: white;}\ # QPushButton:pressed, QPushButton:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #0d5ca6, stop: 1 #2198c0);}") self.setWhatsThis( """ <b>2.5D LUT Editor</b><br> HSpB layers are slower than HSV, but usually they give better results.<br> <b>Select nodes</b> with mouse clicks on the image. Selected nodes are shown as small black circles on the color wheel.<br> <b>Modify the color</b> of a node by dragging it on the wheel. Several nodes can be moved simultaneously by grouping them.<br> <b>Group nodes</b> :<br> 1 - select them with the mouse : while pressing the mouse left button, drag a rubber band around the nodes to select;<br> 2 - next, right click any one of the selected nodes and choose group from the context menu<br> <b>unselect nodes</b> :<br> 1 - check the option Remove Node;<br> 2 - ungroup;<br> 3 - on the image, click the pixels to unselect.<br> <b>Caution</b> : Selecting nodes with the mouse is enabled only when the Color Chooser is closed.<br> Click the <b> Smooth Grid</b> button to smooth color transitions between neighbor nodes.<br> Check the <br>Keep Alpha</b> option to forward the alpha channel without modifications.<br> This option must be unchecked to build a mask from the 3D LUT.<br> """ ) # end of setWhatsThis
def draw_message(self, text: str, name: str, window_type="standard", mode=0, left=True) -> QGraphicsItemGroup: # Create the message box talk_window: QPixmap = self.view.talk_windows[window_type][mode] message_box = self.scene.addPixmap(talk_window) talk_window_x = _TALK_WINDOW_MODE_0_X if not mode else -3 talk_window_y = _TALK_WINDOW_Y if not mode else _TALK_WINDOW_Y - 5 message_box.setPos(talk_window_x, talk_window_y) # Create the name plate name_plate_texture: QPixmap = self.view.talk_windows["name_plate"][ "plate"] name_plate = self.scene.addPixmap(name_plate_texture) name_plate_x = _NAME_PLATE_LEFT_X if left else _NAME_PLATE_RIGHT_X name_plate.setPos(name_plate_x, _NAME_PLATE_Y) # Create the name plate text name_plate_text = QGraphicsTextItem() name_plate_text.setPlainText(name) name_plate_text.setDefaultTextColor(QColor.fromRgba(0xFFFFFFB3)) name_plate_text.setFont(self.view.name_plate_font) name_plate_text.setTextWidth(name_plate_texture.width()) name_plate_text.setPos(name_plate_x, _NAME_PLATE_Y) # Center the name plate text block_format = QTextBlockFormat() block_format.setAlignment(QtGui.Qt.AlignCenter) cursor = name_plate_text.textCursor() cursor.select(QTextCursor.Document) cursor.mergeBlockFormat(block_format) cursor.clearSelection() name_plate_text.setTextCursor(cursor) self.scene.addItem(name_plate_text) # Create the message box text. Draw two lines if required. # Truncate lines with width > 312 split_text = text.split("\n") message_box_text = QGraphicsTextItem() message_box_text_2 = QGraphicsTextItem() if split_text and split_text[0]: text_utils.draw_message_text(message_box_text, self.view.name_plate_font, split_text[0], _TALK_WINDOW_MODE_0_X + 20, _TALK_WINDOW_Y + 5, 312) if len(split_text) > 1 and split_text[1]: text_utils.draw_message_text(message_box_text_2, self.view.name_plate_font, split_text[1], _TALK_WINDOW_MODE_0_X + 20, _TALK_WINDOW_Y + 21, 312) group = self.scene.createItemGroup([ message_box, message_box_text, message_box_text_2, name_plate, name_plate_text ]) group.setZValue(2.0) return group