10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import * |
12 from PyQt4.QtCore import * |
13 from PyQt4.QtGui import * |
13 from PyQt4.QtGui import * |
14 |
14 |
15 from E4Gui.E4Application import e5App |
15 from E5Gui.E5Application import e5App |
16 |
16 |
17 from ViewManager.ViewManager import ViewManager |
17 from ViewManager.ViewManager import ViewManager |
18 |
18 |
19 import QScintilla.Editor |
19 import QScintilla.Editor |
20 |
20 |
21 import UI.PixmapCache |
21 import UI.PixmapCache |
22 |
22 |
23 from E4Gui.E4TabWidget import E4TabWidget, E4WheelTabBar |
23 from E5Gui.E5TabWidget import E5TabWidget, E5WheelTabBar |
24 from E4Gui.E4Led import E4Led |
24 from E5Gui.E5Led import E5Led |
25 |
25 |
26 import Preferences |
26 import Preferences |
27 |
27 |
28 from eric5config import getConfig |
28 from eric5config import getConfig |
29 |
29 |
30 class TabBar(E4WheelTabBar): |
30 class TabBar(E5WheelTabBar): |
31 """ |
31 """ |
32 Class implementing a customized tab bar supporting drag & drop. |
32 Class implementing a customized tab bar supporting drag & drop. |
33 |
33 |
34 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving |
34 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving |
35 the old and new index position |
35 the old and new index position |
46 """ |
46 """ |
47 Constructor |
47 Constructor |
48 |
48 |
49 @param parent reference to the parent widget (QWidget) |
49 @param parent reference to the parent widget (QWidget) |
50 """ |
50 """ |
51 E4WheelTabBar.__init__(self, parent) |
51 E5WheelTabBar.__init__(self, parent) |
52 self.setAcceptDrops(True) |
52 self.setAcceptDrops(True) |
53 |
53 |
54 self.__dragStartPos = QPoint() |
54 self.__dragStartPos = QPoint() |
55 |
55 |
56 def mousePressEvent(self, event): |
56 def mousePressEvent(self, event): |
59 |
59 |
60 @param event reference to the mouse press event (QMouseEvent) |
60 @param event reference to the mouse press event (QMouseEvent) |
61 """ |
61 """ |
62 if event.button() == Qt.LeftButton: |
62 if event.button() == Qt.LeftButton: |
63 self.__dragStartPos = QPoint(event.pos()) |
63 self.__dragStartPos = QPoint(event.pos()) |
64 E4WheelTabBar.mousePressEvent(self, event) |
64 E5WheelTabBar.mousePressEvent(self, event) |
65 |
65 |
66 def mouseMoveEvent(self, event): |
66 def mouseMoveEvent(self, event): |
67 """ |
67 """ |
68 Protected method to handle mouse move events. |
68 Protected method to handle mouse move events. |
69 |
69 |
84 drag.setMimeData(mimeData) |
84 drag.setMimeData(mimeData) |
85 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
85 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
86 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
86 drag.exec_(Qt.DropActions(Qt.CopyAction)) |
87 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
87 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): |
88 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
88 drag.exec_(Qt.DropActions(Qt.MoveAction)) |
89 E4WheelTabBar.mouseMoveEvent(self, event) |
89 E5WheelTabBar.mouseMoveEvent(self, event) |
90 |
90 |
91 def dragEnterEvent(self, event): |
91 def dragEnterEvent(self, event): |
92 """ |
92 """ |
93 Protected method to handle drag enter events. |
93 Protected method to handle drag enter events. |
94 |
94 |
100 mimeData.data("action") == "tab-reordering" and \ |
100 mimeData.data("action") == "tab-reordering" and \ |
101 "tabbar-id" in formats and \ |
101 "tabbar-id" in formats and \ |
102 "source-index" in formats and \ |
102 "source-index" in formats and \ |
103 "tabwidget-id" in formats: |
103 "tabwidget-id" in formats: |
104 event.acceptProposedAction() |
104 event.acceptProposedAction() |
105 E4WheelTabBar.dragEnterEvent(self, event) |
105 E5WheelTabBar.dragEnterEvent(self, event) |
106 |
106 |
107 def dropEvent(self, event): |
107 def dropEvent(self, event): |
108 """ |
108 """ |
109 Protected method to handle drop events. |
109 Protected method to handle drop events. |
110 |
110 |
130 self.emit(SIGNAL("tabMoveRequested(int, int)"), fromIndex, toIndex) |
130 self.emit(SIGNAL("tabMoveRequested(int, int)"), fromIndex, toIndex) |
131 event.acceptProposedAction() |
131 event.acceptProposedAction() |
132 elif event.proposedAction() == Qt.CopyAction: |
132 elif event.proposedAction() == Qt.CopyAction: |
133 self.emit(SIGNAL("tabCopyRequested(int, int)"), fromIndex, toIndex) |
133 self.emit(SIGNAL("tabCopyRequested(int, int)"), fromIndex, toIndex) |
134 event.acceptProposedAction() |
134 event.acceptProposedAction() |
135 E4WheelTabBar.dropEvent(self, event) |
135 E5WheelTabBar.dropEvent(self, event) |
136 |
136 |
137 class TabWidget(E4TabWidget): |
137 class TabWidget(E5TabWidget): |
138 """ |
138 """ |
139 Class implementing a custimized tab widget. |
139 Class implementing a custimized tab widget. |
140 """ |
140 """ |
141 def __init__(self, vm): |
141 def __init__(self, vm): |
142 """ |
142 """ |
143 Constructor |
143 Constructor |
144 |
144 |
145 @param vm view manager widget (Tabview) |
145 @param vm view manager widget (Tabview) |
146 """ |
146 """ |
147 E4TabWidget.__init__(self) |
147 E5TabWidget.__init__(self) |
148 self.setAttribute(Qt.WA_DeleteOnClose, True) |
148 self.setAttribute(Qt.WA_DeleteOnClose, True) |
149 |
149 |
150 self.__tabBar = TabBar(self) |
150 self.__tabBar = TabBar(self) |
151 self.setTabBar(self.__tabBar) |
151 self.setTabBar(self.__tabBar) |
152 |
152 |
160 self.copyTab) |
160 self.copyTab) |
161 |
161 |
162 self.vm = vm |
162 self.vm = vm |
163 self.editors = [] |
163 self.editors = [] |
164 |
164 |
165 self.indicator = E4Led(self) |
165 self.indicator = E5Led(self) |
166 self.setCornerWidget(self.indicator, Qt.TopLeftCorner) |
166 self.setCornerWidget(self.indicator, Qt.TopLeftCorner) |
167 |
167 |
168 self.rightCornerWidget = QWidget(self) |
168 self.rightCornerWidget = QWidget(self) |
169 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) |
169 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) |
170 self.rightCornerWidgetLayout.setMargin(0) |
170 self.rightCornerWidgetLayout.setMargin(0) |
210 |
210 |
211 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
211 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) |
212 self.emptyLabel = QLabel() |
212 self.emptyLabel = QLabel() |
213 self.emptyLabel.setPixmap(ericPic) |
213 self.emptyLabel.setPixmap(ericPic) |
214 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
214 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) |
215 E4TabWidget.addTab(self, self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
215 E5TabWidget.addTab(self, self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") |
216 |
216 |
217 def __initMenu(self): |
217 def __initMenu(self): |
218 """ |
218 """ |
219 Private method to initialize the tab context menu. |
219 Private method to initialize the tab context menu. |
220 """ |
220 """ |
312 Overwritten method to add a new tab. |
312 Overwritten method to add a new tab. |
313 |
313 |
314 @param editor the editor object to be added (QScintilla.Editor.Editor) |
314 @param editor the editor object to be added (QScintilla.Editor.Editor) |
315 @param title title for the new tab (string) |
315 @param title title for the new tab (string) |
316 """ |
316 """ |
317 E4TabWidget.addTab(self, editor, UI.PixmapCache.getIcon("empty.png"), title) |
317 E5TabWidget.addTab(self, editor, UI.PixmapCache.getIcon("empty.png"), title) |
318 if self.closeButton: |
318 if self.closeButton: |
319 self.closeButton.setEnabled(True) |
319 self.closeButton.setEnabled(True) |
320 else: |
320 else: |
321 self.setTabsClosable(True) |
321 self.setTabsClosable(True) |
322 self.navigationButton.setEnabled(True) |
322 self.navigationButton.setEnabled(True) |
337 @param index index position for the new tab (integer) |
337 @param index index position for the new tab (integer) |
338 @param editor the editor object to be added (QScintilla.Editor.Editor) |
338 @param editor the editor object to be added (QScintilla.Editor.Editor) |
339 @param title title for the new tab (string) |
339 @param title title for the new tab (string) |
340 @return index of the inserted tab (integer) |
340 @return index of the inserted tab (integer) |
341 """ |
341 """ |
342 newIndex = E4TabWidget.insertTab(self, index, editor, |
342 newIndex = E5TabWidget.insertTab(self, index, editor, |
343 UI.PixmapCache.getIcon("empty.png"), |
343 UI.PixmapCache.getIcon("empty.png"), |
344 title) |
344 title) |
345 if self.closeButton: |
345 if self.closeButton: |
346 self.closeButton.setEnabled(True) |
346 self.closeButton.setEnabled(True) |
347 else: |
347 else: |
403 self.disconnect(object, SIGNAL('captionChanged'), |
403 self.disconnect(object, SIGNAL('captionChanged'), |
404 self.__captionChange) |
404 self.__captionChange) |
405 self.editors.remove(object) |
405 self.editors.remove(object) |
406 |
406 |
407 if not self.editors: |
407 if not self.editors: |
408 E4TabWidget.addTab(self, self.emptyLabel, |
408 E5TabWidget.addTab(self, self.emptyLabel, |
409 UI.PixmapCache.getIcon("empty.png"), "") |
409 UI.PixmapCache.getIcon("empty.png"), "") |
410 self.emptyLabel.show() |
410 self.emptyLabel.show() |
411 if self.closeButton: |
411 if self.closeButton: |
412 self.closeButton.setEnabled(False) |
412 self.closeButton.setEnabled(False) |
413 else: |
413 else: |
1024 @return always False |
1024 @return always False |
1025 """ |
1025 """ |
1026 if event.type() == QEvent.MouseButtonPress and \ |
1026 if event.type() == QEvent.MouseButtonPress and \ |
1027 not event.button() == Qt.RightButton: |
1027 not event.button() == Qt.RightButton: |
1028 self.currentTabWidget.showIndicator(False) |
1028 self.currentTabWidget.showIndicator(False) |
1029 if isinstance(watched, E4TabWidget): |
1029 if isinstance(watched, E5TabWidget): |
1030 switched = watched is not self.currentTabWidget |
1030 switched = watched is not self.currentTabWidget |
1031 self.currentTabWidget = watched |
1031 self.currentTabWidget = watched |
1032 elif isinstance(watched, QTabBar): |
1032 elif isinstance(watched, QTabBar): |
1033 switched = watched.parent() is not self.currentTabWidget |
1033 switched = watched.parent() is not self.currentTabWidget |
1034 self.currentTabWidget = watched.parent() |
1034 self.currentTabWidget = watched.parent() |