Esempio n. 1
0
    def mouseMoveEvent(self, event):
        #print ">> WorkArea.mouseMoveEvent"
        #if self.pressed :
        currentPos = self.mapToScene(event.pos())
        if self.state == 'pan':
            deltaPos = currentPos - self.startPos
            self.setInteractive(False)
            self.translate(deltaPos.x(), deltaPos.y())
            self.setInteractive(True)

        elif self.state == 'zoom':
            #
            import sys, math
            deltaPos = currentPos - self.startPos
            scale = -1.0
            if 'linux' in sys.platform: scale = 1.0
            scaleFactor = math.pow(2.0,
                                   scale * max(deltaPos.x(), deltaPos.y()) /
                                   200.0)  #
            factor = self.transform().scale(scaleFactor, scaleFactor).mapRect(
                QtCore.QRectF(-1, -1, 2, 2)).width()

            if factor < 0.07 or factor > 100: return
            # update view matrix
            self.setInteractive(False)
            self.scale(scaleFactor, scaleFactor)
            self.translate(-deltaPos.x() * scaleFactor,
                           -deltaPos.y() * scaleFactor)
            self.setInteractive(True)
            #self.startPos = currentPos
        else:
            QtModule.QGraphicsView.mouseMoveEvent(self, event)
Esempio n. 2
0
	def __init__ ( self, link = None, srcConnector = None, dstConnector = None ) :
		#
		QtModule.QGraphicsItem.__init__ ( self )

		from meShaderEd import getDefaultValue
		self.isStraight = getDefaultValue ( app_settings, 'WorkArea', 'straight_links' )

		# qt graphics stuff
		self.brushSelected = QtGui.QBrush ( QtGui.QColor ( 250, 250, 250 ) )
		self.brushNormal = QtGui.QBrush ( QtGui.QColor ( 20, 20, 20 ) )
		self.setFlag ( QtModule.QGraphicsItem.ItemIsSelectable )
		self.setZValue( 0 )

		self.link = link

		self.rect = QtCore.QRectF ()
		self.points = []
		self.path = None
		self.isLinkSelected = False
		self.srcPoint = self.dstPoint = None
		self.srcConnector = self.dstConnector = None

		self.setSrcConnector ( srcConnector )
		self.setDstConnector ( dstConnector)

		if srcConnector != None :
			if srcConnector.isConnectedToInput () and not srcConnector.isConnectedToOutput (): 
				self.swapConnectors ()
Esempio n. 3
0
    def setupGeometry(self):
        #
        wi = 80  # minimal node width
        hi = 0
        x = self.x_offset
        y = self.y_offset

        (wi_label, hi_label) = self.label_widget.getLabelSize()
        self.label_widget.rect = QtCore.QRectF(x, y, wi_label, hi_label)

        (wi_text, hi_text) = self.text_widget.getLabelSize()
        self.text_widget.rect = QtCore.QRectF(x, y + hi_label + self.y_offset,
                                              wi_text, hi_text)

        wi_max = max(wi, wi_label, wi_text) + 2 * self.x_offset
        hi_max = hi_label + hi_text + 3 * self.y_offset

        self.rect = QtCore.QRectF(0, 0, wi_max, hi_max)
