Helpviewer/HelpTabBar.py

changeset 6125
bb1c79bf4f33
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
diff -r 8467f7d4b567 -r bb1c79bf4f33 Helpviewer/HelpTabBar.py
--- a/Helpviewer/HelpTabBar.py	Fri Feb 09 18:53:08 2018 +0100
+++ b/Helpviewer/HelpTabBar.py	Fri Feb 09 18:58:21 2018 +0100
@@ -33,16 +33,17 @@
         self.__tabWidget = parent
         
         self.__previewPopup = None
-        self.__currentTabPreviewIndex = -1
         
         self.setMouseTracking(True)
     
-    def __showTabPreview(self):
+    def __showTabPreview(self, index):
         """
         Private slot to show the tab preview.
+        
+        @param index index of tab to show a preview for
+        @type int
         """
-        indexedBrowser = self.__tabWidget.browserAt(
-            self.__currentTabPreviewIndex)
+        indexedBrowser = self.__tabWidget.browserAt(index)
         currentBrowser = self.__tabWidget.currentBrowser()
         
         if indexedBrowser is None or currentBrowser is None:
@@ -52,13 +53,14 @@
         if indexedBrowser.progress() != 0:
             return
         
-        w = self.tabSizeHint(self.__currentTabPreviewIndex).width()
+        w = self.tabSizeHint(index).width()
         h = int(w * currentBrowser.height() / currentBrowser.width())
         
         self.__previewPopup = E5PassivePopup(self)
         self.__previewPopup.setFrameShape(QFrame.StyledPanel)
         self.__previewPopup.setFrameShadow(QFrame.Plain)
         self.__previewPopup.setFixedSize(w, h)
+        self.__previewPopup.setCustomData("index", index)
         
         from .HelpSnap import renderTabPreview
         label = QLabel()
@@ -68,11 +70,19 @@
         self.__previewPopup.layout().setAlignment(Qt.AlignTop)
         self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0)
         
-        tr = self.tabRect(self.__currentTabPreviewIndex)
+        tr = self.tabRect(index)
         pos = QPoint(tr.x(), tr.y() + tr.height())
         
         self.__previewPopup.show(self.mapToGlobal(pos))
     
+    def __hidePreview(self):
+        """
+        Private method to hide the preview.
+        """
+        if self.__previewPopup is not None:
+            self.__previewPopup.hide()
+        self.__previewPopup = None
+    
     def mouseMoveEvent(self, evt):
         """
         Protected method to handle mouse move events.
@@ -96,17 +106,17 @@
             # If found and not the current tab then show tab preview
             if tabIndex != -1 and \
                tabIndex != self.currentIndex() and \
-               self.__currentTabPreviewIndex != tabIndex and \
                evt.buttons() == Qt.NoButton:
-                self.__currentTabPreviewIndex = tabIndex
-                QTimer.singleShot(200, self.__showTabPreview)
+                if self.__previewPopup is None or \
+                    (self.__previewPopup is not None and
+                     self.__previewPopup.getCustomData("index") != tabIndex):
+                    QTimer.singleShot(
+                        0, lambda: self.__showTabPreview(tabIndex))
             
             # If current tab or not found then hide previous tab preview
             if tabIndex == self.currentIndex() or \
                tabIndex == -1:
-                if self.__previewPopup is not None:
-                    self.__previewPopup.hide()
-                self.__currentTabPreviewIndex = -1
+                self.__hidePreview()
     
     def leaveEvent(self, evt):
         """
@@ -116,9 +126,7 @@
         """
         if Preferences.getHelp("ShowPreview"):
             # If leave tabwidget then hide previous tab preview
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()
         
         E5WheelTabBar.leaveEvent(self, evt)
     
@@ -129,9 +137,7 @@
         @param evt reference to the mouse press event (QMouseEvent)
         """
         if Preferences.getHelp("ShowPreview"):
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()
         
         E5WheelTabBar.mousePressEvent(self, evt)
     
@@ -160,6 +166,4 @@
         @param index index of the removed tab (integer)
         """
         if Preferences.getHelp("ShowPreview"):
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()

eric ide

mercurial