def boundingRect(self): r = self.getRadius() return QtCore.QRectF(-r*1.1, -r*1.1, 2.2*r, 2.2*r)
def boundingRect(self): return QtCore.QRectF(self.box)
def boundingRect(self): ## boundingRect _must_ indicate the entire area that will be drawn on ## or else we will get artifacts and possibly crashing. ## (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect())
def drawpoint(t, y): u = time_projection(t) v = track_projection(y) rect = qc.QRectF(u - 2, v - 2, 4, 4) p.drawRect(rect)
def boundingRect(self): return QtCore.QRectF(0, 0, self.w, self.h)
def __paintSecels(self, painter, cellWidth, cellHeight): indexRange = self.structurePrediction.chain.residueRange() markerRange = range(len(indexRange)) for index, marker in zip(indexRange, markerRange): if len(self.structurePrediction.chain[index].getAtomNames()) == 0: alpha = 100 elif len( self.structurePrediction.chain[index].getAtomNames()) == 1: alpha = 200 else: alpha = 255 xOffset = (marker % self.nCols) * self.cellWidth yOffset = 0.5 * cellHeight + (marker / (self.nCols)) * self.cellHeight secel = self.structurePrediction.getSecelByIndex(index) color = secel.getColor() # Paint Selection Blocks if index in self.localView.structurePrediction.chain.getSelection( ): viewportColor = QtCore.Qt.yellow brush = QtGui.QBrush(viewportColor, QtCore.Qt.SolidPattern) rect = QtCore.QRectF(float(xOffset), float(yOffset) - 0.25 * cellHeight, float(cellWidth), 1.5 * float(cellHeight)) painter.fillRect(rect, brush) # Paint Strand if secel.type == 'strand': color.setAlpha(alpha) brush = QtGui.QBrush(color, QtCore.Qt.SolidPattern) # strand end (triangle) if index == secel.stopIndex: p0 = QtCore.QPointF( float(xOffset + 0.4 * float(cellWidth)), yOffset + 0.15 * float(cellHeight)) p1 = QtCore.QPointF(float(xOffset + cellWidth), yOffset + float(cellHeight) / 2.0) p2 = QtCore.QPointF( float(xOffset + 0.4 * float(cellWidth)), yOffset + 0.85 * float(cellHeight)) path = QtGui.QPainterPath(p0) path.lineTo(p1) path.lineTo(p2) painter.fillPath(path, brush) y0 = int(cellHeight * .32) height = int(cellHeight * .36) rect = QtCore.QRectF(float(xOffset), yOffset + float(y0), 0.4 * float(cellWidth), float(height)) painter.fillRect(rect, brush) # strand main (wide bar) else: y0 = int(cellHeight * .32) height = int(cellHeight * .36) rect = QtCore.QRectF(float(xOffset), yOffset + float(y0), float(cellWidth), float(height)) painter.fillRect(rect, brush) # Paint Helix elif secel.type == 'helix': color.setAlpha(alpha) brush = QtGui.QBrush(color, QtCore.Qt.SolidPattern) y0 = int(cellHeight * .20) height = int(cellHeight * .60) rect = QtCore.QRectF(float(xOffset), yOffset + float(y0), float(cellWidth), float(height)) painter.fillRect(rect, brush) # Paint Coil elif secel.type == 'loop': if index in self.viewportRange: (r, g, b, a) = color.getRgb() color = QtGui.QColor(255 - r, 255 - g, 255 - b) #color.setAlpha(alpha) brush = QtGui.QBrush(color, QtCore.Qt.SolidPattern) y0 = int(cellHeight * .45) height = int(cellHeight * .10) rect = QtCore.QRectF(float(xOffset), yOffset + float(y0), float(cellWidth), float(height)) painter.fillRect(rect, brush) # Paint Viewport if index in self.viewportRange: viewportColor = QtCore.Qt.gray viewportColor = QtGui.QColor(40, 40, 40) viewportColor.setAlpha(100) brush = QtGui.QBrush(viewportColor, QtCore.Qt.SolidPattern) rect = QtCore.QRectF(float(xOffset), float(yOffset) - 0.5 * cellHeight, float(cellWidth), 2.0 * float(cellHeight)) painter.fillRect(rect, brush) xOffset = xOffset + cellWidth
def boundingRect(self): return QtCore.QRectF(-20, 2, 20, -2)
def paint(self, painter, option, index): data = index.data(logmodel.GraphDataRole) if data.isValid(): draw_graph = True if QtCore.PYQT_VERSION_STR.startswith('4.5.'): # toPyObject is buggy in 4.5 def toPy (x): if isinstance(x, QtCore.QVariant): return x.toPyObject() else: return x c_rev, prev_c_rev, labels, is_clicked = ( toPy(item) for item in data.toPyObject()) labels = [[toPy(x) for x in toPy(label)] for label in toPy(labels)] else: c_rev, prev_c_rev, labels, is_clicked = data.toPyObject() else: draw_graph = False option = QtGui.QStyleOptionViewItemV4(option) self.initStyleOption(option, index) widget = self.parent() style = widget.style() text_margin = style.pixelMetric(QtGui.QStyle.PM_FocusFrameHMargin, None, widget) + 1 painter.save() painter.setClipRect(option.rect) style.drawPrimitive(QtGui.QStyle.PE_PanelItemViewItem, option, painter, widget) graphCols = 0 rect = option.rect if draw_graph: painter.save() try: painter.setRenderHint(QtGui.QPainter.Antialiasing) boxsize = float(rect.height()) dotsize = 0.7 pen = QtGui.QPen() penwidth = 1 pen.setWidth(penwidth) pen.setCapStyle(QtCore.Qt.FlatCap) #this is to try get lines 1 pixel wide to actualy be 1 pixel wide. painter.translate(0.5, 0.5) # Draw lines into the cell if prev_c_rev: for start, end, color, direct in prev_c_rev.lines: self.drawLine (painter, pen, rect, boxsize, rect.y(), boxsize, start, end, color, direct) graphCols = max((graphCols, min(start, end))) # Draw lines out of the cell if c_rev: for start, end, color, direct in c_rev.lines: self.drawLine (painter, pen, rect,boxsize, rect.y() + boxsize, boxsize, start, end, color, direct) graphCols = max((graphCols, min(start, end))) # Draw the revision node in the right column if c_rev.col_index is not None: graphCols = max((graphCols, c_rev.col_index)) pen.setColor(self.get_color(c_rev.rev.color, False)) painter.setPen(pen) if not is_clicked: painter.setBrush(QtGui.QBrush( self.get_color(c_rev.rev.color,True))) else: painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) centerx = rect.x() + boxsize * (c_rev.col_index + 0.5) centery = rect.y() + boxsize * 0.5 painter.drawEllipse( QtCore.QRectF(centerx - (boxsize * dotsize * 0.5 ), centery - (boxsize * dotsize * 0.5 ), boxsize * dotsize, boxsize * dotsize)) # Draw twisty if not is_clicked and c_rev.twisty_state is not None: linesize = 0.35 pen.setColor(self._twistyColor) painter.setPen(pen) painter.drawLine(QtCore.QLineF (centerx - boxsize * linesize / 2, centery, centerx + boxsize * linesize / 2, centery)) if not c_rev.twisty_state: painter.drawLine(QtCore.QLineF (centerx, centery - boxsize * linesize / 2, centerx, centery + boxsize * linesize / 2)) finally: painter.restore() rect.adjust( (graphCols + 1.5) * boxsize, 0, 0, 0) painter.save() x = 0 try: tagFont = QtGui.QFont(option.font) tagFont.setPointSizeF(tagFont.pointSizeF() * 9 / 10) for label, bg_color, text_color in labels: tagRect = rect.adjusted(1, 1, -1, -1) tagRect.setWidth(QtGui.QFontMetrics(tagFont).width(label) + 6) tagRect.moveLeft(tagRect.x() + x) painter.setPen(bg_color) painter.fillRect(tagRect.adjusted(1, 1, -1, -1), bg_color) tl = tagRect.topLeft() br = tagRect.bottomRight() painter.drawLine(tl.x(), tl.y() + 1, tl.x(), br.y() - 1) painter.drawLine(br.x(), tl.y() + 1, br.x(), br.y() - 1) painter.drawLine(tl.x() + 1, tl.y(), br.x() - 1, tl.y()) painter.drawLine(tl.x() + 1, br.y(), br.x() - 1, br.y()) painter.setFont(tagFont) painter.setPen(text_color) painter.drawText(tagRect.left() + 3, tagRect.bottom() - option.fontMetrics.descent() + 1, label) x += tagRect.width() + text_margin finally: painter.restore() rect.adjust(x, 0, 0, 0) if not option.text.isEmpty(): painter.setPen(get_text_color(option, style)) text_rect = rect.adjusted(0, 0, -text_margin, 0) painter.setFont(option.font) fm = painter.fontMetrics() text_width = fm.width(option.text) text = option.text if text_width > text_rect.width(): text = self.elidedText(fm, text_rect.width(), QtCore.Qt.ElideRight, text) painter.drawText(text_rect, QtCore.Qt.AlignLeft, text) painter.restore()
def getBoundingBox(self, obj): bbox = QtCore.QRectF(obj.bbox[0], obj.bbox[1], obj.bbox[2], obj.bbox[3]) bboxVis = QtCore.QRectF(obj.bboxVis[0], obj.bboxVis[1], obj.bboxVis[2], obj.bboxVis[3]) return bbox, bboxVis
def update_my_scene(self): sc = self.scene() rs = sc.sceneRect() #print 'XXX: Scene rect', rs #print 80*'_' #for item in sc.items() : # print 'scene item:', item # set dark rects #if self.raxi is not None : self.scene().removeItem(self.raxi) if self.rslefv is not None: self.scene().removeItem(self.rslefv) if self.rsbotv is not None: self.scene().removeItem(self.rsbotv) if self.rslefi is not None: self.scene().removeItem(self.rslefi) if self.rsboti is not None: self.scene().removeItem(self.rsboti) if self.raxesi is not None: self.scene().removeItem(self.raxesi) x, y, w, h = rs.x(), rs.y(), rs.width(), rs.height() rslef = QtCore.QRectF(x, y, w * self.margl, h) self.rslefv = self.add_rect_to_scene_v1(rslef, self.brubx, self.penbx) self.rslefi = self.add_rect_to_scene(rslef, self.brudf, self.pendf) self.rslefi.setCursorHover(Qt.SizeVerCursor) self.rslefi.setCursorGrab(Qt.SplitVCursor) rsbot = QtCore.QRectF(x + w * self.margl, y, w - w * self.margl, h * self.margb) if self.origin_up: rsbot.moveBottomRight(rs.bottomRight()) self.rsbotv = self.add_rect_to_scene_v1(rsbot, self.brubx, self.penbx) self.rsboti = self.add_rect_to_scene(rsbot, self.brudf, self.pendf) self.rectax = QtCore.QRectF(rslef.topRight(), rsbot.topRight()) if self._do_left: self.rulerl = GURuler(sc, GURuler.VL, rect=self.rectax, color=self.colax, pen=self.penax, font=self.fonax) if self._do_bottom: self.rulerd = GURuler(sc, GURuler.HD, rect=self.rectax, color=self.colax, pen=self.penax, font=self.fonax) else: rsbot.moveTopRight(rs.topRight()) self.rsbotv = self.add_rect_to_scene_v1(rsbot, self.brubx, self.penbx) self.rsboti = self.add_rect_to_scene(rsbot, self.brudf, self.pendf) self.rectax = QtCore.QRectF(rslef.bottomRight(), rsbot.bottomRight()).normalized() if self._do_left: self.rulerl = GURuler(sc, GURuler.VL, rect=self.rectax, color=self.colax, pen=self.penax, font=self.fonax, txtoff_vfr=0.055) if self._do_bottom: self.rulerd = GURuler(sc, GURuler.HU, rect=self.rectax, color=self.colax, pen=self.penax, font=self.fonax, txtoff_vfr=0.09) self.raxesi = self.add_rect_to_scene(self.rectax, self.brudf, self.pendf) self.raxesi.setCursorHover(Qt.CrossCursor) self.raxesi.setCursorGrab(Qt.SizeAllCursor) self.rsboti.setCursorHover(Qt.SizeHorCursor) self.rsboti.setCursorGrab(Qt.SplitHCursor) self.rslefv.setZValue(1) self.rsbotv.setZValue(1) self.raxesi.setZValue(20) self.rslefi.setZValue(20) self.rsboti.setZValue(20)
def paintEvent(self, event=None): ''' overrides the paint event so that we can draw our grid ''' painter = QtGui.QPainter(self) painter.save() painter.setRenderHint(QtGui.QPainter.Antialiasing, True) midline = self.width() / 100 #-- cell width xOffset = (self.width() - midline) / 16 #-- cell height yOffset = self.height() / 2 #--red pen if self.isEnabled(): painter.setPen(QtGui.QPen(QtCore.Qt.red, 2)) else: painter.setPen(QtGui.QPen(QtCore.Qt.gray, 2)) sansFont = QtGui.QFont("Helvetica", 8) painter.setFont(sansFont) fm = QtGui.QFontMetrics(sansFont) leftpad = fm.width("Right ") rightpad = fm.width(" Left") #--big horizontal dissection of entire widget painter.drawLine(leftpad, self.height() / 2, self.width() - rightpad, self.height() / 2) #--vertical dissection of entire widget painter.drawLine(self.width() / 2, 0, self.width() / 2, self.height()) for x in range(16): if x > 7: midx = midline else: midx = 0 for y in range(2): tooth_notation = self.grid[y][x] rect = QtCore.QRectF(x * xOffset + midx, y * yOffset, xOffset, yOffset).adjusted(0.5, 0.5, -0.5, -0.5) #-- draw a tooth (subroutine) self.tooth(painter, rect, tooth_notation) if [x, y] == self.highlighted: painter.setPen(QtGui.QPen(QtCore.Qt.cyan, 1)) painter.setBrush(colours.TRANSPARENT) painter.drawRect(rect.adjusted(1, 1, -1, -1)) if self.showSelected: #-- these conditions mean that the tooth needs to be #--highlighted draw a rectangle around the selected tooth, #--but don't overwrite the centre if [x, y] == self.selected: painter.setPen(QtGui.QPen(QtCore.Qt.darkBlue, 2)) painter.setBrush(colours.TRANSPARENT) painter.drawRect(rect.adjusted(1, 1, -1, -1)) elif [x, y] in self.multiSelection: painter.setPen(QtGui.QPen(QtCore.Qt.blue, 2)) painter.setBrush(colours.TRANSPARENT) painter.drawRect(rect.adjusted(1, 1, -1, -1)) if self.isEnabled(): painter.setPen(QtGui.QPen(QtCore.Qt.black, 1)) else: painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1)) textRect = QtCore.QRectF(0, 0, self.width(), self.height()) if self.showLeftRight: #--show left/right (this is done here to avoid being overwritten #--during the rest of the paint job painter.drawText(textRect, QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter, (_("Left"))) painter.drawText(textRect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, (_("Right"))) #--free the painter's saved state painter.restore()
def boundingRect(self): return QtCore.QRectF(0, 0, 48, 48)
def definePath(self): rect = QtCore.QRectF(self.x - 5.0, self.y - 5.0, 10.0, 10.0) path = QtGui.QPainterPath() path.addRect(rect) return path
def boundingRect(self): return QtCore.QRectF(0, 0, self.state['size'][0], self.state['size'][1])
def boundingRect(self): """ Get the bounding rectangle of the item. """ rect = self.image.rect() return QtCore.QRectF(rect.left() - rect.width()/2, rect.top() - rect.height()/2, rect.right(), rect.bottom())
def boundingRect(self): return QtCore.QRectF(-15, -50, 30, 50)
def setTable(self, table): self.tableitem.setPixmap(table) if self.smallerD == 0: self.setSceneRect(QtCore.QRectF(0, 0, 500, 500)) else: self.setSceneRect(QtCore.QRectF(table.rect()))
def boundingRect(self): return QtCore.QRectF(-30, -20, 60, 60)
def __init__(self, body_type=BODY_TYPE_STATIC, mass=1, a_point_or_tuple=[], b_point=None, radius=0, friction=0, elasticity=0, density=0, center_of_grav=None, color=None, scene=None, resource_ref_name=None, prefix=None): if not b_point: x1, y1, x2, y2 = a_point_or_tuple[0][0], a_point_or_tuple[0][ 1], a_point_or_tuple[1][0], a_point_or_tuple[1][1] else: x1, y1, x2, y2 = a_point_or_tuple[0], a_point_or_tuple[1], b_point[ 0], b_point[1] self.line_angle_adjustment = math.atan2((y2 - y1), (x2 - x1)) distance_between = int(((x2 - x1)**2 + (y2 - y1)**2)**.5) if radius <= 1: radius = 1 rect = QtCore.QRectF(0, 0, distance_between + radius, radius) else: #rect=QtCore.QRectF(x1,y1-radius,x1+distance_between,y1+radius) rect = QtCore.QRectF(0, -radius, distance_between, 2 * radius) QtGui.QGraphicsRectItem.__init__(self, rect, scene=scene) #self.rotate(line_angle) bp.blueprint.__init__(self, prefix or 'ch_obj_seg') self.__eventManager = bp.eventManager() self.eventManager = self.getEventManager inertia = pm.moment_for_segment(mass, (x1, y1), (x2, y2), radius) self.chipBody = ChipBody(mass, inertia, body_type) self.bod_segs = [x1, y1] pm.Segment.__init__(self, self.chipBody, (x1, y1), (x2, y2), radius=radius) self.cog = None if type(center_of_grav) == tuple: self.cog = pm.Vec2d(center_of_grav) else: self.cog = pm.Vec2d(self.center_of_gravity) self.cx, self.cy = self.cog if density: self.density = density if friction: self.friction = friction if elasticity: self.elasticity = elasticity if color: self.setBrushColor(color=color) self.setPenColor(color=color) self.hide() self.set_ref_name(resource_ref_name) self.add_self_to_catalog() self.__update_object = True self.updateChipObject()
def boundingRect(self): return QtCore.QRectF(-5, -5, 40, 10)
def set_rect(self, rect): ''' update the rectangle of the root ''' self.rect = rect self.rect_f = QtCore.QRectF(self.rect)
def boundingRect(self): return QtCore.QRectF(-15.5, -15.5, 34, 34)
def printgraph(self, printer): p = QtGui.QPainter(printer) self.view.scene().render(p,QtCore.QRectF(0, 0,printer.width(), printer.height() / 2)) # self.view.scene().render(p) p.end()
def boundingRect(self): return QtCore.QRectF(0, 0, 300, 320)
def update(self, rect=QtCore.QRectF()): '''''' # QtGui.QGraphicsItem.update(self, rect) QtGui.QGraphicsObject.update(self, rect)
def mouseMoveEvent(self, event): newPosition = event.scenePos() self.setPosUsingSheepDog( self.pos() + newPosition - self.mouseMoveLastPosition, QtCore.QRectF(-260, -280, 1350, 1160)) self.mouseMoveLastPosition = newPosition
def recalculate(self, allFrames=False): if len(self.frames) < 1: return #print "recalc", allFrames #print self.state ## calculate image if allFrames: ## Clear out old displays #self.img = None for (i, p, s) in self.items: s = i.scene() if s is not None: s.removeItem(i) self.items = [] ## Compute for all frames frames = self.frames else: frames = self.frames[-1:] #if self.state['displayImageCheck'] and frames[0]['cam'] is not None: #if self.img is None: #self.img = zeros(frames[0]['cam'].shape + (4,), dtype=float32) for f in frames: (r, g, b) = self.evaluateTrace(f['clamp']) #if self.state['displayImageCheck'] and f['cam'] is not None and self.img is not None and f['cam'].shape == self.img.shape: #alpha = gaussian_filter((f['cam'] - f['cam'].min()), (5, 5)) #tol = self.state['spotToleranceSpin'] #alpha = clip(alpha-tol, 0, 2**32) #alpha *= 256. / alpha.max() #newImg = empty(frames[0]['cam'].shape + (4,), dtype=uint16) #newImg[..., 0] = b * alpha #newImg[..., 1] = g * alpha #newImg[..., 2] = r * alpha #newImg[..., 3] = alpha #self.img = clip(self.img + (newImg.astype(uint16)), 0, 255) #else: alpha = self.state['alphaSlider'] spot = QtGui.QGraphicsEllipseItem(QtCore.QRectF(-0.5, -0.5, 1, 1)) spot.setBrush( QtGui.QBrush(QtGui.QColor(r * 255, g * 255, b * 255, alpha))) spot.setPen(QtGui.QPen(QtCore.Qt.NoPen)) p = f['scanner']['position'] s = f['scanner']['spotSize'] self.items.append([spot, p, [s, s]]) self.hide() ## Make sure only correct items are displayed self.show() #if self.state['displayImageCheck']: #self.updateImage() ## update location of image #info = frames[-1]['camInfo'][-1] #s = info['pixelSize'] #p = info['imagePosition'] #self.items[0][1] = p #self.items[0][2] = s ## Set correct scene #cModName = str(self.ui().ui.cameraModCombo.currentText()) #camMod = self.ui().man.getModule(cModName) camMod = self.ui().ui.cameraModCombo.getSelectedObj() scene = camMod.ui.view.scene() for i in self.items: (item, p, s) = i if item.scene() is not scene: camMod.ui.addItem(item, p, s, self.z)
def boundingRect(self): return QtCore.QRectF(self.picture.boundingRect())
def boundingRect(self): return QtCore.QRectF(0, 0, 25, 10)
def boundingRect(self): r = QtCore.QRectF() for h in self.handles: r |= self.mapFromItem(h['item'], h['item'].boundingRect()).boundingRect() ## |= gives the union of the two QRectFs return r