Esempio n. 4
0
	def adjust ( self ) :
		#
		from meShaderEd import getDefaultValue
		self.isStraight = getDefaultValue ( app_settings, 'WorkArea', 'straight_links' )

		if self.srcConnector is not None : self.srcPoint = self.srcConnector.getCenterPoint ()
		if self.dstConnector is not None : self.dstPoint = self.dstConnector.getCenterPoint ()

		self.prepareGeometryChange ()

		del self.points [ : ]  # clear bezier points
		self.path = None
		if self.srcPoint is not None and self.dstPoint is not None :
			self.path = QtGui.QPainterPath ()
			# first point
			self.points.append ( self.srcPoint )
			self.path.moveTo ( self.points [ 0 ] )

			# draw curved spline if isStraight is False
			if not self.isStraight :
				# hull spline
				hull = QtCore.QRectF ( self.srcPoint, self.dstPoint )
				centerX = hull.center ().x ()
				centerY = hull.center ().y ()
				# second point
				offsetVX = min ( abs ( hull.topRight ().x () - hull.topLeft ().x () ) * 0.1, 40 )
				offsetVY = 0.0

				p1 = self.srcPoint + QtCore.QPointF ( offsetVX, offsetVY )
				self.points.append ( p1 )
				# third point
				p2 =   QtCore.QPointF ( centerX, self.srcPoint.y() )
				self.points.append ( p2 )
				# fourth point
				p3 = QtCore.QPointF ( centerX, centerY )
				self.points.append ( p3 )
				# fifth point (bezier tangent)
				p4 = QtCore.QPointF ( centerX, centerY )
				self.points.append ( p4 )
				# sixth point
				p5 = QtCore.QPointF ( centerX, self.dstPoint.y() )
				self.points.append ( p5 )
				# seventh point
				p6 = self.dstPoint - QtCore.QPointF ( offsetVX, offsetVY )
				self.points.append ( p6 )
			# last point
			self.points.append ( self.dstPoint )
			if self.isStraight :
				#if DEBUG_MODE : print '* GfxLink: Straight mode'
				self.path.lineTo ( self.dstPoint )
			else:
				#if DEBUG_MODE : print '* GfxLink: Curved mode'
				#self.path.cubicTo ( self.points[1], self.points[2], self.points[3] )
				#self.path.cubicTo ( self.points[5], self.points[6], self.points[7] )
				self.path.cubicTo ( p1, p1, p3 )
				self.path.cubicTo ( p6, p6, self.dstPoint )
			self.rect = self.path.boundingRect ()
Esempio n. 5
0
 def fitGfxNodesInView(self, gfxNodeList):
     #
     nodeNetRect = QtCore.QRectF()
     for gfxNode in gfxNodeList:
         nodeRect = gfxNode.sceneBoundingRect()
         if nodeNetRect.isNull():
             nodeNetRect = nodeRect
         nodeNetRect = nodeNetRect.united(nodeRect)
     if nodeNetRect.isValid():
         self.fitInView(nodeNetRect, QtCore.Qt.KeepAspectRatio)
Esempio n. 6
0
    def setupGeometry(self):
        #
        self.rect = QtCore.QRectF(0, 0, self.swatchSize, self.swatchSize)
        (x, y) = (0, 0)
        hi = self.rect.height() / (len(self.inputConnectors) + 1)

        for connector in self.inputConnectors:
            connector.rect.moveTo(x - connector.radius,
                                  y + hi - connector.radius)
            y += hi
            connector.setParentItem(self)
Esempio n. 7
0
	def setupHeaderGeometry ( self, x, y ) :
		#
		if self.node.type != 'variable' :
			wi_header = self.rect.width ()
			if self.hasSwatch :
				self.header [ 'swatch' ].rect.moveTo ( x, y )
				#self.header['input'].rect.moveTo( x - self.x_offset - self.header['input'].radius,
				#                                  y + self.swatchSize / 2 - self.header['input'].radius )
				#self.header['output'].rect.moveTo( wi_header - self.header['output'].radius,
				#                                  y + self.swatchSize / 2 - self.header['output'].radius )
				x += self.header [ 'swatch' ].rect.width () + self.x_offset

			( wi, hi ) = self.header [ 'label' ].getLabelSize ()
			self.header [ 'label' ].rect = QtCore.QRectF ( x, y, wi, hi )
			y += hi
			( wi, hi ) = self.header [ 'name' ].getLabelSize()
			self.header [ 'name' ].rect = QtCore.QRectF ( x, y, wi, hi )

			# parent controls from header
			for ctrl in self.header.keys() : self.header [ ctrl ].setParentItem ( self )
Esempio n. 8
0
	def setupGeometry ( self ) :
		#
		( wi_header, hi_header ) = self.getHeaderSize ()
		( wi_output, hi_output ) = self.getParamsSize ( self.outputParamLabels )
		( wi_input, hi_input ) = self.getParamsSize ( self.inputParamLabels )

		wi_max = max ( wi_header, wi_output, wi_input ) + 2 * self.x_offset
		hi_max = hi_header + hi_output + hi_input + 3 * self.y_offset

		self.rect = QtCore.QRectF ( 0, 0, wi_max, hi_max )
		self.setupHeaderGeometry ( self.x_offset, self.y_offset )
		self.setupOutputParamsGeometry ( wi_max - self.x_offset, hi_header + 2 * self.y_offset )
		self.setupInputParamsGeometry ( self.x_offset, hi_header + 2 * self.y_offset + hi_output )
