def get_pen(self): """ constructs and returns the set pen """ pen = QPen() pen.setWidth(self.pen[PenEnum.WIDTH]) pen.setColor(QColor(self.pen[PenEnum.COLOR])) pen.setStyle(self.pen[PenEnum.STYLE]) return pen
def __init__(self, font_loader, logger, opts, width=0, height=0, parent=None, x=0, y=0): QGraphicsRectItem.__init__(self, x, y, width, height, parent) self.font_loader, self.logger, self.opts = font_loader, logger, opts self.current_y, self.max_y, self.max_x = 0, height, width self.is_full = False pen = QPen() pen.setStyle(Qt.NoPen) self.setPen(pen) if not hasattr(self, 'children'): self.children = self.childItems
def __init__(self, font_loader, logger, opts, width=0, height=0, parent=None, x=0, y=0): QGraphicsRectItem.__init__(self, x, y, width, height, parent) self.font_loader, self.logger, self.opts = font_loader, logger, opts self.current_y, self.max_y, self.max_x = 0, height, width self.is_full = False pen = QPen() pen.setStyle(Qt.NoPen) self.setPen(pen) if not hasattr(self, 'children'): self.children = self.childItems
def paint (self,painter,option, widget): painter.setRenderHints(QtGui.QPainter.Antialiasing) pen = QPen(self.color) pen.setWidth(2) pen.setStyle(QtCore.Qt.DashLine) painter.setPen(pen) for action in self.liste_actions.values() : if action.isActive(): if type(action) == ActionMoveToPosition: i = 0 for heros in action.list_left: start_x, start_y = self.scene_coord.LatLonToScene(heros.attribs['latitude'], heros.attribs['longitude']) destination = action.list_right[i] end_x,end_y = self.scene_coord.LatLonToScene(destination.x(), destination.y()) i = (i +1)%len(action.list_right) self.setPos(QPointF(start_x,start_y)) dest = self.view.mapFromScene(QPoint(end_x,end_y)) str = self.view.mapFromScene(QPoint(start_x,start_y)) dest = dest-str painter.drawLine(QPointF(0,0),dest)
def draw(self, event, qp): # self.angle += 0.04 # self._set_current_angle_in_radians(self.angle) #-------------------------------------------------------------------- # Draw X axis #-------------------------------------------------------------------- pen = QPen(QColor(120, 120, 120)) pen.setWidth(2) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) qp.drawLine(0, self.x_axis_y_coordinate, self.width() - self.x_axis_offset_from_right, self.x_axis_y_coordinate) #-------------------------------------------------------------------- # Draw rectangle that will have the vector's shadow #-------------------------------------------------------------------- pen = QPen(QColor(100, 100, 100)) pen.setWidth(2) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) qp.setOpacity(0.2) qp.drawRect( self.width() - self.x_axis_offset_from_right - self.pen_width // 2 - 2, self.x_axis_y_coordinate - self.amplitude - self.pen_width // 2 - 2, self.pen_width + 2, self.amplitude * 2 + self.pen_width + 2) qp.setOpacity(1) #-------------------------------------------------------------------- # Draw vector shadow, if enabled #-------------------------------------------------------------------- if self.draw_shadow: pen = QPen(QColor(220, 20, 20)) pen.setWidth(2) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) qp.setBrush(QColor(220, 20, 20)) qp.setOpacity(1) qp.drawRect( self.width() - self.x_axis_offset_from_right - self.pen_width // 2, self.x_axis_y_coordinate - self.current_height, self.pen_width, self.current_height) qp.setOpacity(1) #-------------------------------------------------------------------- # Draw rotating vector, if enabled #-------------------------------------------------------------------- if self.draw_rotating_vector: vector_origin = Point() vector_origin.x = self.width( ) - self.x_axis_offset_from_right + 20 + self.amplitude vector_origin.y = self.x_axis_y_coordinate vector_width = self.amplitude * math.cos( self.current_angle_in_radians) vector_height = self.amplitude * math.sin( self.current_angle_in_radians) vector_tip = Point() vector_tip.x = vector_origin.x + vector_width vector_tip.y = vector_origin.y - vector_height #---------------------------------------------------- # Draw vector axis and tracing circle pen = QPen(QColor(120, 120, 120)) pen.setWidth(2) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) qp.setBrush(QColor(220, 20, 20)) qp.setOpacity(0.1) qp.drawEllipse(vector_origin.x - self.amplitude, vector_origin.y - self.amplitude, 2 * self.amplitude, 2 * self.amplitude) qp.setOpacity(0.3) # vector's x axis qp.drawLine(vector_origin.x - self.amplitude - 10, vector_origin.y, vector_origin.x + self.amplitude + 10, vector_origin.y) # vector's y axis qp.drawLine(vector_origin.x, vector_origin.y - self.amplitude - 10, vector_origin.x, vector_origin.y + self.amplitude + 10) qp.setOpacity(1) #---------------------------------------------------- # Draw vector itself. pen = QPen(QColor(220, 20, 20)) pen.setWidth(self.pen_width) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) qp.setBrush(QColor(220, 20, 20)) qp.setOpacity(1) qp.drawLine(vector_origin.x, vector_origin.y, vector_tip.x, vector_tip.y) qp.setOpacity(1) #---------------------------------------------------- # Draw vector tip projection pen = QPen(QColor(20, 20, 20)) pen.setWidth(self.pen_width) pen.setStyle(Qt.DotLine) qp.setPen(pen) qp.setOpacity(0.2) qp.drawLine(vector_tip.x, vector_tip.y, self.width() - self.x_axis_offset_from_right, self.x_axis_y_coordinate - vector_height) qp.setOpacity(1) #-------------------------------------------------------------------- # Draw background #-------------------------------------------------------------------- font = QFont() font.setPixelSize(30) pen = QPen(QColor(100, 100, 100)) qp.setPen(pen) qp.setBrush(Qt.green) qp.setFont(font) qp.setOpacity(0.2) for p in self.bkTextPoints + self.timeTextPoints: # qp.rotate(45) qp.drawText(p.x, p.y, p.text) # qp.drawEllipse(p.x, p.y, 50, 30) # qp.rotate(-45) #-------------------------------------------------- # If time isn't paused, shift all background objects left if not self.time_paused: p.x -= self.time_x_increment if p.x <= -150: p.x = 2000 qp.setOpacity(1) #-------------------------------------------------------------------- # Draw points #-------------------------------------------------------------------- # pen = QPen(QColor(120, 60, 60)) pen = QPen(QColor(220, 20, 20)) pen.setWidth(self.pen_width) pen.setCapStyle(Qt.RoundCap) qp.setPen(pen) # qp.setBrush(QBrush(Qt.black)) if not self.time_paused: # Copy height of each point to the point on its left (older point) for i in reversed(range(len(self.ordinates) - 1)): self.ordinates[i + 1] = self.ordinates[i] #print("Using current height of " + str(self.current_height)) self.ordinates[ 0] = -self.current_height # set height of "current" (rightmost) sample for i in range(len(self.ordinates) - 1): qp.drawLine( self.width() - self.x_axis_offset_from_right - i * self.time_x_increment, self.ordinates[i] + self.x_axis_y_coordinate, self.width() - self.x_axis_offset_from_right - (i + 1) * self.time_x_increment, self.ordinates[i + 1] + self.x_axis_y_coordinate)