8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, QUrl, Qt |
12 from PyQt5.QtCore import pyqtSlot, QUrl, Qt |
13 from PyQt5.QtGui import QPixmap, QImage |
13 from PyQt5.QtGui import QPixmap, QImage, QPainter, QColor, QBrush |
14 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply |
14 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply |
15 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, \ |
15 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QGraphicsScene, QMenu, \ |
16 QApplication, QGraphicsPixmapItem |
16 QApplication, QGraphicsPixmapItem |
17 |
17 |
18 from E5Gui import E5MessageBox, E5FileDialog |
18 from E5Gui import E5MessageBox, E5FileDialog |
50 |
50 |
51 self.__imageReply = None |
51 self.__imageReply = None |
52 |
52 |
53 self.__baseUrl = browser.url() |
53 self.__baseUrl = browser.url() |
54 title = browser.title() |
54 title = browser.title() |
|
55 |
|
56 #prepare background of image preview |
|
57 self.__imagePreviewStandardBackground = \ |
|
58 self.imagePreview.backgroundBrush() |
|
59 color1 = QColor(220, 220, 220) |
|
60 color2 = QColor(160, 160, 160) |
|
61 self.__tilePixmap = QPixmap(8, 8) |
|
62 self.__tilePixmap.fill(color1) |
|
63 tilePainter = QPainter(self.__tilePixmap) |
|
64 tilePainter.fillRect(0, 0, 4, 4, color2) |
|
65 tilePainter.fillRect(4, 4, 4, 4, color2) |
|
66 tilePainter.end() |
55 |
67 |
56 # populate General tab |
68 # populate General tab |
57 self.heading.setText("<b>{0}</b>".format(title)) |
69 self.heading.setText("<b>{0}</b>".format(title)) |
58 self.siteAddressLabel.setText(self.__baseUrl.toString()) |
70 self.siteAddressLabel.setText(self.__baseUrl.toString()) |
59 if self.__baseUrl.scheme() in ["https"]: |
71 if self.__baseUrl.scheme() in ["https"]: |
137 Private slot to show a preview of the selected image. |
149 Private slot to show a preview of the selected image. |
138 |
150 |
139 @param current current image entry (QTreeWidgetItem) |
151 @param current current image entry (QTreeWidgetItem) |
140 @param previous old current entry (QTreeWidgetItem) |
152 @param previous old current entry (QTreeWidgetItem) |
141 """ |
153 """ |
142 # TODO: improve display of SVG files when the main color is identical |
|
143 # to the background |
|
144 if current is None: |
154 if current is None: |
145 return |
155 return |
146 |
156 |
147 imageUrl = QUrl(current.text(1)) |
157 imageUrl = QUrl(current.text(1)) |
148 if imageUrl.isRelative(): |
158 if imageUrl.isRelative(): |
151 pixmap = QPixmap() |
161 pixmap = QPixmap() |
152 loading = False |
162 loading = False |
153 |
163 |
154 if imageUrl.scheme() == "data": |
164 if imageUrl.scheme() == "data": |
155 encodedUrl = current.text(1).encode("utf-8") |
165 encodedUrl = current.text(1).encode("utf-8") |
156 imageData = encodedUrl[encodedUrl.find(",") + 1:] |
166 imageData = encodedUrl[encodedUrl.find(b",") + 1:] |
157 pixmap = WebBrowserTools.pixmapFromByteArray(imageData) |
167 pixmap = WebBrowserTools.pixmapFromByteArray(imageData) |
158 elif imageUrl.scheme() == "file": |
168 elif imageUrl.scheme() == "file": |
159 pixmap = QPixmap(imageUrl.toLocalFile()) |
169 pixmap = QPixmap(imageUrl.toLocalFile()) |
160 elif imageUrl.scheme() == "qrc": |
170 elif imageUrl.scheme() == "qrc": |
161 pixmap = QPixmap(imageUrl.toString()[3:]) |
171 pixmap = QPixmap(imageUrl.toString()[3:]) |
192 @param pixmap pixmap to be shown |
202 @param pixmap pixmap to be shown |
193 @type QPixmap |
203 @type QPixmap |
194 """ |
204 """ |
195 scene = QGraphicsScene(self.imagePreview) |
205 scene = QGraphicsScene(self.imagePreview) |
196 if pixmap.isNull(): |
206 if pixmap.isNull(): |
|
207 self.imagePreview.setBackgroundBrush( |
|
208 self.__imagePreviewStandardBackground) |
197 scene.addText(self.tr("Preview not available.")) |
209 scene.addText(self.tr("Preview not available.")) |
198 else: |
210 else: |
|
211 self.imagePreview.setBackgroundBrush(QBrush(self.__tilePixmap)) |
199 scene.addPixmap(pixmap) |
212 scene.addPixmap(pixmap) |
200 self.imagePreview.setScene(scene) |
213 self.imagePreview.setScene(scene) |
201 |
214 |
202 def __showLoadingText(self): |
215 def __showLoadingText(self): |
203 """ |
216 """ |
204 Private method to show some text while loading an image. |
217 Private method to show some text while loading an image. |
205 """ |
218 """ |
|
219 self.imagePreview.setBackgroundBrush( |
|
220 self.__imagePreviewStandardBackground) |
206 scene = QGraphicsScene(self.imagePreview) |
221 scene = QGraphicsScene(self.imagePreview) |
207 scene.addText(self.tr("Loading...")) |
222 scene.addText(self.tr("Loading...")) |
208 self.imagePreview.setScene(scene) |
223 self.imagePreview.setScene(scene) |
209 |
224 |
210 def __imagesTreeContextMenuRequested(self, pos): |
225 def __imagesTreeContextMenuRequested(self, pos): |