E5Gui/E5TabWidget.py

changeset 482
4650a72c307a
parent 458
1695e7a2db54
child 634
7b84cbd2f752
equal deleted inserted replaced
481:ad71812ba395 482:4650a72c307a
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.QtGui import QTabWidget, QTabBar, QApplication, QDrag, QStyle, QLabel, QMovie 10 from PyQt4.QtGui import QTabWidget, QTabBar, QApplication, QDrag, QStyle, QLabel, QMovie
11 from PyQt4.QtCore import Qt, SIGNAL, QPoint, QMimeData, QByteArray, pyqtSignal 11 from PyQt4.QtCore import Qt, QPoint, QMimeData, QByteArray, pyqtSignal
12 12
13 class E5WheelTabBar(QTabBar): 13 class E5WheelTabBar(QTabBar):
14 """ 14 """
15 Class implementing a tab bar class substituting QTabBar to support wheel events. 15 Class implementing a tab bar class substituting QTabBar to support wheel events.
16 """ 16 """
44 Class implementing a tab bar class substituting QTabBar. 44 Class implementing a tab bar class substituting QTabBar.
45 45
46 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving 46 @signal tabMoveRequested(int, int) emitted to signal a tab move request giving
47 the old and new index position 47 the old and new index position
48 """ 48 """
49 tabMoveRequested = pyqtSignal(int, int)
50
49 def __init__(self, parent = None): 51 def __init__(self, parent = None):
50 """ 52 """
51 Constructor 53 Constructor
52 54
53 @param parent reference to the parent widget (QWidget) 55 @param parent reference to the parent widget (QWidget)
108 @param event reference to the drop event (QDropEvent) 110 @param event reference to the drop event (QDropEvent)
109 """ 111 """
110 fromIndex = self.tabAt(self.__dragStartPos) 112 fromIndex = self.tabAt(self.__dragStartPos)
111 toIndex = self.tabAt(event.pos()) 113 toIndex = self.tabAt(event.pos())
112 if fromIndex != toIndex: 114 if fromIndex != toIndex:
113 self.emit(SIGNAL("tabMoveRequested(int, int)"), fromIndex, toIndex) 115 self.tabMoveRequested.emit(fromIndex, toIndex)
114 event.acceptProposedAction() 116 event.acceptProposedAction()
115 E5WheelTabBar.dropEvent(self, event) 117 E5WheelTabBar.dropEvent(self, event)
116 118
117 class E5TabWidget(QTabWidget): 119 class E5TabWidget(QTabWidget):
118 """ 120 """
136 QTabWidget.__init__(self, parent) 138 QTabWidget.__init__(self, parent)
137 139
138 if dnd: 140 if dnd:
139 if not hasattr(self, 'setMovable'): 141 if not hasattr(self, 'setMovable'):
140 self.__tabBar = E5DnDTabBar(self) 142 self.__tabBar = E5DnDTabBar(self)
141 self.connect(self.__tabBar, SIGNAL("tabMoveRequested(int, int)"), 143 self.__tabBar.tabMoveRequested.connect(self.moveTab)
142 self.moveTab)
143 self.setTabBar(self.__tabBar) 144 self.setTabBar(self.__tabBar)
144 else: 145 else:
145 self.__tabBar = E5WheelTabBar(self) 146 self.__tabBar = E5WheelTabBar(self)
146 self.setTabBar(self.__tabBar) 147 self.setTabBar(self.__tabBar)
147 self.setMovable(True) 148 self.setMovable(True)
149 self.__tabBar = E5WheelTabBar(self) 150 self.__tabBar = E5WheelTabBar(self)
150 self.setTabBar(self.__tabBar) 151 self.setTabBar(self.__tabBar)
151 152
152 self.__lastCurrentIndex = -1 153 self.__lastCurrentIndex = -1
153 self.__currentIndex = -1 154 self.__currentIndex = -1
154 self.connect(self, SIGNAL("currentChanged(int)"), self.__currentChanged) 155 self.currentChanged.connect(self.__currentChanged)
155 156
156 def __currentChanged(self, index): 157 def __currentChanged(self, index):
157 """ 158 """
158 Private slot to handle the currentChanged signal. 159 Private slot to handle the currentChanged signal.
159 160

eric ide

mercurial