WebBrowser/SiteInfo/SiteInfoDialog.py

changeset 4941
b0e4e7a65872
parent 4939
98ef487d00eb
child 5001
08eaee907686
diff -r 070b8f12b60d -r b0e4e7a65872 WebBrowser/SiteInfo/SiteInfoDialog.py
--- a/WebBrowser/SiteInfo/SiteInfoDialog.py	Thu Apr 14 18:55:31 2016 +0200
+++ b/WebBrowser/SiteInfo/SiteInfoDialog.py	Thu Apr 14 19:54:12 2016 +0200
@@ -10,7 +10,7 @@
 from __future__ import unicode_literals
 
 from PyQt5.QtCore import pyqtSlot, QUrl, Qt
-from PyQt5.QtGui import QPixmap, QImage
+from PyQt5.QtGui import QPixmap, QImage, QPainter, QColor, QBrush
 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, \
     QApplication, QGraphicsPixmapItem
@@ -53,6 +53,18 @@
         self.__baseUrl = browser.url()
         title = browser.title()
         
+        #prepare background of image preview
+        self.__imagePreviewStandardBackground = \
+            self.imagePreview.backgroundBrush()
+        color1 = QColor(220, 220, 220)
+        color2 = QColor(160, 160, 160)
+        self.__tilePixmap = QPixmap(8, 8)
+        self.__tilePixmap.fill(color1)
+        tilePainter = QPainter(self.__tilePixmap)
+        tilePainter.fillRect(0, 0, 4, 4, color2)
+        tilePainter.fillRect(4, 4, 4, 4, color2)
+        tilePainter.end()
+        
         # populate General tab
         self.heading.setText("<b>{0}</b>".format(title))
         self.siteAddressLabel.setText(self.__baseUrl.toString())
@@ -139,8 +151,6 @@
         @param current current image entry (QTreeWidgetItem)
         @param previous old current entry (QTreeWidgetItem)
         """
-        # TODO: improve display of SVG files when the main color is identical
-        #       to the background
         if current is None:
             return
         
@@ -153,7 +163,7 @@
         
         if imageUrl.scheme() == "data":
             encodedUrl = current.text(1).encode("utf-8")
-            imageData = encodedUrl[encodedUrl.find(",") + 1:]
+            imageData = encodedUrl[encodedUrl.find(b",") + 1:]
             pixmap = WebBrowserTools.pixmapFromByteArray(imageData)
         elif imageUrl.scheme() == "file":
             pixmap = QPixmap(imageUrl.toLocalFile())
@@ -194,8 +204,11 @@
         """
         scene = QGraphicsScene(self.imagePreview)
         if pixmap.isNull():
+            self.imagePreview.setBackgroundBrush(
+                self.__imagePreviewStandardBackground)
             scene.addText(self.tr("Preview not available."))
         else:
+            self.imagePreview.setBackgroundBrush(QBrush(self.__tilePixmap))
             scene.addPixmap(pixmap)
         self.imagePreview.setScene(scene)
     
@@ -203,6 +216,8 @@
         """
         Private method to show some text while loading an image.
         """
+        self.imagePreview.setBackgroundBrush(
+            self.__imagePreviewStandardBackground)
         scene = QGraphicsScene(self.imagePreview)
         scene.addText(self.tr("Loading..."))
         self.imagePreview.setScene(scene)

eric ide

mercurial