Helpviewer/HelpTabBar.py

changeset 6125
bb1c79bf4f33
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
equal deleted inserted replaced
6124:8467f7d4b567 6125:bb1c79bf4f33
31 E5WheelTabBar.__init__(self, parent) 31 E5WheelTabBar.__init__(self, parent)
32 32
33 self.__tabWidget = parent 33 self.__tabWidget = parent
34 34
35 self.__previewPopup = None 35 self.__previewPopup = None
36 self.__currentTabPreviewIndex = -1
37 36
38 self.setMouseTracking(True) 37 self.setMouseTracking(True)
39 38
40 def __showTabPreview(self): 39 def __showTabPreview(self, index):
41 """ 40 """
42 Private slot to show the tab preview. 41 Private slot to show the tab preview.
42
43 @param index index of tab to show a preview for
44 @type int
43 """ 45 """
44 indexedBrowser = self.__tabWidget.browserAt( 46 indexedBrowser = self.__tabWidget.browserAt(index)
45 self.__currentTabPreviewIndex)
46 currentBrowser = self.__tabWidget.currentBrowser() 47 currentBrowser = self.__tabWidget.currentBrowser()
47 48
48 if indexedBrowser is None or currentBrowser is None: 49 if indexedBrowser is None or currentBrowser is None:
49 return 50 return
50 51
51 # no previews during load 52 # no previews during load
52 if indexedBrowser.progress() != 0: 53 if indexedBrowser.progress() != 0:
53 return 54 return
54 55
55 w = self.tabSizeHint(self.__currentTabPreviewIndex).width() 56 w = self.tabSizeHint(index).width()
56 h = int(w * currentBrowser.height() / currentBrowser.width()) 57 h = int(w * currentBrowser.height() / currentBrowser.width())
57 58
58 self.__previewPopup = E5PassivePopup(self) 59 self.__previewPopup = E5PassivePopup(self)
59 self.__previewPopup.setFrameShape(QFrame.StyledPanel) 60 self.__previewPopup.setFrameShape(QFrame.StyledPanel)
60 self.__previewPopup.setFrameShadow(QFrame.Plain) 61 self.__previewPopup.setFrameShadow(QFrame.Plain)
61 self.__previewPopup.setFixedSize(w, h) 62 self.__previewPopup.setFixedSize(w, h)
63 self.__previewPopup.setCustomData("index", index)
62 64
63 from .HelpSnap import renderTabPreview 65 from .HelpSnap import renderTabPreview
64 label = QLabel() 66 label = QLabel()
65 label.setPixmap(renderTabPreview(indexedBrowser.page(), w, h)) 67 label.setPixmap(renderTabPreview(indexedBrowser.page(), w, h))
66 68
67 self.__previewPopup.setView(label) 69 self.__previewPopup.setView(label)
68 self.__previewPopup.layout().setAlignment(Qt.AlignTop) 70 self.__previewPopup.layout().setAlignment(Qt.AlignTop)
69 self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0) 71 self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0)
70 72
71 tr = self.tabRect(self.__currentTabPreviewIndex) 73 tr = self.tabRect(index)
72 pos = QPoint(tr.x(), tr.y() + tr.height()) 74 pos = QPoint(tr.x(), tr.y() + tr.height())
73 75
74 self.__previewPopup.show(self.mapToGlobal(pos)) 76 self.__previewPopup.show(self.mapToGlobal(pos))
77
78 def __hidePreview(self):
79 """
80 Private method to hide the preview.
81 """
82 if self.__previewPopup is not None:
83 self.__previewPopup.hide()
84 self.__previewPopup = None
75 85
76 def mouseMoveEvent(self, evt): 86 def mouseMoveEvent(self, evt):
77 """ 87 """
78 Protected method to handle mouse move events. 88 Protected method to handle mouse move events.
79 89
94 i += 1 104 i += 1
95 105
96 # If found and not the current tab then show tab preview 106 # If found and not the current tab then show tab preview
97 if tabIndex != -1 and \ 107 if tabIndex != -1 and \
98 tabIndex != self.currentIndex() and \ 108 tabIndex != self.currentIndex() and \
99 self.__currentTabPreviewIndex != tabIndex and \
100 evt.buttons() == Qt.NoButton: 109 evt.buttons() == Qt.NoButton:
101 self.__currentTabPreviewIndex = tabIndex 110 if self.__previewPopup is None or \
102 QTimer.singleShot(200, self.__showTabPreview) 111 (self.__previewPopup is not None and
112 self.__previewPopup.getCustomData("index") != tabIndex):
113 QTimer.singleShot(
114 0, lambda: self.__showTabPreview(tabIndex))
103 115
104 # If current tab or not found then hide previous tab preview 116 # If current tab or not found then hide previous tab preview
105 if tabIndex == self.currentIndex() or \ 117 if tabIndex == self.currentIndex() or \
106 tabIndex == -1: 118 tabIndex == -1:
107 if self.__previewPopup is not None: 119 self.__hidePreview()
108 self.__previewPopup.hide()
109 self.__currentTabPreviewIndex = -1
110 120
111 def leaveEvent(self, evt): 121 def leaveEvent(self, evt):
112 """ 122 """
113 Protected method to handle leave events. 123 Protected method to handle leave events.
114 124
115 @param evt reference to the leave event (QEvent) 125 @param evt reference to the leave event (QEvent)
116 """ 126 """
117 if Preferences.getHelp("ShowPreview"): 127 if Preferences.getHelp("ShowPreview"):
118 # If leave tabwidget then hide previous tab preview 128 # If leave tabwidget then hide previous tab preview
119 if self.__previewPopup is not None: 129 self.__hidePreview()
120 self.__previewPopup.hide()
121 self.__currentTabPreviewIndex = -1
122 130
123 E5WheelTabBar.leaveEvent(self, evt) 131 E5WheelTabBar.leaveEvent(self, evt)
124 132
125 def mousePressEvent(self, evt): 133 def mousePressEvent(self, evt):
126 """ 134 """
127 Protected method to handle mouse press events. 135 Protected method to handle mouse press events.
128 136
129 @param evt reference to the mouse press event (QMouseEvent) 137 @param evt reference to the mouse press event (QMouseEvent)
130 """ 138 """
131 if Preferences.getHelp("ShowPreview"): 139 if Preferences.getHelp("ShowPreview"):
132 if self.__previewPopup is not None: 140 self.__hidePreview()
133 self.__previewPopup.hide()
134 self.__currentTabPreviewIndex = -1
135 141
136 E5WheelTabBar.mousePressEvent(self, evt) 142 E5WheelTabBar.mousePressEvent(self, evt)
137 143
138 def event(self, evt): 144 def event(self, evt):
139 """ 145 """
158 Public slot to handle the removal of a tab. 164 Public slot to handle the removal of a tab.
159 165
160 @param index index of the removed tab (integer) 166 @param index index of the removed tab (integer)
161 """ 167 """
162 if Preferences.getHelp("ShowPreview"): 168 if Preferences.getHelp("ShowPreview"):
163 if self.__previewPopup is not None: 169 self.__hidePreview()
164 self.__previewPopup.hide()
165 self.__currentTabPreviewIndex = -1

eric ide

mercurial