from PySide import QtCore, QtGui, QtDeclarative

from fixture import Fixture

class FixtureWidget(QtDeclarative.QDeclarativeItem):

    def __init__(self, parent = None):
        super(FixtureWidget, self).__init__(parent)
        self.setFlag(QtGui.QGraphicsItem.ItemHasNoContents, False)
        self.setAcceptedMouseButtons(QtCore.Qt.MouseButton.LeftButton)
        self.setAcceptsHoverEvents(True)
        self.color = QtGui.QColor(100, 100, 100)
        self.setHeight(16)
        self.setWidth(128)
        self.dragging = False
        self.hovering = False
        self.drag_start = None
        self.rect = QtCore.QRect(0, 0, 128, 16)

    def paint(self, painter, options, widget):
        if self.hovering:
            painter.setPen(QtGui.QColor(50, 100, 255, 255))
            painter.setBrush(QtGui.QColor(50, 100, 255, 255))
            hover_rect = QtCore.QRect(2, 4, 124, 8)
            painter.drawRoundRect(hover_rect, 16, 16)
        fixture_bg = QtCore.QRect(4, 6, 120, 4)
        painter.fillRect(fixture_bg, QtGui.QColor(200, 200, 0))

    def hoverEnterEvent(self, event):
        self.hovering = True
        self.update()

    def hoverLeaveEvent(self, event):
        self.hovering = False
        self.update()

    def mouseMoveEvent(self, event):
        if self.dragging:
            self.setPos(event.scenePos() - self.drag_start - self.pos())

    def mousePressEvent(self, event):
        self.dragging = True
        self.drag_start = event.scenePos()

    def mouseReleaseEvent(self, event):
        self.dragging = False
        self.drag_start = None
@@ -588,29 +588,27 @@
   self.drag_
-start
+pos
  = None%0D%0A   
@@ -1072,16 +1072,21 @@
 , 200, 0
+, 200
 ))%0D%0A%0D%0A  
@@ -1353,19 +1353,15 @@
     
-self.setPos
+npos = 
 (eve
@@ -1390,26 +1390,102 @@
 rag_
-start - self.pos()
+pos)%0D%0A            self.moveBy(npos.x(), npos.y())%0D%0A            self.drag_pos = event.scenePos(
 )%0D%0A%0D
@@ -1572,21 +1572,19 @@
 lf.drag_
-start
+pos
  = event
@@ -1692,13 +1692,11 @@
 rag_
-start
+pos
  = N

Fix dragging to work smoothly