Continued porting the web browser. QtWebEngine

Mon, 28 Mar 2016 13:48:33 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 28 Mar 2016 13:48:33 +0200
branch
QtWebEngine
changeset 4900
32f940762654
parent 4895
3baaf8303a7f
child 4901
38393e4d0ca3

Continued porting the web browser.

- fixed the preview page code

WebBrowser/WebBrowserTabBar.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
--- a/WebBrowser/WebBrowserTabBar.py	Mon Mar 28 11:59:42 2016 +0200
+++ b/WebBrowser/WebBrowserTabBar.py	Mon Mar 28 13:48:33 2016 +0200
@@ -60,9 +60,8 @@
         self.__previewPopup.setFrameShadow(QFrame.Plain)
         self.__previewPopup.setFixedSize(w, h)
         
-        from .WebBrowserSnap import renderTabPreview
         label = QLabel()
-        label.setPixmap(renderTabPreview(indexedBrowser, w, h))
+        label.setPixmap(indexedBrowser.getPreview().scaled(w, h))
         
         self.__previewPopup.setView(label)
         self.__previewPopup.layout().setAlignment(Qt.AlignTop)
--- a/WebBrowser/WebBrowserView.py	Mon Mar 28 11:59:42 2016 +0200
+++ b/WebBrowser/WebBrowserView.py	Mon Mar 28 13:48:33 2016 +0200
@@ -18,7 +18,7 @@
     QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \
     QRect, QFile, QPoint, QByteArray, qVersion
 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \
-    QPalette, QIcon, QContextMenuEvent
+    QPalette, QIcon, QContextMenuEvent, QPixmap
 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \
     QLineEdit, QLabel, QToolTip, QFrame, QDialog
 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
@@ -39,13 +39,13 @@
 
 import Preferences
 import UI.PixmapCache
-import Globals
+##import Globals
 
-try:
-    from PyQt5.QtNetwork import QSslCertificate
-    SSL_AVAILABLE = True
-except ImportError:
-    SSL_AVAILABLE = False
+##try:
+##    from PyQt5.QtNetwork import QSslCertificate
+##    SSL_AVAILABLE = True
+##except ImportError:
+##    SSL_AVAILABLE = False
 
 
 class WebBrowserView(QWebEngineView):
@@ -104,6 +104,7 @@
         self.__menu = QMenu(self)
         self.__clickedPos = QPoint()
         self.__firstLoad = False
+        self.__preview = QPixmap()
         
         self.__currentZoom = 100
         self.__zoomLevels = WebBrowserView.ZoomLevels[:]
@@ -119,6 +120,8 @@
         self.loadStarted.connect(self.__loadStarted)
         self.loadProgress.connect(self.__loadProgress)
         self.loadFinished.connect(self.__loadFinished)
+        # TODO: renderProcessTerminated
+##        self.page().renderProcessTerminated.connect(self.__renderProcessTerminated)
         
 ##        self.page().setForwardUnsupportedContent(True)
 ##        self.page().unsupportedContent.connect(self.__unsupportedContent)
@@ -1497,6 +1500,10 @@
     ## Signal handlers below
     ###########################################################################
     
+    # TODO: renderProcessTerminated
+##    def __renderProcessTerminated(self, status, exitCode):
+##        print(status, exitCode)
+##    
     def __loadStarted(self):
         """
         Private method to handle the loadStarted signal.
@@ -1521,6 +1528,8 @@
         self.__isLoading = False
         self.__progress = 0
         
+        QTimer.singleShot(200, self.__renderPreview)
+        
         # TODO: ClickToFlash (?)
 ##        if Preferences.getWebBrowser("ClickToFlashEnabled"):
 ##            # this is a hack to make the ClickToFlash button appear
@@ -1553,6 +1562,24 @@
         """
         return self.__progress
     
+    def __renderPreview(self):
+        """
+        Private slot to render a preview pixmap after the page was loaded.
+        """
+        from .WebBrowserSnap import renderTabPreview
+        w = 600     # some default width, the preview gets scaled when shown
+        h = int(w * self.height() / self.width())
+        self.__preview = renderTabPreview(self, w, h)
+    
+    def getPreview(self):
+        """
+        Public method to get the preview pixmap.
+        
+        @return preview pixmap
+        @rtype QPixmap
+        """
+        return self.__preview
+    
 ##    def saveAs(self):
 ##        """
 ##        Public method to save the current page to a file.

eric ide

mercurial