def dropEvent(self, event): """ Protected method to handle drop events. @param event reference to the drop event (QDropEvent) """ mimeData = event.mimeData() oldID = long(mimeData.data("tabbar-id")) fromIndex = mimeData.data("source-index").toInt()[0] toIndex = self.tabAt(event.pos()) if oldID != id(self): parentID = long(mimeData.data("tabwidget-id")) if event.proposedAction() == Qt.MoveAction: self.emit(SIGNAL("tabRelocateRequested(long, int, int)"), parentID, fromIndex, toIndex) event.acceptProposedAction() elif event.proposedAction() == Qt.CopyAction: self.emit(SIGNAL("tabCopyRequested(long, int, int)"), parentID, fromIndex, toIndex) event.acceptProposedAction() else: if fromIndex != toIndex: if event.proposedAction() == Qt.MoveAction: self.emit(SIGNAL("tabMoveRequested(int, int)"), fromIndex, toIndex) event.acceptProposedAction() elif event.proposedAction() == Qt.CopyAction: self.emit(SIGNAL("tabCopyRequested(int, int)"), fromIndex, toIndex) event.acceptProposedAction() E4WheelTabBar.dropEvent(self, event)
def mousePressEvent(self, event): """ Protected method to handle mouse press events. @param event reference to the mouse press event (QMouseEvent) """ if event.button() == Qt.LeftButton: self.__dragStartPos = QPoint(event.pos()) E4WheelTabBar.mousePressEvent(self, event)
def __init__(self, parent = None): """ Constructor @param parent reference to the parent widget (QWidget) """ E4WheelTabBar.__init__(self, parent) self.setAcceptDrops(True) self.__dragStartPos = QPoint()
def dragEnterEvent(self, event): """ Protected method to handle drag enter events. @param event reference to the drag enter event (QDragEnterEvent) """ mimeData = event.mimeData() formats = mimeData.formats() if formats.contains("action") and \ mimeData.data("action") == "tab-reordering" and \ formats.contains("tabbar-id") and \ formats.contains("source-index") and \ formats.contains("tabwidget-id"): event.acceptProposedAction() E4WheelTabBar.dragEnterEvent(self, event)
def mouseMoveEvent(self, event): """ Protected method to handle mouse move events. @param event reference to the mouse move event (QMouseEvent) """ if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ (event.pos() - self.__dragStartPos).manhattanLength() > \ QApplication.startDragDistance(): drag = QDrag(self) mimeData = QMimeData() index = self.tabAt(event.pos()) mimeData.setText(self.tabText(index)) mimeData.setData("action", "tab-reordering") mimeData.setData("tabbar-id", str(id(self))) mimeData.setData("source-index", QByteArray.number(self.tabAt(self.__dragStartPos))) mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) drag.setMimeData(mimeData) if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): drag.exec_(Qt.DropActions(Qt.CopyAction)) elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): drag.exec_(Qt.DropActions(Qt.MoveAction)) E4WheelTabBar.mouseMoveEvent(self, event)