86 QApplication.startDragDistance(): |
86 QApplication.startDragDistance(): |
87 drag = QDrag(self) |
87 drag = QDrag(self) |
88 mimeData = QMimeData() |
88 mimeData = QMimeData() |
89 index = self.tabAt(event.pos()) |
89 index = self.tabAt(event.pos()) |
90 mimeData.setText(self.tabText(index)) |
90 mimeData.setText(self.tabText(index)) |
91 mimeData.setData("action", "tab-reordering") |
91 mimeData.setData("action", b"tab-reordering") |
92 mimeData.setData("tabbar-id", str(id(self))) |
92 mimeData.setData("tabbar-id", str(id(self)).encode("utf-8")) |
93 mimeData.setData( |
93 mimeData.setData( |
94 "source-index", |
94 "source-index", |
95 QByteArray.number(self.tabAt(self.__dragStartPos))) |
95 QByteArray.number(self.tabAt(self.__dragStartPos))) |
96 mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) |
96 mimeData.setData( |
|
97 "tabwidget-id", |
|
98 str(id(self.parentWidget())).encode("utf-8")) |
97 drag.setMimeData(mimeData) |
99 drag.setMimeData(mimeData) |
98 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
100 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
99 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
101 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
100 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
102 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
101 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
103 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
108 @param event reference to the drag enter event (QDragEnterEvent) |
110 @param event reference to the drag enter event (QDragEnterEvent) |
109 """ |
111 """ |
110 mimeData = event.mimeData() |
112 mimeData = event.mimeData() |
111 formats = mimeData.formats() |
113 formats = mimeData.formats() |
112 if "action" in formats and \ |
114 if "action" in formats and \ |
113 mimeData.data("action") == "tab-reordering" and \ |
115 mimeData.data("action") == b"tab-reordering" and \ |
114 "tabbar-id" in formats and \ |
116 "tabbar-id" in formats and \ |
115 "source-index" in formats and \ |
117 "source-index" in formats and \ |
116 "tabwidget-id" in formats: |
118 "tabwidget-id" in formats: |
117 event.acceptProposedAction() |
119 event.acceptProposedAction() |
118 super(TabBar, self).dragEnterEvent(event) |
120 super(TabBar, self).dragEnterEvent(event) |
123 |
125 |
124 @param event reference to the drop event (QDropEvent) |
126 @param event reference to the drop event (QDropEvent) |
125 """ |
127 """ |
126 mimeData = event.mimeData() |
128 mimeData = event.mimeData() |
127 oldID = int(mimeData.data("tabbar-id")) |
129 oldID = int(mimeData.data("tabbar-id")) |
128 fromIndex = mimeData.data("source-index").toInt()[0] |
130 fromIndex = int(mimeData.data("source-index")) |
129 toIndex = self.tabAt(event.pos()) |
131 toIndex = self.tabAt(event.pos()) |
130 if oldID != id(self): |
132 if oldID != id(self): |
131 parentID = int(mimeData.data("tabwidget-id")) |
133 parentID = int(mimeData.data("tabwidget-id")) |
132 if event.proposedAction() == Qt.MoveAction: |
134 if event.proposedAction() == Qt.MoveAction: |
133 self.tabRelocateRequested.emit( |
135 self.tabRelocateRequested.emit( |