def paint( self, painter, option, widget=None ): if self.visible == True: painter.setPen( QColor( self.color ) ) # see try-catch (pardon me) above try: self.sp = CST.toCcsCoord( self.ccs, self.startPoint.x, self.startPoint.y ) self.ep = CST.toCcsCoord( self.ccs, self.endPoint.x, self.endPoint.y ) except: self.sp = CST.toCcsCoord( self.ccs, self.startPoint.x(), self.startPoint.y() ) self.ep = CST.toCcsCoord( self.ccs, self.endPoint.x(), self.endPoint.y() ) self.Rect = QRectF( self.sp, self.ep ) self.line = QLineF( self.sp, self.ep ) if self.line.length() > self.minLength or self.drawAlways == True: painter.drawLine( self.line ) if self.paintToBorder == True: # paint line to approximately the edge of the ccs. ep2 = self.line.pointAt( self.ccs.width / self.line.length() * 2) painter.drawLine(self.ep,ep2) sp2 = self.line.pointAt(-self.ccs.width / self.line.length() * 2) painter.drawLine(self.sp,sp2) if self.showIncline == True: incline = ( self.endPoint.y - self.startPoint.y ) / ( self.endPoint.x - self.startPoint.x ) # print text limited to 2 decimal digits. painter.setBackground ( QBrush ( QColor( 'lightGrey' ) ) ) painter.setBackgroundMode (Qt.BGMode(1)) painter.setPen( QColor( 'black' ) )
def setPosition( self, x = False, y = False ): if x == False and y == False: self.setPos ( CST.toCcsCoord( self.ccs, self.x, self.y ) ) else: self.setPos( CST.toCcsCoord( self.ccs, x, y ) )
def paint( self, painter, option, widget=None ): if self.visible == True: painter.setPen( QColor( self.color ) ) painter.setBrush( QColor( self.fillColor ) ) self.sp = CST.toCcsCoord( self.ccs, self.startPoint.x(), self.startPoint.y() ) self.ep = CST.toCcsCoord( self.ccs, self.endPoint.x(), self.endPoint.y() ) self.Rect = QRectF( self.sp, self.ep ) painter.drawRect( self.Rect )
def __init__(self, ccs, parent, x, y, size, red=0, green=255, blue=0): super(Point, self).__init__(parent) self.Rect = QRectF(-size/2, -size/2, size, size) self.color = QColor(red, green, blue) self.parent = parent # x and y are in cartesian coordinate system. self.x = x self.y = y self.ccs = ccs self.size = size # coordinates go through conversion when item is placed or painted. self.setPos(CST.toCcsCoord(self.ccs, self.x,self.y, self, parent)) self.leftMouseButtonPressed = None # All children of this point. These get updated when point # moves self.children = [] # point is draggable by default. If you need a non-draggable # point, unset by callin set_draggable( False ) self.draggable = True self.visible = True
def setPosition( self ): # x needs to be set because it is eval'ed in # the function string x = self.x self.y = eval( self.function ) self.setPos ( CST.toCcsCoord( self.ccs, self.x, self.y ) )
def calculatePosition( self, e ): # only needs x_move here as y is calculated dependently on x x_move = e.pos().x() - self.xOnWidget p = CST.toCcsCoord( self.ccs, self.x, self.y, self, self.parent ) x = p.x() + x_move p = CST.fromCcsCoord( self.ccs, x, 0, self, self.parent ) self.x = p.x() self.setPosition()
def paint(self, painter, option, widget=None): self.Rect = QRectF( -self.ccs.width/2, -self.ccs.height/2 , self.ccs.width, self.ccs.height) self.setPos(QPointF(self.ccs.xAxis, self.ccs.yAxis)) color = QPen(QColor(0, 100, 0)) # x must be set, because function will most probably contain it. x = self.ccs.xMin try: sp = CST.toCcsCoord( self.ccs, x, eval( self.function ) ) except: # silence errors like "raise negative number to fractional power" pass # ep needs to be set to prevent from # "assigned from before instantiated" below ep = None for xRaw in range ( self.ccs.xMin, self.ccs.xMax+1 ): for tiny in range ( 0 , 10 ): # don't forget to cast into float! x = float(tiny) / 10 + xRaw # try to set ep, which might fail due tu "raise to fractional power asf. try: ep = CST.toCcsCoord( self.ccs, x, eval( self.function ) ) if sp.y() != ep.y(): painter.drawLine( QLineF(sp, ep ) ) except: pass sp = ep
def calculatePosition(self, e): """Calculates its position after a move. Can easily overwritten by subclasses to get different behaviour""" # these calculations are in widget coordinates. x_move = e.pos().x() - self.xOnWidget y_move = e.pos().y() - self.yOnWidget p = CST.toCcsCoord( self.ccs, self.x, self.y, self, self.parent ) x = p.x() + x_move y = p.y() + y_move self.setPos(QPointF(x, y)) # self.x and self.y need to be adjusted, too. p = CST.fromCcsCoord( self.ccs, x,y, self, self.parent ) self.x = p.x() self.y = p.y()