E5Gui/E5TabWidget.py

changeset 2990
583beaf0b4b8
parent 2953
703452a2876f
child 3057
10516539f238
child 3160
209a07d7e401
equal deleted inserted replaced
2989:7efa8b8b6903 2990:583beaf0b4b8
6 """ 6 """
7 Module implementing a TabWidget class substituting QTabWidget. 7 Module implementing a TabWidget class substituting QTabWidget.
8 """ 8 """
9 9
10 from PyQt4.QtCore import Qt, QPoint, QMimeData, QByteArray, pyqtSignal 10 from PyQt4.QtCore import Qt, QPoint, QMimeData, QByteArray, pyqtSignal
11 from PyQt4.QtGui import QTabWidget, QTabBar, QApplication, QDrag, QStyle, QLabel, QMovie 11 from PyQt4.QtGui import QTabWidget, QTabBar, QApplication, QDrag, QStyle, \
12 QLabel, QMovie
12 13
13 14
14 class E5WheelTabBar(QTabBar): 15 class E5WheelTabBar(QTabBar):
15 """ 16 """
16 Class implementing a tab bar class substituting QTabBar to support wheel events. 17 Class implementing a tab bar class substituting QTabBar to support wheel
18 events.
17 """ 19 """
18 def __init__(self, parent=None): 20 def __init__(self, parent=None):
19 """ 21 """
20 Constructor 22 Constructor
21 23
43 45
44 class E5DnDTabBar(E5WheelTabBar): 46 class E5DnDTabBar(E5WheelTabBar):
45 """ 47 """
46 Class implementing a tab bar class substituting QTabBar. 48 Class implementing a tab bar class substituting QTabBar.
47 49
48 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving 50 @signal tabMoveRequested(int, int) emitted to signal a tab move request
49 the old and new index position 51 giving the old and new index position
50 """ 52 """
51 tabMoveRequested = pyqtSignal(int, int) 53 tabMoveRequested = pyqtSignal(int, int)
52 54
53 def __init__(self, parent=None): 55 def __init__(self, parent=None):
54 """ 56 """
124 Class implementing a tab widget class substituting QTabWidget. 126 Class implementing a tab widget class substituting QTabWidget.
125 127
126 It provides slots to show the previous and next tab and give 128 It provides slots to show the previous and next tab and give
127 them the input focus and it allows to have a context menu for the tabs. 129 them the input focus and it allows to have a context menu for the tabs.
128 130
129 @signal customTabContextMenuRequested(const QPoint & point, int index) emitted when 131 @signal customTabContextMenuRequested(const QPoint & point, int index)
130 a context menu for a tab is requested 132 emitted when a context menu for a tab is requested
131 """ 133 """
132 customTabContextMenuRequested = pyqtSignal(QPoint, int) 134 customTabContextMenuRequested = pyqtSignal(QPoint, int)
133 135
134 def __init__(self, parent=None, dnd=False): 136 def __init__(self, parent=None, dnd=False):
135 """ 137 """
184 self.__lastCurrentIndex = self.__currentIndex 186 self.__lastCurrentIndex = self.__currentIndex
185 self.__currentIndex = index 187 self.__currentIndex = index
186 188
187 def switchTab(self): 189 def switchTab(self):
188 """ 190 """
189 Public slot used to switch between the current and the previous current tab. 191 Public slot used to switch between the current and the previous
192 current tab.
190 """ 193 """
191 if self.__lastCurrentIndex == -1 or self.__currentIndex == -1: 194 if self.__lastCurrentIndex == -1 or self.__currentIndex == -1:
192 return 195 return
193 196
194 self.setCurrentIndex(self.__lastCurrentIndex) 197 self.setCurrentIndex(self.__lastCurrentIndex)
238 """ 241 """
239 _tabbar = self.tabBar() 242 _tabbar = self.tabBar()
240 for index in range(_tabbar.count()): 243 for index in range(_tabbar.count()):
241 rect = _tabbar.tabRect(index) 244 rect = _tabbar.tabRect(index)
242 if rect.contains(point): 245 if rect.contains(point):
243 self.customTabContextMenuRequested.emit(_tabbar.mapToParent(point), index) 246 self.customTabContextMenuRequested.emit(
247 _tabbar.mapToParent(point), index)
244 return 248 return
245 249
246 self.customTabContextMenuRequested.emit(_tabbar.mapToParent(point), -1) 250 self.customTabContextMenuRequested.emit(_tabbar.mapToParent(point), -1)
247 251
248 def selectTab(self, pos): 252 def selectTab(self, pos):
290 """ 294 """
291 Private method to determine the free side of a tab. 295 Private method to determine the free side of a tab.
292 296
293 @return free side (QTabBar.ButtonPosition) 297 @return free side (QTabBar.ButtonPosition)
294 """ 298 """
295 side = self.__tabBar.style().styleHint(QStyle.SH_TabBar_CloseButtonPosition, 299 side = self.__tabBar.style().styleHint(
300 QStyle.SH_TabBar_CloseButtonPosition,
296 None, None, None) 301 None, None, None)
297 if side == QTabBar.LeftSide: 302 if side == QTabBar.LeftSide:
298 side = QTabBar.RightSide 303 side = QTabBar.RightSide
299 else: 304 else:
300 side = QTabBar.LeftSide 305 side = QTabBar.LeftSide

eric ide

mercurial