eric6/Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
maintenance
changeset 8176
31965986ecd1
parent 8043
0acf98cd089a
parent 8143
2c730d5fd177
child 8273
698ae46f40a4
equal deleted inserted replaced
8153:e01ae92db699 8176:31965986ecd1
74 Protected method to handle mouse press events. 74 Protected method to handle mouse press events.
75 75
76 @param event reference to the mouse press event 76 @param event reference to the mouse press event
77 @type QMouseEvent 77 @type QMouseEvent
78 """ 78 """
79 if event.button() == Qt.LeftButton: 79 if event.button() == Qt.MouseButton.LeftButton:
80 self.__dragStartPos = QPoint(event.pos()) 80 self.__dragStartPos = QPoint(event.pos())
81 super(TabBar, self).mousePressEvent(event) 81 super(TabBar, self).mousePressEvent(event)
82 82
83 def mouseMoveEvent(self, event): 83 def mouseMoveEvent(self, event):
84 """ 84 """
86 86
87 @param event reference to the mouse move event 87 @param event reference to the mouse move event
88 @type QMouseEvent 88 @type QMouseEvent
89 """ 89 """
90 if ( 90 if (
91 event.buttons() == Qt.MouseButtons(Qt.LeftButton) and 91 event.buttons() == Qt.MouseButtons(Qt.MouseButton.LeftButton) and
92 (event.pos() - self.__dragStartPos).manhattanLength() > 92 (event.pos() - self.__dragStartPos).manhattanLength() >
93 QApplication.startDragDistance() 93 QApplication.startDragDistance()
94 ): 94 ):
95 drag = QDrag(self) 95 drag = QDrag(self)
96 mimeData = QMimeData() 96 mimeData = QMimeData()
103 QByteArray.number(self.tabAt(self.__dragStartPos))) 103 QByteArray.number(self.tabAt(self.__dragStartPos)))
104 mimeData.setData( 104 mimeData.setData(
105 "tabwidget-id", 105 "tabwidget-id",
106 str(id(self.parentWidget())).encode("utf-8")) 106 str(id(self.parentWidget())).encode("utf-8"))
107 drag.setMimeData(mimeData) 107 drag.setMimeData(mimeData)
108 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): 108 if event.modifiers() == Qt.KeyboardModifiers(
109 drag.exec(Qt.DropActions(Qt.CopyAction)) 109 Qt.KeyboardModifier.ShiftModifier
110 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): 110 ):
111 drag.exec(Qt.DropActions(Qt.MoveAction)) 111 drag.exec(Qt.DropActions(Qt.DropAction.CopyAction))
112 elif event.modifiers() == Qt.KeyboardModifiers(
113 Qt.KeyboardModifier.NoModifier
114 ):
115 drag.exec(Qt.DropActions(Qt.DropAction.MoveAction))
112 super(TabBar, self).mouseMoveEvent(event) 116 super(TabBar, self).mouseMoveEvent(event)
113 117
114 def dragEnterEvent(self, event): 118 def dragEnterEvent(self, event):
115 """ 119 """
116 Protected method to handle drag enter events. 120 Protected method to handle drag enter events.
141 oldID = int(mimeData.data("tabbar-id")) 145 oldID = int(mimeData.data("tabbar-id"))
142 fromIndex = int(mimeData.data("source-index")) 146 fromIndex = int(mimeData.data("source-index"))
143 toIndex = self.tabAt(event.pos()) 147 toIndex = self.tabAt(event.pos())
144 if oldID != id(self): 148 if oldID != id(self):
145 parentID = int(mimeData.data("tabwidget-id")) 149 parentID = int(mimeData.data("tabwidget-id"))
146 if event.proposedAction() == Qt.MoveAction: 150 if event.proposedAction() == Qt.DropAction.MoveAction:
147 self.tabRelocateRequested.emit( 151 self.tabRelocateRequested.emit(
148 str(parentID), fromIndex, toIndex) 152 str(parentID), fromIndex, toIndex)
149 event.acceptProposedAction() 153 event.acceptProposedAction()
150 elif event.proposedAction() == Qt.CopyAction: 154 elif event.proposedAction() == Qt.DropAction.CopyAction:
151 self.tabCopyRequested[str, int, int].emit( 155 self.tabCopyRequested[str, int, int].emit(
152 str(parentID), fromIndex, toIndex) 156 str(parentID), fromIndex, toIndex)
153 event.acceptProposedAction() 157 event.acceptProposedAction()
154 else: 158 else:
155 if fromIndex != toIndex: 159 if fromIndex != toIndex:
156 if event.proposedAction() == Qt.MoveAction: 160 if event.proposedAction() == Qt.DropAction.MoveAction:
157 self.tabMoveRequested.emit(fromIndex, toIndex) 161 self.tabMoveRequested.emit(fromIndex, toIndex)
158 event.acceptProposedAction() 162 event.acceptProposedAction()
159 elif event.proposedAction() == Qt.CopyAction: 163 elif event.proposedAction() == Qt.DropAction.CopyAction:
160 self.tabCopyRequested[int, int].emit(fromIndex, toIndex) 164 self.tabCopyRequested[int, int].emit(fromIndex, toIndex)
161 event.acceptProposedAction() 165 event.acceptProposedAction()
162 super(TabBar, self).dropEvent(event) 166 super(TabBar, self).dropEvent(event)
163 167
164 168
180 iconSize = self.__tabBar.iconSize() 184 iconSize = self.__tabBar.iconSize()
181 self.__tabBar.setIconSize( 185 self.__tabBar.setIconSize(
182 QSize(2 * iconSize.width(), iconSize.height())) 186 QSize(2 * iconSize.width(), iconSize.height()))
183 187
184 self.setUsesScrollButtons(True) 188 self.setUsesScrollButtons(True)
185 self.setElideMode(Qt.ElideNone) 189 self.setElideMode(Qt.TextElideMode.ElideNone)
186 if isMacPlatform(): 190 if isMacPlatform():
187 self.setDocumentMode(True) 191 self.setDocumentMode(True)
188 192
189 self.__tabBar.tabMoveRequested.connect(self.moveTab) 193 self.__tabBar.tabMoveRequested.connect(self.moveTab)
190 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) 194 self.__tabBar.tabRelocateRequested.connect(self.__relocateTab)
194 198
195 self.vm = vm 199 self.vm = vm
196 self.editors = [] 200 self.editors = []
197 201
198 self.indicator = E5Led(self) 202 self.indicator = E5Led(self)
199 self.setCornerWidget(self.indicator, Qt.TopLeftCorner) 203 self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner)
200 204
201 self.rightCornerWidget = QWidget(self) 205 self.rightCornerWidget = QWidget(self)
202 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) 206 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget)
203 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) 207 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0)
204 self.rightCornerWidgetLayout.setSpacing(0) 208 self.rightCornerWidgetLayout.setSpacing(0)
208 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) 212 self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered)
209 213
210 self.navigationButton = QToolButton(self) 214 self.navigationButton = QToolButton(self)
211 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) 215 self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow"))
212 self.navigationButton.setToolTip(self.tr("Show a navigation menu")) 216 self.navigationButton.setToolTip(self.tr("Show a navigation menu"))
213 self.navigationButton.setPopupMode(QToolButton.InstantPopup) 217 self.navigationButton.setPopupMode(
218 QToolButton.ToolButtonPopupMode.InstantPopup)
214 self.navigationButton.setMenu(self.__navigationMenu) 219 self.navigationButton.setMenu(self.__navigationMenu)
215 self.navigationButton.setEnabled(False) 220 self.navigationButton.setEnabled(False)
216 self.rightCornerWidgetLayout.addWidget(self.navigationButton) 221 self.rightCornerWidgetLayout.addWidget(self.navigationButton)
217 222
218 self.tabCloseRequested.connect(self.__closeRequested) 223 self.tabCloseRequested.connect(self.__closeRequested)
219 224
220 self.setCornerWidget(self.rightCornerWidget, Qt.TopRightCorner) 225 self.setCornerWidget(self.rightCornerWidget, Qt.Corner.TopRightCorner)
221 226
222 self.__initMenu() 227 self.__initMenu()
223 self.contextMenuEditor = None 228 self.contextMenuEditor = None
224 self.contextMenuIndex = -1 229 self.contextMenuIndex = -1
225 230
226 self.setTabContextMenuPolicy(Qt.CustomContextMenu) 231 self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
227 self.customTabContextMenuRequested.connect(self.__showContextMenu) 232 self.customTabContextMenuRequested.connect(self.__showContextMenu)
228 233
229 ericPic = QPixmap( 234 ericPic = QPixmap(
230 os.path.join(getConfig('ericPixDir'), 'eric_small.png')) 235 os.path.join(getConfig('ericPixDir'), 'eric_small.png'))
231 self.emptyLabel = QLabel() 236 self.emptyLabel = QLabel()
232 self.emptyLabel.setPixmap(ericPic) 237 self.emptyLabel.setPixmap(ericPic)
233 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) 238 self.emptyLabel.setAlignment(
239 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter)
234 super(TabWidget, self).addTab( 240 super(TabWidget, self).addTab(
235 self.emptyLabel, 241 self.emptyLabel,
236 UI.PixmapCache.getIcon("empty"), "") 242 UI.PixmapCache.getIcon("empty"), "")
237 243
238 def __initMenu(self): 244 def __initMenu(self):
809 self.currentTabWidget = tw 815 self.currentTabWidget = tw
810 self.currentTabWidget.showIndicator(True) 816 self.currentTabWidget.showIndicator(True)
811 tw.currentChanged.connect(self.__currentChanged) 817 tw.currentChanged.connect(self.__currentChanged)
812 tw.installEventFilter(self) 818 tw.installEventFilter(self)
813 tw.tabBar().installEventFilter(self) 819 tw.tabBar().installEventFilter(self)
814 self.__splitter.setOrientation(Qt.Vertical) 820 self.__splitter.setOrientation(Qt.Orientation.Vertical)
815 self.__inRemoveView = False 821 self.__inRemoveView = False
816 822
817 self.maxFileNameChars = Preferences.getUI( 823 self.maxFileNameChars = Preferences.getUI(
818 "TabViewManagerFilenameLength") 824 "TabViewManagerFilenameLength")
819 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") 825 self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
1158 self.currentTabWidget = self.tabWidgets[-1] 1164 self.currentTabWidget = self.tabWidgets[-1]
1159 self.currentTabWidget.showIndicator(True) 1165 self.currentTabWidget.showIndicator(True)
1160 tw.currentChanged.connect(self.__currentChanged) 1166 tw.currentChanged.connect(self.__currentChanged)
1161 tw.installEventFilter(self) 1167 tw.installEventFilter(self)
1162 tw.tabBar().installEventFilter(self) 1168 tw.tabBar().installEventFilter(self)
1163 if self.__splitter.orientation() == Qt.Horizontal: 1169 if self.__splitter.orientation() == Qt.Orientation.Horizontal:
1164 size = self.width() 1170 size = self.width()
1165 else: 1171 else:
1166 size = self.height() 1172 size = self.height()
1167 self.__splitter.setSizes( 1173 self.__splitter.setSizes(
1168 [int(size / len(self.tabWidgets))] * len(self.tabWidgets)) 1174 [int(size / len(self.tabWidgets))] * len(self.tabWidgets))
1209 if self.currentTabWidget is not None: 1215 if self.currentTabWidget is not None:
1210 assembly = self.currentTabWidget.currentWidget() 1216 assembly = self.currentTabWidget.currentWidget()
1211 if assembly is not None: 1217 if assembly is not None:
1212 editor = assembly.getEditor() 1218 editor = assembly.getEditor()
1213 if editor is not None: 1219 if editor is not None:
1214 editor.setFocus(Qt.OtherFocusReason) 1220 editor.setFocus(Qt.FocusReason.OtherFocusReason)
1215 if len(self.tabWidgets) == 1: 1221 if len(self.tabWidgets) == 1:
1216 self.splitRemoveAct.setEnabled(False) 1222 self.splitRemoveAct.setEnabled(False)
1217 self.nextSplitAct.setEnabled(False) 1223 self.nextSplitAct.setEnabled(False)
1218 self.prevSplitAct.setEnabled(False) 1224 self.prevSplitAct.setEnabled(False)
1219 return True 1225 return True
1247 def getSplitOrientation(self): 1253 def getSplitOrientation(self):
1248 """ 1254 """
1249 Public method to get the orientation of the split view. 1255 Public method to get the orientation of the split view.
1250 1256
1251 @return orientation of the split 1257 @return orientation of the split
1252 @rtype Qt.Horizontal or Qt.Vertical 1258 @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical
1253 """ 1259 """
1254 return self.__splitter.orientation() 1260 return self.__splitter.orientation()
1255 1261
1256 def setSplitOrientation(self, orientation): 1262 def setSplitOrientation(self, orientation):
1257 """ 1263 """
1258 Public method used to set the orientation of the split view. 1264 Public method used to set the orientation of the split view.
1259 1265
1260 @param orientation orientation of the split 1266 @param orientation orientation of the split
1261 @type Qt.Horizontal or Qt.Vertical 1267 @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical
1262 """ 1268 """
1263 self.__splitter.setOrientation(orientation) 1269 self.__splitter.setOrientation(orientation)
1264 1270
1265 def nextSplit(self): 1271 def nextSplit(self):
1266 """ 1272 """
1335 @type QEvent 1341 @type QEvent
1336 @return always False 1342 @return always False
1337 @rtype bool 1343 @rtype bool
1338 """ 1344 """
1339 if ( 1345 if (
1340 event.type() == QEvent.MouseButtonPress and 1346 event.type() == QEvent.Type.MouseButtonPress and
1341 not event.button() == Qt.RightButton 1347 not event.button() == Qt.MouseButton.RightButton
1342 ): 1348 ):
1343 switched = True 1349 switched = True
1344 self.currentTabWidget.showIndicator(False) 1350 self.currentTabWidget.showIndicator(False)
1345 if isinstance(watched, E5TabWidget): 1351 if isinstance(watched, E5TabWidget):
1346 switched = watched is not self.currentTabWidget 1352 switched = watched is not self.currentTabWidget

eric ide

mercurial