24 |
24 |
25 class ImagesIcon(StatusBarIcon): |
25 class ImagesIcon(StatusBarIcon): |
26 """ |
26 """ |
27 Class implementing the images loading status bar icon. |
27 Class implementing the images loading status bar icon. |
28 """ |
28 """ |
|
29 |
29 def __init__(self, window): |
30 def __init__(self, window): |
30 """ |
31 """ |
31 Constructor |
32 Constructor |
32 |
33 |
33 @param window reference to the web browser window |
34 @param window reference to the web browser window |
34 @type WebBrowserWindow |
35 @type WebBrowserWindow |
35 """ |
36 """ |
36 super().__init__(window) |
37 super().__init__(window) |
37 |
38 |
38 self.setToolTip(self.tr("Modify images loading settings temporarily" |
39 self.setToolTip( |
39 " or globally")) |
40 self.tr("Modify images loading settings temporarily" " or globally") |
|
41 ) |
40 self.__icon = UI.PixmapCache.getPixmap("filePixmap").scaled(16, 16) |
42 self.__icon = UI.PixmapCache.getPixmap("filePixmap").scaled(16, 16) |
41 self.setPixmap(self.__icon) |
43 self.setPixmap(self.__icon) |
42 |
44 |
43 self._window.tabWidget().currentChanged.connect(self.__updateIcon) |
45 self._window.tabWidget().currentChanged.connect(self.__updateIcon) |
44 self.clicked.connect(self.__showMenu) |
46 self.clicked.connect(self.__showMenu) |
45 |
47 |
46 self.__updateIcon() |
48 self.__updateIcon() |
47 |
49 |
48 def preferencesChanged(self): |
50 def preferencesChanged(self): |
49 """ |
51 """ |
50 Public method to handle changes of the settings. |
52 Public method to handle changes of the settings. |
51 """ |
53 """ |
52 self.__updateIcon() |
54 self.__updateIcon() |
53 |
55 |
54 @pyqtSlot(QPoint) |
56 @pyqtSlot(QPoint) |
55 def __showMenu(self, pos): |
57 def __showMenu(self, pos): |
56 """ |
58 """ |
57 Private slot to show the menu. |
59 Private slot to show the menu. |
58 |
60 |
59 @param pos position to show the menu at |
61 @param pos position to show the menu at |
60 @type QPoint |
62 @type QPoint |
61 """ |
63 """ |
62 boldFont = self.font() |
64 boldFont = self.font() |
63 boldFont.setBold(True) |
65 boldFont.setBold(True) |
64 |
66 |
65 menu = QMenu() |
67 menu = QMenu() |
66 menu.addAction(self.tr("Current Page Settings")).setFont(boldFont) |
68 menu.addAction(self.tr("Current Page Settings")).setFont(boldFont) |
67 |
69 |
68 if self._testCurrentPageWebAttribute( |
70 if self._testCurrentPageWebAttribute( |
69 QWebEngineSettings.WebAttribute.AutoLoadImages): |
71 QWebEngineSettings.WebAttribute.AutoLoadImages |
70 menu.addAction(self.tr("Disable loading images (temporarily)"), |
72 ): |
71 self.__toggleLoadingImages) |
73 menu.addAction( |
|
74 self.tr("Disable loading images (temporarily)"), |
|
75 self.__toggleLoadingImages, |
|
76 ) |
72 else: |
77 else: |
73 menu.addAction(self.tr("Enable loading images (temporarily)"), |
78 menu.addAction( |
74 self.__toggleLoadingImages) |
79 self.tr("Enable loading images (temporarily)"), |
75 |
80 self.__toggleLoadingImages, |
|
81 ) |
|
82 |
76 menu.addSeparator() |
83 menu.addSeparator() |
77 menu.addAction(self.tr("Global Settings")).setFont(boldFont) |
84 menu.addAction(self.tr("Global Settings")).setFont(boldFont) |
78 act = menu.addAction(self.tr("Automatically load images")) |
85 act = menu.addAction(self.tr("Automatically load images")) |
79 act.setCheckable(True) |
86 act.setCheckable(True) |
80 act.setChecked(Preferences.getWebBrowser("AutoLoadImages")) |
87 act.setChecked(Preferences.getWebBrowser("AutoLoadImages")) |
81 act.toggled.connect(self.__setGlobalLoadingImages) |
88 act.toggled.connect(self.__setGlobalLoadingImages) |
82 |
89 |
83 menu.exec(pos) |
90 menu.exec(pos) |
84 |
91 |
85 @pyqtSlot() |
92 @pyqtSlot() |
86 def __updateIcon(self): |
93 def __updateIcon(self): |
87 """ |
94 """ |
88 Private slot to update the icon. |
95 Private slot to update the icon. |
89 """ |
96 """ |
90 if self._testCurrentPageWebAttribute( |
97 if self._testCurrentPageWebAttribute( |
91 QWebEngineSettings.WebAttribute.AutoLoadImages): |
98 QWebEngineSettings.WebAttribute.AutoLoadImages |
|
99 ): |
92 self.setGraphicsEffect(None) |
100 self.setGraphicsEffect(None) |
93 else: |
101 else: |
94 effect = QGraphicsColorizeEffect(self) |
102 effect = QGraphicsColorizeEffect(self) |
95 effect.setColor(Qt.GlobalColor.gray) |
103 effect.setColor(Qt.GlobalColor.gray) |
96 self.setGraphicsEffect(effect) |
104 self.setGraphicsEffect(effect) |
97 |
105 |
98 @pyqtSlot() |
106 @pyqtSlot() |
99 def __toggleLoadingImages(self): |
107 def __toggleLoadingImages(self): |
100 """ |
108 """ |
101 Private slot to toggle the images loading setting. |
109 Private slot to toggle the images loading setting. |
102 """ |
110 """ |
103 if self._currentPage() is None: |
111 if self._currentPage() is None: |
104 return |
112 return |
105 |
113 |
106 current = self._testCurrentPageWebAttribute( |
114 current = self._testCurrentPageWebAttribute( |
107 QWebEngineSettings.WebAttribute.AutoLoadImages) |
115 QWebEngineSettings.WebAttribute.AutoLoadImages |
|
116 ) |
108 self._setCurrentPageWebAttribute( |
117 self._setCurrentPageWebAttribute( |
109 QWebEngineSettings.WebAttribute.AutoLoadImages, not current) |
118 QWebEngineSettings.WebAttribute.AutoLoadImages, not current |
110 |
119 ) |
|
120 |
111 if current: |
121 if current: |
112 # reload page upon disabling loading images |
122 # reload page upon disabling loading images |
113 self._window.currentBrowser().reload() |
123 self._window.currentBrowser().reload() |
114 |
124 |
115 self.__updateIcon() |
125 self.__updateIcon() |
116 |
126 |
117 @pyqtSlot(bool) |
127 @pyqtSlot(bool) |
118 def __setGlobalLoadingImages(self, enable): |
128 def __setGlobalLoadingImages(self, enable): |
119 """ |
129 """ |
120 Private slot to toggle the global images loading setting. |
130 Private slot to toggle the global images loading setting. |
121 |
131 |
122 @param enable flag indicating the state to set |
132 @param enable flag indicating the state to set |
123 @type bool |
133 @type bool |
124 """ |
134 """ |
125 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
135 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
136 |
126 WebBrowserWindow.webSettings().setAttribute( |
137 WebBrowserWindow.webSettings().setAttribute( |
127 QWebEngineSettings.WebAttribute.AutoLoadImages, enable) |
138 QWebEngineSettings.WebAttribute.AutoLoadImages, enable |
|
139 ) |
128 Preferences.setWebBrowser("AutoLoadImages", enable) |
140 Preferences.setWebBrowser("AutoLoadImages", enable) |
129 |
141 |
130 Preferences.syncPreferences() |
142 Preferences.syncPreferences() |
131 self._window.preferencesChanged() |
143 self._window.preferencesChanged() |
132 |
144 |
133 self.__updateIcon() |
145 self.__updateIcon() |
134 |
146 |
135 if not enable: |
147 if not enable: |
136 # reload page upon disabling loading images |
148 # reload page upon disabling loading images |
137 self._window.currentBrowser().reload() |
149 self._window.currentBrowser().reload() |