Esempio n. 9
0
	def setupInputParamsGeometry ( self, xs, ys ) :
		#
		y = ys
		hi = 0
		for label in self.inputParamLabels :
			( wi, hi ) = label.getLabelSize ()
			label.rect = QtCore.QRectF ( xs, y, wi, hi )
			y += hi
			label.setParentItem ( self )

		y = ys
		x = xs - self.x_offset
		for connector in self.inputConnectors :
			connector.rect.moveTo ( x - connector.radius, y + hi / 2 - connector.radius )
			y += hi
			connector.setParentItem ( self )
Esempio n. 10
0
 def wheelEvent(self, event):
     #print ">> WorkArea.wheelEvent"
     # QtGui.QGraphicsView.wheelEvent( self, event)
     import sys, math
     scale = -1.0
     if 'linux' in sys.platform: scale = 1.0
     if not usePyQt5:
         scaleFactor = math.pow(2.0, scale * event.delta() / 600.0)
     else:
         delta = event.angleDelta()
         #print ( '>> delta rx = %d ry = %d' % ( delta.x (), delta.y () ) )
         scaleFactor = math.pow(2.0, scale * delta.y() / 600.0)
     # self.matrix () is depicated
     factor = self.transform().scale(scaleFactor, scaleFactor).mapRect(
         QtCore.QRectF(-1, -1, 2, 2)).width()
     if factor < 0.07 or factor > 100: return
     self.scale(scaleFactor, scaleFactor)
Esempio n. 11
0
    def __init__(self, node=None, swatchSize=UI.SWATCH_SIZE):
        #
        QtModule.QGraphicsItem.__init__(self)

        self.brush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
        self.PenBorderNormal = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0)),
                                          1.0, QtCore.Qt.SolidLine,
                                          QtCore.Qt.RoundCap,
                                          QtCore.Qt.RoundJoin)

        self.PenBorderSelected = QtGui.QPen(
            QtGui.QBrush(QtGui.QColor(250, 250, 250)), 2.0,
            QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)

        self.node = node
        self.inputConnectors = []

        self.isNodeSelected = False

        self.radius = UI.NODE_RADIUS
        self.swatchSize = UI.SWATCH_SIZE

        self.shadow_offset = UI.SHADOW_OFFSET
        self.shadow_opacity = UI.SHADOW_OPACITY

        shadowColor = QtGui.QColor(0, 0, 0)
        shadowColor.setAlphaF(self.shadow_opacity)
        self.BrushShadow = QtGui.QBrush(shadowColor)
        self.PenShadow = QtGui.QPen(shadowColor)

        self.rect = QtCore.QRectF(0, 0, self.swatchSize, self.swatchSize)
        self.pixmap = None

        if self.node is not None:
            self.updateGfxNode()
            (x, y) = self.node.offset
            self.setPos(x, y)

        # flag (new from QT 4.6...)
        self.setFlag(QtModule.QGraphicsItem.ItemSendsScenePositionChanges)
        self.setFlag(QtModule.QGraphicsItem.ItemSendsGeometryChanges)

        # qt graphics stuff
        self.setFlag(QtModule.QGraphicsItem.ItemIsMovable)
        self.setFlag(QtModule.QGraphicsItem.ItemIsSelectable)
        self.setZValue(1)
