54 """ |
54 """ |
55 Constructor |
55 Constructor |
56 |
56 |
57 @param parent reference to the parent widget (QWidget) |
57 @param parent reference to the parent widget (QWidget) |
58 """ |
58 """ |
59 E5WheelTabBar.__init__(self, parent) |
59 super().__init__(parent) |
60 self.setAcceptDrops(True) |
60 self.setAcceptDrops(True) |
61 |
61 |
62 self.__dragStartPos = QPoint() |
62 self.__dragStartPos = QPoint() |
63 |
63 |
64 def mousePressEvent(self, event): |
64 def mousePressEvent(self, event): |
67 |
67 |
68 @param event reference to the mouse press event (QMouseEvent) |
68 @param event reference to the mouse press event (QMouseEvent) |
69 """ |
69 """ |
70 if event.button() == Qt.LeftButton: |
70 if event.button() == Qt.LeftButton: |
71 self.__dragStartPos = QPoint(event.pos()) |
71 self.__dragStartPos = QPoint(event.pos()) |
72 E5WheelTabBar.mousePressEvent(self, event) |
72 super().mousePressEvent(event) |
73 |
73 |
74 def mouseMoveEvent(self, event): |
74 def mouseMoveEvent(self, event): |
75 """ |
75 """ |
76 Protected method to handle mouse move events. |
76 Protected method to handle mouse move events. |
77 |
77 |
92 drag.setMimeData(mimeData) |
92 drag.setMimeData(mimeData) |
93 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
93 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
94 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
94 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
95 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
95 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
96 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
96 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
97 E5WheelTabBar.mouseMoveEvent(self, event) |
97 super().mouseMoveEvent(event) |
98 |
98 |
99 def dragEnterEvent(self, event): |
99 def dragEnterEvent(self, event): |
100 """ |
100 """ |
101 Protected method to handle drag enter events. |
101 Protected method to handle drag enter events. |
102 |
102 |
108 mimeData.data("action") == "tab-reordering" and \ |
108 mimeData.data("action") == "tab-reordering" and \ |
109 "tabbar-id" in formats and \ |
109 "tabbar-id" in formats and \ |
110 "source-index" in formats and \ |
110 "source-index" in formats and \ |
111 "tabwidget-id" in formats: |
111 "tabwidget-id" in formats: |
112 event.acceptProposedAction() |
112 event.acceptProposedAction() |
113 E5WheelTabBar.dragEnterEvent(self, event) |
113 super().dragEnterEvent(event) |
114 |
114 |
115 def dropEvent(self, event): |
115 def dropEvent(self, event): |
116 """ |
116 """ |
117 Protected method to handle drop events. |
117 Protected method to handle drop events. |
118 |
118 |
136 self.tabMoveRequested.emit(fromIndex, toIndex) |
136 self.tabMoveRequested.emit(fromIndex, toIndex) |
137 event.acceptProposedAction() |
137 event.acceptProposedAction() |
138 elif event.proposedAction() == Qt.CopyAction: |
138 elif event.proposedAction() == Qt.CopyAction: |
139 self.tabCopyRequested.emit(fromIndex, toIndex) |
139 self.tabCopyRequested.emit(fromIndex, toIndex) |
140 event.acceptProposedAction() |
140 event.acceptProposedAction() |
141 E5WheelTabBar.dropEvent(self, event) |
141 super().dropEvent(event) |
142 |
142 |
143 |
143 |
144 class TabWidget(E5TabWidget): |
144 class TabWidget(E5TabWidget): |
145 """ |
145 """ |
146 Class implementing a custimized tab widget. |
146 Class implementing a custimized tab widget. |
208 |
208 |
209 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
209 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
210 self.emptyLabel = QLabel() |
210 self.emptyLabel = QLabel() |
211 self.emptyLabel.setPixmap(ericPic) |
211 self.emptyLabel.setPixmap(ericPic) |
212 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
212 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
213 E5TabWidget.addTab(self, self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
213 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
214 |
214 |
215 def __initMenu(self): |
215 def __initMenu(self): |
216 """ |
216 """ |
217 Private method to initialize the tab context menu. |
217 Private method to initialize the tab context menu. |
218 """ |
218 """ |
261 |
261 |
262 @param coord the position of the mouse pointer (QPoint) |
262 @param coord the position of the mouse pointer (QPoint) |
263 @param index index of the tab the menu is requested for (integer) |
263 @param index index of the tab the menu is requested for (integer) |
264 """ |
264 """ |
265 if self.editors: |
265 if self.editors: |
266 self.contextMenuEditor = self.widget(index) |
266 self.contextMenuEditor = self.widget(index).getEditor() |
267 if self.contextMenuEditor: |
267 if self.contextMenuEditor: |
268 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
268 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
269 fileName = self.contextMenuEditor.getFileName() |
269 fileName = self.contextMenuEditor.getFileName() |
270 self.copyPathAct.setEnabled(bool(fileName)) |
270 self.copyPathAct.setEnabled(bool(fileName)) |
271 if fileName: |
271 if fileName: |
321 Overwritten method to add a new tab. |
321 Overwritten method to add a new tab. |
322 |
322 |
323 @param editor the editor object to be added (QScintilla.Editor.Editor) |
323 @param editor the editor object to be added (QScintilla.Editor.Editor) |
324 @param title title for the new tab (string) |
324 @param title title for the new tab (string) |
325 """ |
325 """ |
326 E5TabWidget.addTab(self, editor, UI.PixmapCache.getIcon("empty.png"), title) |
326 assembly = editor.parent() |
|
327 super().addTab(assembly, UI.PixmapCache.getIcon("empty.png"), title) |
327 if self.closeButton: |
328 if self.closeButton: |
328 self.closeButton.setEnabled(True) |
329 self.closeButton.setEnabled(True) |
329 else: |
330 else: |
330 self.setTabsClosable(True) |
331 self.setTabsClosable(True) |
331 self.navigationButton.setEnabled(True) |
332 self.navigationButton.setEnabled(True) |
345 @param index index position for the new tab (integer) |
346 @param index index position for the new tab (integer) |
346 @param editor the editor object to be added (QScintilla.Editor.Editor) |
347 @param editor the editor object to be added (QScintilla.Editor.Editor) |
347 @param title title for the new tab (string) |
348 @param title title for the new tab (string) |
348 @return index of the inserted tab (integer) |
349 @return index of the inserted tab (integer) |
349 """ |
350 """ |
350 newIndex = E5TabWidget.insertTab(self, index, editor, |
351 assembly = editor.parent() |
351 UI.PixmapCache.getIcon("empty.png"), |
352 newIndex = super().insertTab(index, assembly, |
352 title) |
353 UI.PixmapCache.getIcon("empty.png"), |
|
354 title) |
353 if self.closeButton: |
355 if self.closeButton: |
354 self.closeButton.setEnabled(True) |
356 self.closeButton.setEnabled(True) |
355 else: |
357 else: |
356 self.setTabsClosable(True) |
358 self.setTabsClosable(True) |
357 self.navigationButton.setEnabled(True) |
359 self.navigationButton.setEnabled(True) |
386 if len(txt) > maxFileNameChars: |
388 if len(txt) > maxFileNameChars: |
387 txt = "...{0}".format(txt[-maxFileNameChars:]) |
389 txt = "...{0}".format(txt[-maxFileNameChars:]) |
388 if editor.isReadOnly(): |
390 if editor.isReadOnly(): |
389 txt = self.trUtf8("{0} (ro)").format(txt) |
391 txt = self.trUtf8("{0} (ro)").format(txt) |
390 |
392 |
391 index = self.indexOf(editor) |
393 assembly = editor.parent() |
|
394 index = self.indexOf(assembly) |
392 if index > -1: |
395 if index > -1: |
393 self.setTabText(index, txt) |
396 self.setTabText(index, txt) |
394 self.setTabToolTip(index, fn) |
397 self.setTabToolTip(index, fn) |
395 |
398 |
396 def removeWidget(self, object): |
399 def removeWidget(self, object): |
397 """ |
400 """ |
398 Public method to remove a widget. |
401 Public method to remove a widget. |
399 |
402 |
400 @param object object to be removed (QWidget) |
403 @param object object to be removed (QWidget) |
401 """ |
404 """ |
402 index = self.indexOf(object) |
|
403 if index > -1: |
|
404 self.removeTab(index) |
|
405 |
|
406 if isinstance(object, QScintilla.Editor.Editor): |
405 if isinstance(object, QScintilla.Editor.Editor): |
407 object.captionChanged.disconnect(self.__captionChange) |
406 object.captionChanged.disconnect(self.__captionChange) |
408 self.editors.remove(object) |
407 self.editors.remove(object) |
|
408 index = self.indexOf(object.parent()) |
|
409 else: |
|
410 index = self.indexOf(object) |
|
411 if index > -1: |
|
412 self.removeTab(index) |
409 |
413 |
410 if not self.editors: |
414 if not self.editors: |
411 E5TabWidget.addTab(self, self.emptyLabel, |
415 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
412 UI.PixmapCache.getIcon("empty.png"), "") |
|
413 self.emptyLabel.show() |
416 self.emptyLabel.show() |
414 if self.closeButton: |
417 if self.closeButton: |
415 self.closeButton.setEnabled(False) |
418 self.closeButton.setEnabled(False) |
416 else: |
419 else: |
417 self.setTabsClosable(False) |
420 self.setTabsClosable(False) |
430 # step 1: get data of the tab of the source |
433 # step 1: get data of the tab of the source |
431 toolTip = tw.tabToolTip(sourceIndex) |
434 toolTip = tw.tabToolTip(sourceIndex) |
432 text = tw.tabText(sourceIndex) |
435 text = tw.tabText(sourceIndex) |
433 icon = tw.tabIcon(sourceIndex) |
436 icon = tw.tabIcon(sourceIndex) |
434 whatsThis = tw.tabWhatsThis(sourceIndex) |
437 whatsThis = tw.tabWhatsThis(sourceIndex) |
435 editor = tw.widget(sourceIndex) |
438 editor = tw.widget(sourceIndex).getEditor() |
436 |
439 |
437 # step 2: relocate the tab |
440 # step 2: relocate the tab |
438 tw.removeWidget(editor) |
441 tw.removeWidget(editor) |
439 self.insertWidget(targetIndex, editor, text) |
442 self.insertWidget(targetIndex, editor, text) |
440 |
443 |
454 @param sourceIndex index of the tab in the old tab widget (integer) |
457 @param sourceIndex index of the tab in the old tab widget (integer) |
455 @param targetIndex index position to place it to (integer) |
458 @param targetIndex index position to place it to (integer) |
456 """ |
459 """ |
457 tw = self.vm.getTabWidgetById(sourceId) |
460 tw = self.vm.getTabWidgetById(sourceId) |
458 if tw is not None: |
461 if tw is not None: |
459 editor = tw.widget(sourceIndex) |
462 editor = tw.widget(sourceIndex).getEditor() |
460 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
463 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
461 editor.getFileName()) |
464 editor.getFileName()) |
462 self.vm.insertView(newEditor, self, targetIndex, |
465 self.vm.insertView(newEditor, self, targetIndex, |
463 editor.getFileName(), editor.getNoName()) |
466 editor.getFileName(), editor.getNoName()) |
464 |
467 |
467 Public method to copy an editor. |
470 Public method to copy an editor. |
468 |
471 |
469 @param sourceIndex index of the tab (integer) |
472 @param sourceIndex index of the tab (integer) |
470 @param targetIndex index position to place it to (integer) |
473 @param targetIndex index position to place it to (integer) |
471 """ |
474 """ |
472 editor = self.widget(sourceIndex) |
475 editor = self.widget(sourceIndex).getEditor() |
473 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
476 newEditor = self.vm.cloneEditor(editor, editor.getFileType(), |
474 editor.getFileName()) |
477 editor.getFileName()) |
475 self.vm.insertView(newEditor, self, targetIndex, |
478 self.vm.insertView(newEditor, self, targetIndex, |
476 editor.getFileName(), editor.getNoName()) |
479 editor.getFileName(), editor.getNoName()) |
477 |
480 |
478 def currentWidget(self): |
481 def currentWidget(self): |
479 """ |
482 """ |
480 Overridden method to return a reference to the current page. |
483 Overridden method to return a reference to the current page. |
481 |
484 |
482 @return reference to the current page (QWidget) |
485 @return reference to the current page (Editor) |
483 """ |
486 """ |
484 if not self.editors: |
487 if not self.editors: |
485 return None |
488 return None |
486 else: |
489 else: |
487 return E5TabWidget.currentWidget(self) |
490 try: |
|
491 return super().currentWidget().getEditor() |
|
492 except AttributeError: |
|
493 return super().currentWidget() |
|
494 |
|
495 def setCurrentWidget(self, editor): |
|
496 """ |
|
497 Public method to set the current tab by the given editor. |
|
498 |
|
499 @param editor editor to determine current tab from (Editor) |
|
500 """ |
|
501 super().setCurrentWidget(editor.parent()) |
|
502 |
|
503 def indexOf(self, object): |
|
504 """ |
|
505 Public method to get the tab index of the given editor. |
|
506 |
|
507 @param object object to get the index for (QLabel or Editor) |
|
508 @return tab index of the editor (integer) |
|
509 """ |
|
510 if isinstance(object, QScintilla.Editor.Editor): |
|
511 object = object.parent() |
|
512 return super().indexOf(object) |
488 |
513 |
489 def hasEditor(self, editor): |
514 def hasEditor(self, editor): |
490 """ |
515 """ |
491 Public method to check for an editor. |
516 Public method to check for an editor. |
492 |
517 |
516 Private method to close the other tabs. |
541 Private method to close the other tabs. |
517 """ |
542 """ |
518 index = self.contextMenuIndex |
543 index = self.contextMenuIndex |
519 for i in list(range(self.count() - 1, index, -1)) + \ |
544 for i in list(range(self.count() - 1, index, -1)) + \ |
520 list(range(index - 1, -1, -1)): |
545 list(range(index - 1, -1, -1)): |
521 editor = self.widget(i) |
546 editor = self.widget(i).getEditor() |
522 self.vm.closeEditorWindow(editor) |
547 self.vm.closeEditorWindow(editor) |
523 |
548 |
524 def __contextMenuCloseAll(self): |
549 def __contextMenuCloseAll(self): |
525 """ |
550 """ |
526 Private method to close all tabs. |
551 Private method to close all tabs. |
603 |
628 |
604 def __closeButtonClicked(self): |
629 def __closeButtonClicked(self): |
605 """ |
630 """ |
606 Private method to handle the press of the close button. |
631 Private method to handle the press of the close button. |
607 """ |
632 """ |
608 self.vm.closeEditorWindow(self.currentWidget()) |
633 self.vm.closeEditorWindow(self.currentWidget().getEditor()) |
609 |
634 |
610 def __closeRequested(self, index): |
635 def __closeRequested(self, index): |
611 """ |
636 """ |
612 Private method to handle the press of the individual tab close button. |
637 Private method to handle the press of the individual tab close button. |
613 |
638 |
614 @param index index of the tab (integer) |
639 @param index index of the tab (integer) |
615 """ |
640 """ |
616 if index >= 0: |
641 if index >= 0: |
617 self.vm.closeEditorWindow(self.widget(index)) |
642 self.vm.closeEditorWindow(self.widget(index).getEditor()) |
618 |
643 |
619 def mouseDoubleClickEvent(self, event): |
644 def mouseDoubleClickEvent(self, event): |
620 """ |
645 """ |
621 Protected method handling double click events. |
646 Protected method handling double click events. |
622 |
647 |