WebBrowser/WebBrowserTabBar.py

changeset 6125
bb1c79bf4f33
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
--- a/WebBrowser/WebBrowserTabBar.py	Fri Feb 09 18:53:08 2018 +0100
+++ b/WebBrowser/WebBrowserTabBar.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:
@@ -54,13 +55,14 @@
         
         preview = indexedBrowser.getPreview()
         if not preview.isNull():
-            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)
             
             label = QLabel()
             label.setPixmap(preview.scaled(w, h))
@@ -69,11 +71,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.
@@ -97,17 +107,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):
         """
@@ -117,9 +127,7 @@
         """
         if Preferences.getWebBrowser("ShowPreview"):
             # If leave tabwidget then hide previous tab preview
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()
         
         super(WebBrowserTabBar, self).leaveEvent(evt)
     
@@ -130,9 +138,7 @@
         @param evt reference to the mouse press event (QMouseEvent)
         """
         if Preferences.getWebBrowser("ShowPreview"):
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()
         
         super(WebBrowserTabBar, self).mousePressEvent(evt)
     
@@ -161,6 +167,4 @@
         @param index index of the removed tab (integer)
         """
         if Preferences.getWebBrowser("ShowPreview"):
-            if self.__previewPopup is not None:
-                self.__previewPopup.hide()
-            self.__currentTabPreviewIndex = -1
+            self.__hidePreview()

eric ide

mercurial