Exemple #1
0
    def restoreGeometry(self, geometry):
        """
        Restores the geometry of this subwindow

        :param geometry: the saved state as a QByteArray instance
        :return:
        """
        if geometry.size() < 4:
            return False
        stream = QDataStream(geometry)
        if stream.readUInt32() != 0x1D9D0CB:
            return False
        if stream.readUInt16() != 1:
            return False
        stream.readUInt16()  # minorVersion is ignored.
        x = stream.readInt64()
        y = stream.readInt64()
        width = stream.readInt64()
        height = stream.readInt64()
        restoredFrameGeometry = QRect(x, y, width, height)
        x = stream.readInt64()
        y = stream.readInt64()
        width = stream.readInt64()
        height = stream.readInt64()
        restoredNormalGeometry = QRect(x, y, width, height)
        maximized = stream.readUInt32()
        fullScreen = stream.readUInt32()
        frameHeight = 20
        if not restoredFrameGeometry.isValid():
            restoredFrameGeometry = QRect(QPoint(0, 0), self.sizeHint())
        if not restoredNormalGeometry.isValid():
            restoredNormalGeometry = QRect(QPoint(0, frameHeight),
                                           self.sizeHint())
        restoredFrameGeometry.moveTop(max(restoredFrameGeometry.top(), 0))
        restoredNormalGeometry.moveTop(
            max(restoredNormalGeometry.top(), 0 + frameHeight))
        if maximized or fullScreen:
            self.setGeometry(restoredNormalGeometry)
            ws = self.windowState()
            if maximized:
                ws |= Qt.WindowMaximized
            if fullScreen:
                ws |= Qt.WindowFullScreen
            self.setWindowState(ws)
        else:
            offset = QPoint()
            self.setWindowState(self.windowState()
                                & ~(Qt.WindowMaximized | Qt.WindowFullScreen))
            self.move(restoredFrameGeometry.topLeft() + offset)
            self.resize(restoredNormalGeometry.size())
        return True
Exemple #2
0
    def dropMimeData(self, data, action, row, column, parentIndex):
        """ Handles the data supplied by a drag and drop operation that ended with the given action. """
        if action == Qt.IgnoreAction:
            return True
        if not data.hasFormat("application/vnd.text.list"):
            return False

        encodedData = data.data("application/vnd.text.list")
        stream = QDataStream(encodedData, QIODevice.ReadOnly)

        parent = self.nodeFromIndex(parentIndex)
        destRow = row if row != -1 else parent.childCount()
        numPlacedBeforeDestination = 0

        # MAYA-66630: We want all of this to be one undo transaction
        while not stream.atEnd():

            typeId = stream.readInt32()
            uuid = stream.readInt64()
            oldRow = stream.readInt32()

            child = None
            if typeId == TYPE_ID_LIGHT_ITEM:
                child = self.lights[uuid]
            elif typeId == TYPE_ID_GROUP_ITEM:
                child = self.groups[uuid]
            else:
                print("Error: Unstream of unknown node type " + str(typeId))
                continue

            oldParent = child.parent()
            oldParent.removeChild(child)

            # We are inserting into range [row, row+numRows]. But we also remove. If we remove an item from our parent before this range,
            # we must reduce indices that we insert at after that
            if oldParent == parent and oldRow < row:
                numPlacedBeforeDestination += 1

            parent.insertChild(child, destRow - numPlacedBeforeDestination)

            destRow += 1

        return True