def __init__(self, parent, x, y, w, h, item): self.cmptEmitter = QtCore.QObject() iParent = item ''' self._rect = QtCore.QRectF(x,y,w,h) self._scene = parent print "self comptItem",self._scene.sceneContainer ," and",self._scene.sceneContainer.graphicsView self.mouseOver = False self.resizeHandleSize = 4.0 self.mousePressPos = None self.mouseMovePos = None self.mouseIsPressed = False #self.setAcceptsHoverEvents(True) self.updateResizeHandles() ''' if hasattr(iParent, "__iter__"): self.mobj = iParent[0] else: self.mobj = iParent self.layoutWidgetPt = parent QGraphicsRectItem.__init__(self, x, y, w, h) self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setFlag(QGraphicsItem.ItemIsSelectable) #self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1) QT_VERSION = str(QtCore.QT_VERSION_STR).split('.') QT_MINOR_VERSION = int(QT_VERSION[1]) if QT_MINOR_VERSION >= 6: #if config.QT_MINOR_VERSION >= 6: self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1) self.setAcceptHoverEvents(True) self.setToolTip(iParent.name)
def __init__(self): super(IDLocator, self).__init__() # Set up the user interface from Designer. self.ui = Ui_idLocator() self.ui.setupUi(self) self.scene = QGraphicsScene() self.view = QGraphicsView(self.scene) self.view.setRenderHint(QPainter.HighQualityAntialiasing) self.ui.imgLayout.addWidget(self.view) self.img = QPixmap() self.imgItem = QGraphicsPixmapItem(self.img) self.scene.addItem(self.imgItem) self.bottomRect = QGraphicsRectItem() self.brush = QBrush(QColor(0, 60, 80, 64)) self.bottomRect.setBrush(self.brush) self.topRect = QGraphicsRectItem() self.brush = QBrush(QColor(60, 0, 80, 64)) self.topRect.setBrush(self.brush) self.scene.addItem(self.bottomRect) self.scene.addItem(self.topRect) # Connect up the buttons. self.ui.goButton.clicked.connect(self.getToIt) self.ui.cancelButton.clicked.connect(self.close) self.grabFirstImage() self.setRectangles() self.ui.topSlider.valueChanged.connect(self.updateTopRect) self.ui.bottomSlider.valueChanged.connect(self.updateBottomRect) self.ui.topLayout.setAlignment(Qt.AlignHCenter) self.ui.bottomLayout.setAlignment(Qt.AlignHCenter)
def mousePressEvent(self, event): pos = event.scenePos() any_item = self.scene.item_at(pos) if not any_item and event.button() & Qt.LeftButton: self.modifiers = event.modifiers() self.selection_rect = QRectF(pos, QSizeF(0, 0)) self.rect_item = QGraphicsRectItem( self.selection_rect.normalized()) self.rect_item.setPen( QPen(QBrush(QColor(51, 153, 255, 192)), 0.4, Qt.SolidLine, Qt.RoundCap)) self.rect_item.setBrush(QBrush(QColor(168, 202, 236, 192))) self.rect_item.setZValue(-100) # Clear the focus if necessary. if not self.scene.stickyFocus(): self.scene.clearFocus() if not self.modifiers & Qt.ControlModifier: self.scene.clearSelection() event.accept() return True else: self.cancel(self.ErrorReason) return False
def __init__(self, pos, size, type_, parent=None, scene=None, areaBorder=2, index=0, textSize=50): QGraphicsRectItem.__init__(self, 0, 0, size.width(), size.height(), parent) self.setPos(pos) self.newEvent = IsClicked() self.newEvent.area = self #self.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsSelectable) ## set index label self.text = QGraphicsTextItem("%d" % index, self) self.setTextSize(textSize) ## TODO: How to create constants for the type? ## (such as constants in Qt) (enum?) self.kind = type_ pen = QPen(self.color, areaBorder, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) self.setPen(pen)
def draw_sep_area(self, y_mid, show_symbols=False): x = self.sceneRect().x() y = self.sceneRect().y() h = self.sceneRect().height() w = self.sceneRect().width() if self.noise_area is not None: self.noise_area.hide() if self.ones_area is None: self.ones_area = QGraphicsRectItem(x, y, w, h / 2 + y_mid) self.ones_area.setBrush(constants.ONES_AREA_COLOR) self.ones_area.setOpacity(constants.SEPARATION_OPACITY) self.ones_area.setPen(QPen(constants.TRANSPARENT_COLOR, 0)) self.addItem(self.ones_area) else: self.ones_area.show() self.ones_area.setRect(x, y, w, h / 2 + y_mid) start = y + h / 2 + y_mid if self.zeros_area is None: self.zeros_area = QGraphicsRectItem(x, start, w, (y + h) - start) self.zeros_area.setBrush(constants.ZEROS_AREA_COLOR) self.zeros_area.setOpacity(constants.SEPARATION_OPACITY) self.zeros_area.setPen(QPen(constants.TRANSPARENT_COLOR, 0)) self.addItem(self.zeros_area) else: self.zeros_area.show() self.zeros_area.setRect(x, start, w, (y + h) - start) self.y_mid = y_mid self.redraw_legend(show_symbols)
def __init__(self, scene): QGraphicsRectItem.__init__(self, QRectF(0, 0, 0, 0)) self.setZValue(-1) self.hide() scene.addItem(self)
def addGraphicsItems(self): self.mainRect = QGraphicsRectItem(QRectF(-15, -15, 30, 30), self) self.nodeTitle = QGraphicsTextItem(type(self).name, self) titleFont = QFont() titleFont.setBold(True) self.nodeTitle.setFont(titleFont) self.selectedChanged(self.isSelected())
def __init__(self, tree, width, height): QGraphicsScene.__init__(self) rect = QGraphicsRectItem(0, 0, width + 100, height) rect.setPen(Qt.white) self.addItem(rect) self.tree = tree self.constructTree()
def mousePressEvent(self, event): if not self._photo.isUnderMouse(): return if self.box_creation_mode: photo_click_point = self.mapToScene(event.pos()).toPoint() self.box_start_point = photo_click_point self._box_graphic = QGraphicsRectItem(0, 0, 1, 1) self._box_graphic.setBrush(QBrush(Qt.transparent)) self._box_graphic.setPen( QPen(Qt.blue, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) self._box_graphic.setPos(photo_click_point) self.scene.addItem(self._box_graphic) elif self.line_selection_mode and self.start_line_select is None: photo_click_point = self.mapToScene(event.pos()).toPoint() self.start_line_select = photo_click_point self.line_graphic = QGraphicsLineItem() self.line_graphic.setPen( QPen(Qt.green, 4, Qt.DotLine, Qt.RoundCap, Qt.RoundJoin)) self.scene.addItem(self.line_graphic) else: # this is pretty hacky and ugly but it works well if not self.any_selection_nodes_under_mouse( ) and not self.ctrl_held: self.deselect_all() super(PhotoViewer, self).mousePressEvent(event)
def display(self): """Updates the widgets, especially based on length of recordings.""" lg.debug('GraphicsScene is between {}s and {}s'.format(self.minimum, self.maximum)) x_scale = 1 / self.parent.value('overview_scale') lg.debug('Set scene x-scaling to {}'.format(x_scale)) self.scale(1 / self.transform().m11(), 1) # reset to 1 self.scale(x_scale, 1) self.scene = QGraphicsScene(self.minimum, 0, self.maximum, TOTAL_HEIGHT) self.setScene(self.scene) # reset annotations self.idx_markers = [] self.idx_annot = [] self.display_current() for name, pos in BARS.items(): item = QGraphicsRectItem(self.minimum, pos['pos0'], self.maximum, pos['pos1']) item.setToolTip(pos['tip']) self.scene.addItem(item) self.add_timestamps()
def add_color_scale(self): x_init = self.position[0] + self.margin + self.width y_init = self.position[1] + self.margin square_size = 20 text_title = QGraphicsSimpleTextItem("clearance") text_title.setPos(x_init, y_init - square_size) self.addToGroup(text_title) for i in range(10): x = x_init y = y_init + 9 * square_size - i * square_size rect = QGraphicsRectItem(x, y, square_size, square_size) pen = QPen() pen.setWidth(0.01) value = (float(i)/9 * (self.vertical_clearance_max - self.vertical_clearance_min)) + self.vertical_clearance_min color = self.color_interpolation.get_interpolation_from_value(value) brush = QBrush(color) rect.setPen(pen) rect.setBrush(brush) self.addToGroup(rect) if i == 0: text_start = QGraphicsSimpleTextItem("%.2f m" % float(self.vertical_clearance_min)) text_start.setPos(x + square_size + 5, y) self.addToGroup(text_start) if i == 9: text_end = QGraphicsSimpleTextItem("%.2f m" % float(self.vertical_clearance_max)) text_end.setPos(x + square_size + 5, y) self.addToGroup(text_end) else: value = self.vertical_clearance_min + (self.vertical_clearance_max-self.vertical_clearance_min) * i/9 text = QGraphicsSimpleTextItem("%.2f m" % value) text.setPos(x + square_size + 5, y) self.addToGroup(text)
def mark_stages(self, start_time, length, stage_name): """Mark stages, only add the new ones. Parameters ---------- start_time : int start time in s of the epoch being scored. length : int duration in s of the epoch being scored. stage_name : str one of the stages defined in global stages. """ y_pos = BARS['stage']['pos0'] # the -1 is really important, otherwise we stay on the edge of the rect old_score = self.scene.itemAt(start_time + length / 2, y_pos + STAGES[stage_name]['pos0'] + STAGES[stage_name]['pos1'] - 1, self.transform()) # check we are not removing the black border if old_score is not None and old_score.pen() == NoPen: lg.debug('Removing old score at {}'.format(start_time)) self.scene.removeItem(old_score) self.idx_annot.remove(old_score) rect = QGraphicsRectItem(start_time, y_pos + STAGES[stage_name]['pos0'], length, STAGES[stage_name]['pos1']) rect.setPen(NoPen) rect.setBrush(STAGES[stage_name]['color']) self.scene.addItem(rect) self.idx_annot.append(rect)
def display(self): """Updates the widgets, especially based on length of recordings.""" lg.debug('GraphicsScene is between {}s and {}s'.format( self.minimum, self.maximum)) x_scale = 1 / self.parent.value('overview_scale') lg.debug('Set scene x-scaling to {}'.format(x_scale)) self.scale(1 / self.transform().m11(), 1) # reset to 1 self.scale(x_scale, 1) self.scene = QGraphicsScene(self.minimum, 0, self.maximum, TOTAL_HEIGHT) self.setScene(self.scene) # reset annotations self.idx_markers = [] self.idx_annot = [] self.display_current() for name, pos in BARS.items(): item = QGraphicsRectItem(self.minimum, pos['pos0'], self.maximum, pos['pos1']) item.setToolTip(pos['tip']) self.scene.addItem(item) self.add_timestamps()
class FuncItem(KineticsDisplayItem): name = constants.ITEM """Class for displaying Functions""" #fontMetrics = None font = QtGui.QFont(KineticsDisplayItem.defaultFontName) font.setPointSize(KineticsDisplayItem.defaultFontSize) fontMetrics = QtGui.QFontMetrics(font) def __init__(self, mobj, parent): super(FuncItem, self).__init__(mobj, parent) self.setFlag(QGraphicsItem.ItemIsMovable, True) iconmap_file = (os.path.join(config.settings[config.KEY_ICON_DIR], 'classIcon/Function.png')) self.funcImage = QtGui.QImage(iconmap_file).scaled(15, 33) self.bg = QGraphicsRectItem(self) self.bg.setAcceptHoverEvents(True) self.gobj = QGraphicsPixmapItem( QtGui.QPixmap.fromImage(self.funcImage), self.bg) self.gobj.setAcceptHoverEvents(True) self.gobj.mobj = self.mobj funcdoc = (moose.element(self.mobj.path)).expr self.gobj.setToolTip(funcdoc) def setDisplayProperties(self, x, y, textcolor, bgcolor): """Set the display properties of this item.""" poolt = ["ZombieBufPool", "BufPool", "ZombiePool", "Pool"] if self.gobj.mobj.parent.className in poolt: self.setGeometry(0, 30, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) else: self.setGeometry(x, y, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) self.bg.setBrush(QtGui.QBrush(bgcolor)) self.setFlag(QGraphicsItem.ItemIsMovable, False) def refresh(self, scale): pass def boundingRect(self): ''' reimplimenting boundingRect for redrawning ''' return QtCore.QRectF(0, 0, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) def updateSlot(self): return None def updateColor(self, bgcolor): return None def updateRect(self, ratio): return None def returnColor(self): return (self.bg.brush().color()) def updateValue(self, gobj, funcdoc='Not Available'): self.gobj.setToolTip(funcdoc)
def update_items(self): self.item = QGraphicsRectItem(0, 0, self.width, self.row_h * self.coeff_h) seq_width = 0 nopen = QPen(Qt.NoPen) self.item.setPen(nopen) font = QFont(self.ftype, self.fsize) if self.fstyle == "italic": font.setStyle(QFont.StyleItalic) elif self.fstyle == "oblique": font.setStyle(QFont.StyleOblique) rect_cls = QGraphicsRectItem for i, val in enumerate(self.liste): width = self.col_w height = self.row_h * len(str(val)) + 1 rectitem = rect_cls(0, 0, width, height, parent=self.item) rectitem.setX(seq_width) # to give correct X to children item rectitem.setBrush(QBrush(QColor(self.bgcolor))) rectitem.setPen(nopen) # write letter if enough space in height if height >= self.fsize: text = QGraphicsSimpleTextItem(str(val), parent=rectitem) text.setFont(font) text.setBrush(QBrush(QColor(self.fgcolor))) # Center text according to rectitem size txtw = text.boundingRect().width() / 3.0 txth = text.boundingRect().height() text.setRotation(self.rot) text.setX(txth * 1.5) #text.setY(0) seq_width += width self.width = seq_width
def __init__(self, *args): super(Demo, self).__init__(*args) loadUi('MainWindow.ui', self) scene = QGraphicsScene() rectItem = QGraphicsRectItem(QRectF(0, 0, 320, 240)) rectItem.setBrush(Qt.red) #rectItem.setPen(Qt.NoPen) rectItem.setFlag(QGraphicsItem.ItemIsMovable) scene.addItem(rectItem) ellipseItem = QGraphicsEllipseItem(QRectF(0, 0, 200, 200)) ellipseItem.setBrush(Qt.blue) #ellipseItem.setPen(Qt.NoPen) ellipseItem.setFlag(QGraphicsItem.ItemIsMovable) scene.addItem(ellipseItem) rectSizeGripItem = SizeGripItem(SimpleResizer(rectItem), rectItem) ellipseSizeGripItem = SizeGripItem(SimpleResizer(ellipseItem), ellipseItem) graphicsView = QGraphicsView(self) graphicsView.setScene(scene) self.setCentralWidget(graphicsView)
def mousePressEvent(self, e): #print('%s.mousePressEvent, at point: ' % self.__class__.__name__, e.pos(), e.scenePos()) QGraphicsRectItem.mousePressEvent( self, e) # points would not show up w/o this line ps = e.scenePos() #print('%s.mousePressEvent itemAt:' % self.__class__.__name__, self.scene().itemAt(ps)) t = self.scene().views()[0].transform() item_sel = self.scene().itemAt(ps.x(), ps.y(), t) #item_sel = self.scene().itemAt(ps) if item_sel in self.lst_ctl_points: #print('set mode EDIT') self.set_mode(EDIT) self.set_child_item_sel(item_sel) self.rect0 = self.rect().normalized() self.p0 = self.pos() self.p0_ptr = self.ptr.pos() self.p0_ptl = self.ptl.pos() self.p0_pbr = self.pbr.pos() self.p0_pbl = self.pbl.pos() if item_sel == self.ped: self.control_point_menu()
def __init__(self, height, length, note_info): QGraphicsRectItem.__init__(self, 0, 0, length, height) self.orig_brush = QColor(note_info[3], 0, 0) self.hover_brush = QColor(note_info[3] + 98, 200, 100) self.select_brush = QColor(note_info[3] + 98, 100, 100) self.note = note_info self.length = length self.piano = self.scene self.pressed = False self.hovering = False self.moving_diff = (0,0) self.expand_diff = 0 self.setAcceptHoverEvents(True) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setPen(QPen(QColor(0,0,0,0))) self.setBrush(self.orig_brush) l = 5 self.front = NoteExpander(l, height, self) self.back = NoteExpander(l, height, self) self.back.setPos(length - l, 0)
def mousePressEvent(self, event): QGraphicsScene.mousePressEvent(self, event) if not (any(key.pressed for key in self.piano_keys) or any(note.pressed for note in self.notes)): for note in self.selected_notes: note.setSelected(False) self.selected_notes = [] if event.button() == Qt.LeftButton: if self.insert_mode: self.place_ghost = True else: self.marquee_select = True self.marquee_rect = QRectF(event.scenePos().x(), event.scenePos().y(), 1, 1) self.marquee = QGraphicsRectItem(self.marquee_rect) self.marquee.setBrush(QColor(255, 255, 255, 100)) self.addItem(self.marquee) else: for s_note in self.notes: if s_note.pressed and s_note in self.selected_notes: break elif s_note.pressed and s_note not in self.selected_notes: for note in self.selected_notes: note.setSelected(False) self.selected_notes = [s_note] break for note in self.selected_notes: if not self.velocity_mode: note.mousePressEvent(event)
def hoverEnterEvent(self, event): QGraphicsRectItem.hoverEnterEvent(self, event) if self.parent.isSelected(): self.parent.setBrush(self.parent.select_brush) else: self.parent.setBrush(self.parent.orig_brush) self.setBrush(self.hover_brush)
def setSelected(self, selected): QGraphicsRectItem.setSelected(self, selected) if self.isSelected(): self.Signaller.signalSelected.emit() if not self.isSelected(): self._hovering = False self.updateColor()
def mouseReleaseEvent(self, e): """ !!! This method does not receive control because module is distracted before... """ #logger.debug('mouseReleaseEvent') QGraphicsRectItem.mouseReleaseEvent(self, e) #QApplication.setOverrideCursor(QCursor(self.hover_cursor)) QApplication.restoreOverrideCursor()
def __init__(self, manager, recordset: list, parent=None): super().__init__(parent=parent) self.UI = Ui_frmRecordsets() self.UI.setupUi(self) # Internal lists self.sensors = {} # List of sensors objects self.sensors_items = {} # List of QAction corresponding to each sensors self.sensors_graphs = {} # List of graph corresponding to each sensor graph self.sensors_location = [] # List of sensors location in this recordset self.sensors_blocks = {} # Sensor blocks - each block of data for each sensor # Variables self.time_pixmap = False # Flag used to check if we need to repaint the timeline or not self.zoom_level = 1 # Current timeview zoom level # Manually created UI objects self.time_bar = QGraphicsLineItem() # Currently selected timestamp bar self.selection_rec = QGraphicsRectItem() # Section rectangle self.sensors_menu = QMenu(self.UI.btnNewGraph) self.UI.btnNewGraph.setMenu(self.sensors_menu) # Data access informations self.dbMan = manager self.recordsets = recordset # Init temporal browser self.timeScene = QGraphicsScene() self.UI.graphTimeline.setScene(self.timeScene) self.UI.graphTimeline.fitInView(self.timeScene.sceneRect()) self.UI.graphTimeline.time_clicked.connect(self.timeview_clicked) self.UI.graphTimeline.time_selected.connect(self.timeview_selected) self.UI.scrollTimeline.valueChanged.connect(self.timeview_scroll) # Init temporal sensor list self.timeSensorsScene = QGraphicsScene() self.UI.graphSensorsTimeline.setScene(self.timeSensorsScene) self.UI.graphSensorsTimeline.fitInView(self.timeSensorsScene.sceneRect(), Qt.KeepAspectRatio) # Update general informations about recordsets self.update_recordset_infos() # Load sensors for that recordset self.load_sensors() # Connect signals to slots self.UI.btnClearSelection.clicked.connect(self.on_timeview_clear_selection_requested) self.UI.btnTimeZoomSelection.clicked.connect(self.on_timeview_zoom_selection_requested) self.UI.btnZoomReset.clicked.connect(self.on_timeview_zoom_reset_requested) self.UI.btnDisplayTimeline.clicked.connect(self.on_timeview_show_hide_requested) self.UI.btnTileHorizontal.clicked.connect(self.tile_graphs_horizontally) self.UI.btnTileVertical.clicked.connect(self.tile_graphs_vertically) self.UI.btnTileAuto.clicked.connect(self.tile_graphs_auto) self.sensors_menu.triggered.connect(self.sensor_graph_selected) # Initial UI state self.UI.btnZoomReset.setEnabled(False) self.UI.btnTimeZoomSelection.setEnabled(False) self.UI.btnClearSelection.setEnabled(False) self.update_tile_buttons_state()
def draw_sep_area(self, y_mid): x = self.sceneRect().x() y = self.sceneRect().y() h = self.sceneRect().height() w = self.sceneRect().width() if self.noise_area is not None: self.noise_area.hide() if self.ones_area is None: self.ones_area = QGraphicsRectItem(x, y, w, h / 2 + y_mid) self.ones_area.setBrush(constants.ONES_AREA_COLOR) self.ones_area.setOpacity(constants.SEPARATION_OPACITY) self.ones_area.setPen(QPen(constants.TRANSPARENT_COLOR, Qt.FlatCap)) self.addItem(self.ones_area) else: self.ones_area.show() self.ones_area.setRect(x, y, w, h / 2 + y_mid) start = y + h / 2 + y_mid if self.zeros_area is None: self.zeros_area = QGraphicsRectItem(x, start, w, (y + h) - start) self.zeros_area.setBrush(constants.ZEROS_AREA_COLOR) self.zeros_area.setOpacity(constants.SEPARATION_OPACITY) self.zeros_area.setPen(QPen(constants.TRANSPARENT_COLOR, Qt.FlatCap)) self.addItem(self.zeros_area) else: self.zeros_area.show() self.zeros_area.setRect(x, start, w, (y + h) - start)
def __init__(self, virtual_helix_item, xover_item, strand3p, idx): """Summary Args: virtual_helix_item (cadnano.views.pathview.virtualhelixitem.VirtualHelixItem): from vhi xover_item (TYPE): Description strand3p (Strand): reference to the 3' strand idx (int): the base index within the virtual helix """ super(ForcedXoverNode3, self).__init__(virtual_helix_item) self._vhi = virtual_helix_item self._xover_item = xover_item self._idx = idx self.is_forward = strand3p.strandSet().isForward() self._is_on_top = self.is_forward self._partner_virtual_helix = virtual_helix_item self._blank_thing = QGraphicsRectItem(_blankRect, self) self._blank_thing.setBrush(QBrush(Qt.white)) self._path_thing = QGraphicsPathItem(self) self.configurePath() self._label = None self.setPen(_NO_PEN) self.setBrush(_NO_BRUSH) self.setRect(_rect) self.setZValue(styles.ZENDPOINTITEM + 1)
def draw_sep_area(self, ymid): x = self.sceneRect().x() y = self.sceneRect().y() h = self.sceneRect().height() w = self.sceneRect().width() # padding = constants.SEPARATION_PADDING padding = 0 if self.noise_area is not None: self.noise_area.hide() if self.ones_area is None: self.ones_area = QGraphicsRectItem(x, y, w, h / 2 - padding + ymid) self.ones_area.setBrush(constants.ONES_AREA_COLOR) self.ones_area.setOpacity(constants.SEPARATION_OPACITY) self.ones_area.setPen(QPen(constants.TRANSPARENT_COLOR, Qt.FlatCap)) self.addItem(self.ones_area) else: self.ones_area.show() self.ones_area.setRect(x, y, w, h / 2 - padding + ymid) start = y + h / 2 + padding + ymid if self.zeros_area is None: self.zeros_area = QGraphicsRectItem(x, start, w, (y + h) - start) self.zeros_area.setBrush(constants.ZEROS_AREA_COLOR) self.zeros_area.setOpacity(constants.SEPARATION_OPACITY) self.zeros_area.setPen( QPen(constants.TRANSPARENT_COLOR, Qt.FlatCap)) self.addItem(self.zeros_area) else: self.zeros_area.show() self.zeros_area.setRect(x, start, w, (y + h) - start)
def hoverLeaveEvent(self, event): self.hovering = False QGraphicsRectItem.hoverLeaveEvent(self, event) if not self.isSelected(): self.setBrush(self.orig_brush) elif self.isSelected(): self.setBrush(self.select_brush)
def mousePressEvent(self, event): QGraphicsRectItem.mousePressEvent(self, event) self.pressed = True self.moving_diff = (0,0) self.expand_diff = 0 self.setCursor(QCursor(Qt.ClosedHandCursor)) self.setSelected(True)
def __init__(self, height, length, note_info): QGraphicsRectItem.__init__(self, 0, 0, length, height) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setAcceptHoverEvents(True) clearpen = QPen(QColor(0,0,0,0)) self.setPen(clearpen) self.orig_brush = QColor(note_info[3], 0, 0) self.hover_brush = QColor(note_info[3] + 100, 200, 100) self.select_brush = QColor(note_info[3] + 100, 100, 100) self.setBrush(self.orig_brush) self.note = note_info self.length = length self.piano = self.scene self.pressed = False self.hovering = False self.moving_diff = (0,0) self.expand_diff = 0 l = 5 self.front = NoteExpander(l, height, self) self.back = NoteExpander(l, height, self) self.back.setPos(length - l, 0)
def openFile(self, svg_file: QFile): if not svg_file.exists(): return if self.backgroundItem: drawBackground = self.backgroundItem.isVisible() else: drawBackground = False s = self.scene() s.clear() self.resetTransform() self.svgItem = QGraphicsSvgItem(svg_file.fileName()) self.svgItem.setFlags(QGraphicsItem.ItemClipsToShape) self.svgItem.setCacheMode(QGraphicsItem.NoCache) self.svgItem.setZValue(0) tmp = self.svgItem.renderer().defaultSize() self.default_width = tmp.width() self.default_height = tmp.height() self.backgroundItem = QGraphicsRectItem(self.svgItem.boundingRect()) self.backgroundItem.setBrush(Qt.white) self.backgroundItem.setPen(QPen(Qt.NoPen)) self.backgroundItem.setVisible(drawBackground) self.backgroundItem.setZValue(-1) s.addItem(self.backgroundItem) s.addItem(self.svgItem)
def __init__(self, parent=None): super(RectZoomMoveView, self).__init__(parent) self.setChart(QChart()) self.chart().setMargins(QMargins(5, 5, 5, 5)) self.chart().setContentsMargins(-10, -10, -10, -10) self.chart().setTitle(" ") self.relationState = True # Define two rectangles for background and drawing respectively self.parentRect = QGraphicsRectItem(self.chart()) self.parentRect.setFlag(QGraphicsItem.ItemClipsChildrenToShape, True) self.parentRect.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.RangeItem = RectRangeItem(parent=self.parentRect) self.RangeItem.setZValue(998) pen = QPen(Qt.gray) pen.setWidth(1) self.parentRect.setPen(pen) self.parentRect.setZValue(997) self.scene().addItem(self.parentRect) self.scene().addItem(self.RangeItem) self.RangeItem.hide() self.m_chartRectF = QRectF() self.m_rubberBandOrigin = QPointF(0, 0) self.dataLength = 0 self.RangeItem.selectedChange.connect(self.changeFromRectItem) self.BtnsWidget = ViewButtonsWidget(self) self.BtnsWidget.refreshBtn.clicked.connect(self.updateView) self.BtnsWidget.RelationSig.connect(self.setRelationState) self.BtnsWidget.dateRangeEdit.dateRangeSig.connect(self.changDateRect)
def simplex_run(self): args = { 'height': self.ui.inputHeight.value(), 'length': self.ui.inputLength.value(), 'calc_a': self.ui.inputCalcA.value(), 'calc_b': self.ui.inputCalcB.value(), 'calc_c': self.ui.inputCalcC.value(), 'gradual': self.ui.inputGradual.checkState() } simplex = sw.SimplexGenerator(args) self.ui.creationBar.setMaximum(args.get('height') * args.get('length')) counter = 0 for p in simplex.createelevation(): counter += 1 item = QGraphicsRectItem(3 * p.get('x'), 3 * p.get('y'), 3, 3) item.setBrush(QColor(*simplex.decidebiome(p.get('elev')))) self.scene.addItem(item) self.ui.creationBar.setValue(counter) if args.get('gradual'): # Update for each 100th pixel to keep performance so-and-so if counter % 100 == 0: QApplication.processEvents()
def show_select_area_at_default_position(self): trimming_data = Project.latest_trimming_data() if trimming_data.position: self.start_position = QPoint(trimming_data.position[0], trimming_data.position[1]) rect = QRectF(trimming_data.position[0], trimming_data.position[1], self.width, self.height) else: self.start_position = QPoint((self.w - self.width) // 2, (self.h - self.height) // 2) rect = QRectF((self.w - self.width) // 2, (self.h - self.height) // 2, self.width, self.height) self.select_area = QGraphicsRectItem(rect) self.select_area.setZValue(1) pen = QPen(QColor('#ffa00e')) pen.setWidth(4) pen.setJoinStyle(Qt.RoundJoin) self.select_area.setPen(pen) self.select_area.setFlag(QGraphicsItem.ItemIsMovable, True) self.original_image_scene.addItem(self.select_area) self.select_area_label_proxy = QGraphicsProxyWidget(self.select_area) self.select_area_label = SelectAreaLabel() self.select_area_label.set_label() self.select_area_label_proxy.setWidget(self.select_area_label) self.select_area_label_proxy.setPos( self.select_area.boundingRect().left() + 2, self.select_area.boundingRect().bottom() - self.select_area_label.height() - 2)
def create_dialog_box(self): self.dialog_box = QGraphicsRectItem(0, 0, self.width() - 20, self.height() / 4) self.dialog_box.setBrush(QColor(0, 0, 0)) self.dialog_box.setX(10) self.dialog_box.setY(self.height() - self.dialog_box.boundingRect().height() - 10) self.dialog_box.setZValue(15); self.dialog_box.setOpacity(0) self.addItem(self.dialog_box)
def mousePressEvent(self, mouseEvent): if mouseEvent.button() == Qt.LeftButton: self.fragmente() elif mouseEvent.button() == Qt.RightButton: QGraphicsRectItem.hoverLeaveEvent(self, None) self.scene().removeItem(self) else: QGraphicsRectItem.mousePressEvent(self, mouseEvent)
def itemMouseMoveEvent(event): QGraphicsRectItem.mouseMoveEvent(item, event) centerPos = item.scenePos() point[0] = centerPos.x() point[1] = centerPos.y() self.update()
def __init__(self, width, height, parent): QGraphicsRectItem.__init__(self, 0, 0, width, height, parent) self.setPen(QPen(QColor(0,0,0,80))) self.width = width self.height = height self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setAcceptHoverEvents(True) self.hover_brush = QColor(200, 0, 0) self.click_brush = QColor(255, 100, 100) self.pressed = False
def mouseReleaseEvent(self, event): QGraphicsRectItem.mouseReleaseEvent(self, event) self.pressed = False if event.button() == Qt.LeftButton: self.moving_diff = (0,0) self.expand_diff = 0 self.back.stretch = False self.front.stretch = False (pos_x, pos_y,) = self.piano().snap(self.pos().x(), self.pos().y()) self.setPos(pos_x, pos_y) self.updateNoteInfo(pos_x, pos_y)
def __init__(self, length, height, parent): QGraphicsRectItem.__init__(self, 0, 0, length, height, parent) self.parent = parent self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setAcceptHoverEvents(True) clearpen = QPen(QColor(0,0,0,0)) self.setPen(clearpen) self.orig_brush = QColor(0, 0, 0, 0) self.hover_brush = QColor(200, 200, 200) self.stretch = False
def _configureOutline(self, outline: QGraphicsRectItem) -> QRectF: """Adjusts `outline` size with default padding. Args: outline: Description Returns: o_rect: `outline` QRectF adjusted by _BOUNDING_RECT_PADDING """ _p = self._BOUNDING_RECT_PADDING o_rect = self.rect().adjusted(-_p, -_p, _p, _p) outline.setRect(o_rect) return o_rect
def __init__(self,x,y,h,w, scene=None,parent=None, editor=None): """" This class implements the resizable rectangle item which is dispalied on the scene x y should be the original positions in scene coordinates h,w are the height and the width of the rectangle """ self._editor = editor QGraphicsRectItem.__init__(self,0,0,w,h,parent=parent) self.Signaller=QGraphicsResizableRectSignaller(parent=parent) scene.addItem(self) #Default Appearence Properties self._fontColor=QColor(255, 255, 255) self._fontSize=10 self._lineWidth=1 ##Note: need to do like this because the x,y of the graphics item fix the position # of the zero relative to the scene self.moveBy(x,y) #Flags self.setFlag(QGraphicsItem.ItemIsMovable,True ) self.setFlag(QGraphicsItem.ItemIsSelectable,True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges ,True) self.setAcceptHoverEvents(True) self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton) self._resizeHandles=[] # A bit of flags self._hovering=False self._normalColor = QColor(0, 0, 255) self.updateColor() self._has_moved=False self._selected=False self._dbg=False self._setupTextItem() self._isFixed = False self.initHandles() self.hideHandles() self.setToolTip("Hold CTRL to drag the box")
def __init__(self, size, scene: QGraphicsScene): self.rectItems = [] self.pixmap = QPixmap(QSize(820,820)) self.painter = QPainter(self.pixmap) self.scene = scene self.owners = None self.values = None pen = QPen() pen.setStyle(Qt.NoPen) for index in range(size**2): item = QGraphicsRectItem() item.setRect(int(index/size), int(index%size), 0.9, 0.9) item.setPen(pen) scene.addItem(item) self.rectItems.append(item)
def __init__(self, virtual_helix_item, xover_item, strand3p, idx): """Summary Args: virtual_helix_item (cadnano.gui.views.pathview.virtualhelixitem.VirtualHelixItem): from vhi xover_item (TYPE): Description strand3p (Strand): reference to the 3' strand idx (int): the base index within the virtual helix """ super(ForcedXoverNode3, self).__init__(virtual_helix_item) self._vhi = virtual_helix_item self._xover_item = xover_item self._idx = idx self.is_forward = strand3p.strandSet().isForward() self._is_on_top = self.is_forward self._partner_virtual_helix = virtual_helix_item self._blank_thing = QGraphicsRectItem(_blankRect, self) self._blank_thing.setBrush(QBrush(Qt.white)) self._path_thing = QGraphicsPathItem(self) self.configurePath() self._label = None self.setPen(_NO_PEN) self.setBrush(_NO_BRUSH) self.setRect(_rect) self.setZValue(styles.ZENDPOINTITEM + 1)
def __init__(self, id, label, parent = 0): QGraphicsRectItem.__init__(self, parent) #1x1 rectangle with top left at origin: self.setRect(0.0, 0.0, 1.0, 1.0) #shut off the outline: self.setPen(QPen(Qt.NoPen)) self.__center_x = 0.0 self.__center_y = 0.0 self.__width = 1.0 self.__height = 1.0 self.__id = id self.__label = label self.__label_scale = 1.0
def __init__(self,): super().__init__() self.squareItem = QGraphicsRectItem() self.squareItem.setBrush(QBrush(QColor(Qt.blue))) self.squareItem.setPen(QPen(QColor(Qt.black), 2)) self.squareItem.setRect(0, 0, 50, 50) self.squareItem.setParentItem(self) self.setAcceptDrops(True)
def display_markers(self): """Mark all the markers, from the dataset. This function should be called only when we load the dataset or when we change the settings. """ for rect in self.idx_markers: self.scene.removeItem(rect) self.idx_markers = [] markers = [] if self.parent.info.markers is not None: if self.parent.value('marker_show'): markers = self.parent.info.markers for mrk in markers: rect = QGraphicsRectItem(mrk['start'], BARS['markers']['pos0'], mrk['end'] - mrk['start'], BARS['markers']['pos1']) self.scene.addItem(rect) color = self.parent.value('marker_color') rect.setPen(QPen(QColor(color))) rect.setBrush(QBrush(QColor(color))) rect.setZValue(-5) self.idx_markers.append(rect)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent): """Handler for user mouse press. Args: event: Contains item, scene, and screen coordinates of the event, and previous event. """ self.clearSelectionsIfActiveTool() return QGraphicsRectItem.mousePressEvent(self, event)
def mouseReleaseEvent(self, event): if self._has_moved: self.Signaller.signalHasMoved.emit(self.pos()) #self._has_moved=False self._has_moved=False QApplication.restoreOverrideCursor() return QGraphicsRectItem.mouseReleaseEvent(self, event)
def __init__(self): self.rect = QRectF() self.style = Style() self.root = QGraphicsItemGroup() if False: self.debug_rect = QGraphicsRectItem(self.root) self.debug_rect.setPen(QPen(QColor(255, 0, 0))) else: self.debug_rect = None
def openFile(self, svg_file): if not svg_file.exists(): return s = self.scene() if self.backgroundItem: drawBackground = self.backgroundItem.isVisible() else: drawBackground = False if self.outlineItem: drawOutline = self.outlineItem.isVisible() else: drawOutline = True s.clear() self.resetTransform() self.svgItem = QGraphicsSvgItem(svg_file.fileName()) self.svgItem.setFlags(QGraphicsItem.ItemClipsToShape) self.svgItem.setCacheMode(QGraphicsItem.NoCache) self.svgItem.setZValue(0) self.backgroundItem = QGraphicsRectItem(self.svgItem.boundingRect()) self.backgroundItem.setBrush(Qt.white) self.backgroundItem.setPen(QPen(Qt.NoPen)) self.backgroundItem.setVisible(drawBackground) self.backgroundItem.setZValue(-1) self.outlineItem = QGraphicsRectItem(self.svgItem.boundingRect()) outline = QPen(Qt.black, 2, Qt.DashLine) outline.setCosmetic(True) self.outlineItem.setPen(outline) self.outlineItem.setBrush(QBrush(Qt.NoBrush)) self.outlineItem.setVisible(drawOutline) self.outlineItem.setZValue(1) s.addItem(self.backgroundItem) s.addItem(self.svgItem) s.addItem(self.outlineItem) s.setSceneRect(self.outlineItem.boundingRect().adjusted(-10, -10, 10, 10))
def create_map_points(self): self.map_points_text_items = [] self.map_points_items = [] for map_point in self.map_data.map_points: color = QColor().fromRgb(map_point.r, map_point.g, map_point.b) rect = QGraphicsRectItem( QRectF( QPointF(map_point.x, map_point.y), QSizeF(5 / self.scale_ratio, 5 / self.scale_ratio) ) ) rect.setPen(QPen(Qt.black, 1 / self.scale_ratio)) rect.setBrush(color) self.map_points_items.append(rect) text = QGraphicsTextItem(map_point.text) text.setDefaultTextColor(color) text.setPos(map_point.x, map_point.y) text.setFont(QFont('Times New Roman', 8 / self.scale_ratio, 2)) self.map_points_text_items.append(text)
def display_current(self): """Create a rectangle showing the current window.""" if self.idx_current in self.scene.items(): self.scene.removeItem(self.idx_current) item = QGraphicsRectItem(0, CURR['pos0'], self.parent.value('window_length'), CURR['pos1']) # it's necessary to create rect first, and then move it item.setPos(self.parent.value('window_start'), 0) item.setPen(QPen(Qt.lightGray)) item.setBrush(QBrush(Qt.lightGray)) item.setZValue(-10) self.scene.addItem(item) self.idx_current = item
def create_material_legend(self, *args): self.position = args[0], args[1] square_size = 20 material_list_key = sorted(self.material_dict) x_init = self.position[0] + self.left_margin y_init = self.position[1] + self.top_margin i = 0 for key in material_list_key: scene_y = y_init + i * (square_size + 5) material = self.material_dict[key] surface_colour = material.get_surface_colour() rect = QGraphicsRectItem(x_init, scene_y, square_size, square_size) pen = QPen() pen.setWidthF(0.5) rect.setPen(pen) BaseGraphic.set_rect_fill(self.visualization_mode, rect, surface_colour) self.graphic_items.append(rect) text = QGraphicsSimpleTextItem(key) text.setPos(x_init + square_size + 5, scene_y) self.graphic_items.append(text) i += 1
def makeGhostNote(self, pos_x, pos_y): """creates the ghostnote that is placed on the scene before the real one is.""" if self.ghost_note: self.removeItem(self.ghost_note) length = self.full_note_width * self.default_length (start, note) = self.snap(pos_x, pos_y) self.ghost_vel = self.default_ghost_vel self.ghost_rect = QRectF(start, note, length, self.note_height) self.ghost_rect_orig_width = self.ghost_rect.width() self.ghost_note = QGraphicsRectItem(self.ghost_rect) self.ghost_note.setBrush(QColor(230, 221, 45, 100)) self.addItem(self.ghost_note)
def __init__(self, is_fwd: bool, pre_xover_item: 'PreXoverItem'): """ Args: is_fwd: Description pre_xover_item: Description """ super(QGraphicsSimpleTextItem, self).__init__(pre_xover_item) self.is_fwd = is_fwd self._tbr = None self._outline = QGraphicsRectItem(self) self.setFont(self._XO_FONT) self.setBrush(getBrushObj('#666666'))