Esempio n. 12
0
	def __init__ ( self, param = None, radius = UI.CONNECTOR_RADIUS, isRound = True, node = None ) :
		#
		QtModule.QGraphicsItem.__init__ ( self )
		self.paramsBrushes = {   'c' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkRed ) )
														,'f' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.lightGray ) )
														,'m' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkYellow ) )
														,'p' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkCyan ) )
														,'s' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkGreen ) )
														,'v' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkMagenta ) )
														,'n' : QtGui.QBrush ( QtGui.QColor ( QtCore.Qt.darkBlue ) )
														,'I' : QtGui.QBrush ( QtGui.QColor ( 'white' ) )
														,'G' : QtGui.QBrush ( QtGui.QColor ( 'red' ) )
														,'R' : QtGui.QBrush ( QtGui.QColor ( 'orange' ) )
												 }
		self.brush = QtGui.QBrush ( QtGui.QColor ( 140, 140, 140 ) ) # ( 128, 128, 128 ) ( 132, 132, 132 )
		self.PenBorderNormal = QtGui.QPen ( QtGui.QColor ( 0, 0, 0 ) )
		self.PenBorderSelected = QtGui.QPen ( QtGui.QColor ( 240, 240, 240 ), 2.0 )

		self.isNodeSelected = False
		self.isRound = isRound
		self.radius = radius
		self.rect = QtCore.QRectF ( 0, 0, radius*2, radius*2 )
		self.param = param  # Node parameter
		self.links = []     # gfxLinks list
		self.singleLinkOnly = True
		self.state = 'idle'

		self.node = node  # is not None if this "ConnectorNode"
		if node is not None :
			# flag (new from QT 4.6...)
			#self.setFlag ( QtModule.QGraphicsItem.ItemSendsScenePositionChanges )
			self.setFlag ( QtModule.QGraphicsItem.ItemSendsGeometryChanges )

			# qt graphics stuff
			self.setFlag ( QtModule.QGraphicsItem.ItemIsMovable )
			self.setFlag ( QtModule.QGraphicsItem.ItemIsSelectable )
			self.setZValue ( 1 )
			( x, y ) = self.node.offset
			self.setPos ( x, y )
		#
		# setup connector color
		#
		paramTypeStr = self.getInputParam ().encodedTypeStr ()
		if paramTypeStr in self.paramsBrushes.keys () :
			self.brush = self.paramsBrushes [ paramTypeStr ]
Esempio n. 13
0
    def __init__(self, text, param=None, bgFill=True):
        #
        QtModule.QGraphicsItem.__init__(self)

        self.text = text
        self.param = param
        self.help = None

        self.normalColor = QtGui.QColor(0, 0, 0)
        self.selectedColor = QtGui.QColor(240, 240, 240)
        self.alternateColor = QtGui.QColor(250, 170, 0)
        self.bgColor = QtGui.QColor(140, 140, 140)

        self.PenNormal = QtGui.QPen(self.normalColor)
        self.PenSelected = QtGui.QPen(self.selectedColor)
        self.PenAlternate = QtGui.QPen(self.alternateColor)
        self.bgBrush = QtGui.QBrush(self.bgColor)

        self.pen = self.PenNormal

        self.font = QtGui.QFont()

        self.justify = QtCore.Qt.AlignLeft

        self.bgFill = bgFill
        self.selected = False
        self.alternate = False
        self.bold = False
        self.italic = False

        self.editable = False
        self.processEvents = False
        self.setFlag(QtModule.QGraphicsItem.ItemIsMovable, False)
        self.setFlag(QtModule.QGraphicsItem.ItemIsSelectable, False)

        self.rect = QtCore.QRectF()
Esempio n. 14
0
 def boundingRect(self):
     #
     bound_rect = QtCore.QRectF(self.rect).united(self.shadowRect())
     return bound_rect
Esempio n. 15
0
 def shadowRect(self):
     #
     shadowRect = QtCore.QRectF(self.rect)
     shadowRect.translate(self.shadow_offset, self.shadow_offset)
     return shadowRect
Esempio n. 16
0
	def boundingRect ( self ) :
		#
		bound_rect = QtCore.QRectF ( self.rect ).united( self.shadowRect () )
		bound_rect.adjust( -8, 0, 8, 0 )
		return bound_rect
Esempio n. 17
0
 def boundingRect(self):
     #print ( "GfxNode.boundingRect" )
     bound_rect = QtCore.QRectF(self.rect)
     #bound_rect.adjust( -8, 0, 8, 0 )
     return bound_rect
Esempio n. 18
0
	def shape ( self ) :
		#
		shape = QtGui.QPainterPath ()
		shape_rect = QtCore.QRectF ( self.rect )
		shape.addEllipse ( shape_rect )
		return shape