Sat, 27 Feb 2016 13:10:03 +0100
Continued porting the web browser.
- ported the page preview stuff
--- a/Preferences/__init__.py Sat Feb 27 12:52:47 2016 +0100 +++ b/Preferences/__init__.py Sat Feb 27 13:10:03 2016 +0100 @@ -1026,6 +1026,7 @@ # search engine name) "SearchLanguage": QLocale().language(), "RssFeeds": [], + "ShowPreview": True, # Grease Monkey "GreaseMonkeyDisabledScripts": [], # Downloads @@ -2765,7 +2766,7 @@ ## "PluginsEnabled", "DnsPrefetchEnabled", ## "OfflineStorageDatabaseEnabled", ## "OfflineWebApplicationCacheEnabled", "LocalStorageEnabled", -## "ShowPreview", "AccessKeysEnabled", +## "AccessKeysEnabled", ## "DoNotTrack", "SendReferer", ## "SiteSpecificQuirksEnabled", ## "ClickToFlashEnabled", @@ -2781,6 +2782,7 @@ "SyncEnabled", "SyncBookmarks", "SyncHistory", "SyncPasswords", "SyncUserAgents", "SyncSpeedDial", "SyncEncryptData", "SyncEncryptPasswordsOnly", + "ShowPreview", ]: return toBool(prefClass.settings.value( "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebBrowser/WebBrowserSnap.py Sat Feb 27 13:10:03 2016 +0100 @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2010 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing functions to generate page previews. +""" + +from __future__ import unicode_literals + +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QPixmap, QPainter + + +def renderTabPreview(view, w, h): + """ + Public function to render a pixmap of a page. + + @param view reference to the view to be previewed (QWebEngineView) + @param w width of the preview pixmap (integer) + @param h height of the preview pixmap (integer) + @return preview pixmap (QPixmap) + """ + pageImage = __render(view, view.width(), view.height()) + return pageImage.scaled( + w, h, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) + + +def __render(view, w, h): + """ + Private function to render a pixmap of given size for a web page. + + @param view reference to the view to be previewed (QWebEngineView) + @param w width of the pixmap (integer) + @param h height of the pixmap (integer) + @return rendered pixmap (QPixmap) + """ + # create the page image + pageImage = QPixmap(w, h) + pageImage.fill(Qt.transparent) + + # render it + p = QPainter(pageImage) + view.render(p) + p.end() + + return pageImage
--- a/WebBrowser/WebBrowserTabBar.py Sat Feb 27 12:52:47 2016 +0100 +++ b/WebBrowser/WebBrowserTabBar.py Sat Feb 27 13:10:03 2016 +0100 @@ -37,42 +37,41 @@ self.setMouseTracking(True) - # TODO: page preview -## def __showTabPreview(self): -## """ -## Private slot to show the tab preview. -## """ -## indexedBrowser = self.__tabWidget.browserAt( -## self.__currentTabPreviewIndex) -## currentBrowser = self.__tabWidget.currentBrowser() -## -## if indexedBrowser is None or currentBrowser is None: -## return -## -## # no previews during load -## if indexedBrowser.progress() != 0: -## return -## -## w = self.tabSizeHint(self.__currentTabPreviewIndex).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) -## -## from .HelpSnap import renderTabPreview -## label = QLabel() -## label.setPixmap(renderTabPreview(indexedBrowser.page(), w, h)) -## -## self.__previewPopup.setView(label) -## self.__previewPopup.layout().setAlignment(Qt.AlignTop) -## self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0) -## -## tr = self.tabRect(self.__currentTabPreviewIndex) -## pos = QPoint(tr.x(), tr.y() + tr.height()) -## -## self.__previewPopup.show(self.mapToGlobal(pos)) + def __showTabPreview(self): + """ + Private slot to show the tab preview. + """ + indexedBrowser = self.__tabWidget.browserAt( + self.__currentTabPreviewIndex) + currentBrowser = self.__tabWidget.currentBrowser() + + if indexedBrowser is None or currentBrowser is None: + return + + # no previews during load + if indexedBrowser.progress() != 0: + return + + w = self.tabSizeHint(self.__currentTabPreviewIndex).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) + + from .WebBrowserSnap import renderTabPreview + label = QLabel() + label.setPixmap(renderTabPreview(indexedBrowser, w, h)) + + self.__previewPopup.setView(label) + self.__previewPopup.layout().setAlignment(Qt.AlignTop) + self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0) + + tr = self.tabRect(self.__currentTabPreviewIndex) + pos = QPoint(tr.x(), tr.y() + tr.height()) + + self.__previewPopup.show(self.mapToGlobal(pos)) def mouseMoveEvent(self, evt): """ @@ -85,30 +84,29 @@ super(WebBrowserTabBar, self).mouseMoveEvent(evt) - # TODO: page preview -## if Preferences.getWebBrowser("ShowPreview"): -## # Find the tab under the mouse -## i = 0 -## tabIndex = -1 -## while i < self.count() and tabIndex == -1: -## if self.tabRect(i).contains(evt.pos()): -## tabIndex = i -## i += 1 -## -## # 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 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 + if Preferences.getWebBrowser("ShowPreview"): + # Find the tab under the mouse + i = 0 + tabIndex = -1 + while i < self.count() and tabIndex == -1: + if self.tabRect(i).contains(evt.pos()): + tabIndex = i + i += 1 + + # 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 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 def leaveEvent(self, evt): """ @@ -116,12 +114,11 @@ @param evt reference to the leave event (QEvent) """ - # TODO: page preview -## if Preferences.getWebBrowser("ShowPreview"): -## # If leave tabwidget then hide previous tab preview -## if self.__previewPopup is not None: -## self.__previewPopup.hide() -## self.__currentTabPreviewIndex = -1 + if Preferences.getWebBrowser("ShowPreview"): + # If leave tabwidget then hide previous tab preview + if self.__previewPopup is not None: + self.__previewPopup.hide() + self.__currentTabPreviewIndex = -1 super(WebBrowserTabBar, self).leaveEvent(evt) @@ -131,11 +128,10 @@ @param evt reference to the mouse press event (QMouseEvent) """ - # TODO: page preview -## if Preferences.getWebBrowser("ShowPreview"): -## if self.__previewPopup is not None: -## self.__previewPopup.hide() -## self.__currentTabPreviewIndex = -1 + if Preferences.getWebBrowser("ShowPreview"): + if self.__previewPopup is not None: + self.__previewPopup.hide() + self.__currentTabPreviewIndex = -1 super(WebBrowserTabBar, self).mousePressEvent(evt) @@ -149,12 +145,11 @@ @param evt reference to the event to be handled (QEvent) @return flag indicating, if the event was handled (boolean) """ - # TODO: page preview -## if evt.type() == QEvent.ToolTip and \ -## Preferences.getWebBrowser("ShowPreview"): -## # suppress tool tips if we are showing previews -## evt.setAccepted(True) -## return True + if evt.type() == QEvent.ToolTip and \ + Preferences.getWebBrowser("ShowPreview"): + # suppress tool tips if we are showing previews + evt.setAccepted(True) + return True return super(WebBrowserTabBar, self).event(evt) @@ -164,9 +159,7 @@ @param index index of the removed tab (integer) """ - pass - # TODO: page preview -## if Preferences.getWebBrowser("ShowPreview"): -## if self.__previewPopup is not None: -## self.__previewPopup.hide() -## self.__currentTabPreviewIndex = -1 + if Preferences.getWebBrowser("ShowPreview"): + if self.__previewPopup is not None: + self.__previewPopup.hide() + self.__currentTabPreviewIndex = -1
--- a/eric6.e4p Sat Feb 27 12:52:47 2016 +0100 +++ b/eric6.e4p Sat Feb 27 13:10:03 2016 +0100 @@ -1394,6 +1394,7 @@ <Source>WebBrowser/WebBrowserClearPrivateDataDialog.py</Source> <Source>WebBrowser/WebBrowserLanguagesDialog.py</Source> <Source>WebBrowser/WebBrowserPage.py</Source> + <Source>WebBrowser/WebBrowserSnap.py</Source> <Source>WebBrowser/WebBrowserTabBar.py</Source> <Source>WebBrowser/WebBrowserTabWidget.py</Source> <Source>WebBrowser/WebBrowserView.py</Source>