32 """ |
32 """ |
33 Class implementing a customized tab bar supporting drag & drop. |
33 Class implementing a customized tab bar supporting drag & drop. |
34 |
34 |
35 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving |
35 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving |
36 the old and new index position |
36 the old and new index position |
37 @signal tabRelocateRequested(long, int, int) emitted to signal a tab relocation |
37 @signal tabRelocateRequested(str, int, int) emitted to signal a tab relocation |
38 request giving the id of the old tab widget, the index in the old tab widget |
38 request giving the string encoded id of the old tab widget, the index in |
39 and the new index position |
39 the old tab widget and the new index position |
40 @signal tabCopyRequested(long, int, int) emitted to signal a clone request |
40 @signal tabCopyRequested(str, int, int) emitted to signal a clone request |
41 giving the id of the source tab widget, the index in the source tab widget |
41 giving the string encoded id of the source tab widget, the index in the |
42 and the new index position |
42 source tab widget and the new index position |
43 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
43 @signal tabCopyRequested(int, int) emitted to signal a clone request giving |
44 the old and new index position |
44 the old and new index position |
45 """ |
45 """ |
46 tabMoveRequested = pyqtSignal(int, int) |
46 tabMoveRequested = pyqtSignal(int, int) |
47 tabRelocateRequested = pyqtSignal(int, int, int) |
47 tabRelocateRequested = pyqtSignal(int, int, int) |
48 tabCopyRequested = pyqtSignal(int, int, int) |
48 tabCopyRequested = pyqtSignal((str, int, int), (int, int)) |
49 tabCopyRequested = pyqtSignal(int, int) |
|
50 |
49 |
51 def __init__(self, parent = None): |
50 def __init__(self, parent = None): |
52 """ |
51 """ |
53 Constructor |
52 Constructor |
54 |
53 |
81 drag = QDrag(self) |
80 drag = QDrag(self) |
82 mimeData = QMimeData() |
81 mimeData = QMimeData() |
83 index = self.tabAt(event.pos()) |
82 index = self.tabAt(event.pos()) |
84 mimeData.setText(self.tabText(index)) |
83 mimeData.setText(self.tabText(index)) |
85 mimeData.setData("action", "tab-reordering") |
84 mimeData.setData("action", "tab-reordering") |
86 mimeData.setData("tabbar-id", QByteArray.number(id(self))) |
85 mimeData.setData("tabbar-id", str(id(self))) |
87 mimeData.setData("source-index", |
86 mimeData.setData("source-index", |
88 QByteArray.number(self.tabAt(self.__dragStartPos))) |
87 QByteArray.number(self.tabAt(self.__dragStartPos))) |
89 mimeData.setData("tabwidget-id", QByteArray.number(id(self.parentWidget()))) |
88 mimeData.setData("tabwidget-id", str(id(self.parentWidget()))) |
90 drag.setMimeData(mimeData) |
89 drag.setMimeData(mimeData) |
91 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
90 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
92 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
91 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
93 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
92 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
94 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
93 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
115 Protected method to handle drop events. |
114 Protected method to handle drop events. |
116 |
115 |
117 @param event reference to the drop event (QDropEvent) |
116 @param event reference to the drop event (QDropEvent) |
118 """ |
117 """ |
119 mimeData = event.mimeData() |
118 mimeData = event.mimeData() |
120 oldID = mimeData.data("tabbar-id").toLong()[0] |
119 oldID = int(mimeData.data("tabbar-id")) |
121 fromIndex = mimeData.data("source-index").toInt()[0] |
120 fromIndex = mimeData.data("source-index").toInt()[0] |
122 toIndex = self.tabAt(event.pos()) |
121 toIndex = self.tabAt(event.pos()) |
123 if oldID != id(self): |
122 if oldID != id(self): |
124 parentID = mimeData.data("tabwidget-id").toLong()[0] |
123 parentID = int(mimeData.data("tabwidget-id")) |
125 if event.proposedAction() == Qt.MoveAction: |
124 if event.proposedAction() == Qt.MoveAction: |
126 self.tabRelocateRequested.emit(parentID, fromIndex, toIndex) |
125 self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex) |
127 event.acceptProposedAction() |
126 event.acceptProposedAction() |
128 elif event.proposedAction() == Qt.CopyAction: |
127 elif event.proposedAction() == Qt.CopyAction: |
129 self.tabCopyRequested.emit(parentID, fromIndex, toIndex) |
128 self.tabCopyRequested[str, int, int].emit( |
|
129 str(parentID), fromIndex, toIndex) |
130 event.acceptProposedAction() |
130 event.acceptProposedAction() |
131 else: |
131 else: |
132 if fromIndex != toIndex: |
132 if fromIndex != toIndex: |
133 if event.proposedAction() == Qt.MoveAction: |
133 if event.proposedAction() == Qt.MoveAction: |
134 self.tabMoveRequested.emit(fromIndex, toIndex) |
134 self.tabMoveRequested.emit(fromIndex, toIndex) |
135 event.acceptProposedAction() |
135 event.acceptProposedAction() |
136 elif event.proposedAction() == Qt.CopyAction: |
136 elif event.proposedAction() == Qt.CopyAction: |
137 self.tabCopyRequested.emit(fromIndex, toIndex) |
137 self.tabCopyRequested[int, int].emit(fromIndex, toIndex) |
138 event.acceptProposedAction() |
138 event.acceptProposedAction() |
139 E5WheelTabBar.dropEvent(self, event) |
139 E5WheelTabBar.dropEvent(self, event) |
140 |
140 |
141 class TabWidget(E5TabWidget): |
141 class TabWidget(E5TabWidget): |
142 """ |
142 """ |
153 |
153 |
154 self.__tabBar = TabBar(self) |
154 self.__tabBar = TabBar(self) |
155 self.setTabBar(self.__tabBar) |
155 self.setTabBar(self.__tabBar) |
156 |
156 |
157 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
157 self.__tabBar.tabMoveRequested.connect(self.moveTab) |
158 self.__tabBar.tabRelocateRequested.connect(self.relocateTab) |
158 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) |
159 self.__tabBar.tabCopyRequested.connect(self.copyTabOther) |
159 self.__tabBar.tabCopyRequested[str, int, int].connect(self.__copyTabOther) |
160 self.__tabBar.tabCopyRequested.connect(self.copyTab) |
160 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) |
161 |
161 |
162 self.vm = vm |
162 self.vm = vm |
163 self.editors = [] |
163 self.editors = [] |
164 |
164 |
165 self.indicator = E5Led(self) |
165 self.indicator = E5Led(self) |
402 self.closeButton.setEnabled(False) |
402 self.closeButton.setEnabled(False) |
403 else: |
403 else: |
404 self.setTabsClosable(False) |
404 self.setTabsClosable(False) |
405 self.navigationButton.setEnabled(False) |
405 self.navigationButton.setEnabled(False) |
406 |
406 |
407 def relocateTab(self, sourceId, sourceIndex, targetIndex): |
407 def __relocateTab(self, sourceId, sourceIndex, targetIndex): |
408 """ |
408 """ |
409 Public method to relocate an editor from another TabWidget. |
409 Private method to relocate an editor from another TabWidget. |
410 |
410 |
411 @param sourceId id of the TabWidget to get the editor from (long) |
411 @param sourceId id of the TabWidget to get the editor from (string) |
412 @param sourceIndex index of the tab in the old tab widget (integer) |
412 @param sourceIndex index of the tab in the old tab widget (integer) |
413 @param targetIndex index position to place it to (integer) |
413 @param targetIndex index position to place it to (integer) |
414 """ |
414 """ |
415 tw = self.vm.getTabWidgetById(sourceId) |
415 tw = self.vm.getTabWidgetById(int(sourceId)) |
416 if tw is not None: |
416 if tw is not None: |
417 # step 1: get data of the tab of the source |
417 # step 1: get data of the tab of the source |
418 toolTip = tw.tabToolTip(sourceIndex) |
418 toolTip = tw.tabToolTip(sourceIndex) |
419 text = tw.tabText(sourceIndex) |
419 text = tw.tabText(sourceIndex) |
420 icon = tw.tabIcon(sourceIndex) |
420 icon = tw.tabIcon(sourceIndex) |
431 self.setTabWhatsThis(targetIndex, whatsThis) |
431 self.setTabWhatsThis(targetIndex, whatsThis) |
432 |
432 |
433 # step 4: set current widget |
433 # step 4: set current widget |
434 self.setCurrentIndex(targetIndex) |
434 self.setCurrentIndex(targetIndex) |
435 |
435 |
436 def copyTabOther(self, sourceId, sourceIndex, targetIndex): |
436 def __copyTabOther(self, sourceId, sourceIndex, targetIndex): |
437 """ |
437 """ |
438 Public method to copy an editor from another TabWidget. |
438 Private method to copy an editor from another TabWidget. |
439 |
439 |
440 @param sourceId id of the TabWidget to get the editor from (long) |
440 @param sourceId id of the TabWidget to get the editor from (string) |
441 @param sourceIndex index of the tab in the old tab widget (integer) |
441 @param sourceIndex index of the tab in the old tab widget (integer) |
442 @param targetIndex index position to place it to (integer) |
442 @param targetIndex index position to place it to (integer) |
443 """ |
443 """ |
444 tw = self.vm.getTabWidgetById(sourceId) |
444 tw = self.vm.getTabWidgetById(int(sourceId)) |
445 if tw is not None: |
445 if tw is not None: |
446 editor = tw.widget(sourceIndex) |
446 editor = tw.widget(sourceIndex) |
447 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
447 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
448 editor.getFileName()) |
448 editor.getFileName()) |
449 self.vm.insertView(newEditor, self, targetIndex, |
449 self.vm.insertView(newEditor, self, targetIndex, |
450 editor.getFileName(), editor.getNoName()) |
450 editor.getFileName(), editor.getNoName()) |
451 |
451 |
452 def copyTab(self, sourceIndex, targetIndex): |
452 def __copyTab(self, sourceIndex, targetIndex): |
453 """ |
453 """ |
454 Public method to copy an editor. |
454 Private method to copy an editor. |
455 |
455 |
456 @param sourceIndex index of the tab (integer) |
456 @param sourceIndex index of the tab (integer) |
457 @param targetIndex index position to place it to (integer) |
457 @param targetIndex index position to place it to (integer) |
458 """ |
458 """ |
459 editor = self.widget(sourceIndex) |
459 editor = self.widget(sourceIndex) |