Esempio n. 1
0
    def mouseMoveEvent(self, e):
        if self.leftMouseButtonPressed:
            x_move = e.pos().x() - self.xOnWidget
            y_move = e.pos().y() - self.yOnWidget
            
            self.xAxis = self.x() + x_move
            self.yAxis = self.y() + y_move
           
            self.setPos( QPointF( self.xAxis, self.yAxis ) )
            
            # xMin is left border (scene-coord = 0) an yMax is top border (scene-coord = 0)
            min = self.mapToScene( CST.toCcsCoord( self, self.xMin, self.yMax ) )
            max = self.mapToScene( CST.toCcsCoord( self, self.xMax, self.yMin ) )
            if min.x() < 0:
                self.xMin += 1
                self.xMax += 1

            if max.x() > self.width:
                self.xMin -= 1
                self.xMax -= 1
                
            if min.y() < 0:
                self.yMin -= 1
                self.yMax -= 1
                #~ print "bumm"
            
            if max.y() > self.height:
                self.yMin += 1
                self.yMax += 1
                
            # reset Rect to allow for infinite moves
            self.Rect = QRectF( 
                    self.xMin - self.xAxis - 100, 
                    self.yMin - self.yAxis - 100, 
                    self.width             + 200, 
                    self.height            + 200
            )
Esempio n. 2
0
    def paint(self, painter, option, widget=None):
        ordinateColor = QPen( QColor(255, 0, 0 ) )
        normalLineCol = QPen( QColor(0, 0, 255 ) )
        
        for i in range ( self.xMin-1 , self.xMax+2 ):
            if i == 0:
                painter.setPen( ordinateColor )
            else:
                painter.setPen( normalLineCol )
            
            #~ if i == 0:
            painter.drawLine(
                CST.toCcsCoord( self, i,self.yMin-1 ), 
                CST.toCcsCoord( self, i,self.yMax+1 )
            )
            
            tickCoord = CST.toCcsCoord(self, i, 0)
            tickCoord += CST.toCcsCoord(self, self.tickXOffset, self.tickYOffset)
            painter.drawText(
                tickCoord,
                QString.number(i)
            )

        for i in range (self.yMin-1, self.yMax+2):
        #~ for i in self.yRange :
            #~ print i
            
            if i == 0:
                painter.setPen(ordinateColor)
            else:
                painter.setPen(normalLineCol)
            
            #~ if i == 0:
            painter.drawLine(
                CST.toCcsCoord( self, self.xMin-1,i ), 
                CST.toCcsCoord( self, self.xMax+1,i )
            )
            
            tickCoord = CST.toCcsCoord(self, 0,i)
            tickCoord += CST.toCcsCoord(self, self.tickXOffset, self.tickYOffset)
            painter.drawText(
                tickCoord,
                QString.number(i)
            )