15 |
15 |
16 |
16 |
17 class OpenPagesWidget(QListWidget): |
17 class OpenPagesWidget(QListWidget): |
18 """ |
18 """ |
19 Class implementing a widget showing the list of open pages. |
19 Class implementing a widget showing the list of open pages. |
20 |
20 |
21 @signal currentPageChanged(index) emitted to signal a change of the current |
21 @signal currentPageChanged(index) emitted to signal a change of the current |
22 page index |
22 page index |
23 """ |
23 """ |
|
24 |
24 currentPageChanged = pyqtSignal(int) |
25 currentPageChanged = pyqtSignal(int) |
25 |
26 |
26 def __init__(self, stack, parent=None): |
27 def __init__(self, stack, parent=None): |
27 """ |
28 """ |
28 Constructor |
29 Constructor |
29 |
30 |
30 @param stack reference to the stack widget containing the open |
31 @param stack reference to the stack widget containing the open |
31 help pages |
32 help pages |
32 @type QStackedWidget |
33 @type QStackedWidget |
33 @param parent reference to the parent widget (defaults to None) |
34 @param parent reference to the parent widget (defaults to None) |
34 @type QWidget (optional) |
35 @type QWidget (optional) |
35 """ |
36 """ |
36 super().__init__(parent) |
37 super().__init__(parent) |
37 self.setObjectName("OpenPagesWidget") |
38 self.setObjectName("OpenPagesWidget") |
38 |
39 |
39 self.__helpViewer = parent |
40 self.__helpViewer = parent |
40 |
41 |
41 self.setAlternatingRowColors(True) |
42 self.setAlternatingRowColors(True) |
42 self.setSelectionMode( |
43 self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) |
43 QAbstractItemView.SelectionMode.SingleSelection) |
44 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
44 self.setContextMenuPolicy( |
45 self.currentRowChanged.connect(self.__currentRowChanged) |
45 Qt.ContextMenuPolicy.CustomContextMenu) |
46 self.customContextMenuRequested.connect(self.__showContextMenu) |
46 self.currentRowChanged.connect( |
47 |
47 self.__currentRowChanged) |
|
48 self.customContextMenuRequested.connect( |
|
49 self.__showContextMenu) |
|
50 |
|
51 self.__stack = stack |
48 self.__stack = stack |
52 self.__stack.currentChanged.connect(self.__currentPageChanged) |
49 self.__stack.currentChanged.connect(self.__currentPageChanged) |
53 |
50 |
54 self.__initContextMenu() |
51 self.__initContextMenu() |
55 |
52 |
56 self.__defaultFont = self.font() |
53 self.__defaultFont = self.font() |
57 self.__boldFont = self.font() |
54 self.__boldFont = self.font() |
58 self.__boldFont.setBold(True) |
55 self.__boldFont.setBold(True) |
59 |
56 |
60 def __initContextMenu(self): |
57 def __initContextMenu(self): |
61 """ |
58 """ |
62 Private method to initialize the context menu. |
59 Private method to initialize the context menu. |
63 """ |
60 """ |
64 self.__menu = QMenu(self) |
61 self.__menu = QMenu(self) |
65 self.__menu.addAction( |
62 self.__menu.addAction( |
66 UI.PixmapCache.getIcon("tabClose"), |
63 UI.PixmapCache.getIcon("tabClose"), |
67 self.tr('Close'), self.__contextMenuClose) |
64 self.tr("Close"), |
|
65 self.__contextMenuClose, |
|
66 ) |
68 self.closeOthersMenuAct = self.__menu.addAction( |
67 self.closeOthersMenuAct = self.__menu.addAction( |
69 UI.PixmapCache.getIcon("tabCloseOther"), |
68 UI.PixmapCache.getIcon("tabCloseOther"), |
70 self.tr("Close Others"), |
69 self.tr("Close Others"), |
71 self.__contextMenuCloseOthers) |
70 self.__contextMenuCloseOthers, |
72 self.__menu.addAction( |
71 ) |
73 self.tr('Close All'), self.__contextMenuCloseAll) |
72 self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll) |
74 self.__menu.addSeparator() |
73 self.__menu.addSeparator() |
75 self.__copyUrlAct = self.__menu.addAction( |
74 self.__copyUrlAct = self.__menu.addAction( |
76 self.tr("Copy URL to Clipboard"), |
75 self.tr("Copy URL to Clipboard"), self.__contextMenuCopyUrlToClipboard |
77 self.__contextMenuCopyUrlToClipboard) |
76 ) |
78 |
77 |
79 @pyqtSlot(QPoint) |
78 @pyqtSlot(QPoint) |
80 def __showContextMenu(self, point): |
79 def __showContextMenu(self, point): |
81 """ |
80 """ |
82 Private slot to handle the customContextMenuRequested signal of |
81 Private slot to handle the customContextMenuRequested signal of |
83 the viewlist. |
82 the viewlist. |
84 |
83 |
85 @param point position to open the menu at |
84 @param point position to open the menu at |
86 @type QPoint |
85 @type QPoint |
87 """ |
86 """ |
88 itm = self.itemAt(point) |
87 itm = self.itemAt(point) |
89 self.__copyUrlAct.setEnabled(bool(itm) and itm.text() != "about:blank") |
88 self.__copyUrlAct.setEnabled(bool(itm) and itm.text() != "about:blank") |
90 self.closeOthersMenuAct.setEnabled(self.count() > 1) |
89 self.closeOthersMenuAct.setEnabled(self.count() > 1) |
91 self.__menu.popup(self.mapToGlobal(point)) |
90 self.__menu.popup(self.mapToGlobal(point)) |
92 |
91 |
93 @pyqtSlot(int) |
92 @pyqtSlot(int) |
94 def __currentPageChanged(self, index): |
93 def __currentPageChanged(self, index): |
95 """ |
94 """ |
96 Private slot to handle a change of the shown page. |
95 Private slot to handle a change of the shown page. |
97 |
96 |
98 @param index index of the current page |
97 @param index index of the current page |
99 @type int |
98 @type int |
100 """ |
99 """ |
101 for row in range(self.count()): |
100 for row in range(self.count()): |
102 itm = self.item(row) |
101 itm = self.item(row) |
103 itm.setFont( |
102 itm.setFont(self.__boldFont if row == index else self.__defaultFont) |
104 self.__boldFont if row == index else self.__defaultFont |
103 |
105 ) |
|
106 |
|
107 @pyqtSlot(int) |
104 @pyqtSlot(int) |
108 def __currentRowChanged(self, row): |
105 def __currentRowChanged(self, row): |
109 """ |
106 """ |
110 Private slot handling a change of the current row. |
107 Private slot handling a change of the current row. |
111 |
108 |
112 @param row current row |
109 @param row current row |
113 @type int |
110 @type int |
114 """ |
111 """ |
115 self.__stack.setCurrentIndex(row) |
112 self.__stack.setCurrentIndex(row) |
116 self.currentPageChanged.emit(row) |
113 self.currentPageChanged.emit(row) |
117 |
114 |
118 def addPage(self, viewer, background=False): |
115 def addPage(self, viewer, background=False): |
119 """ |
116 """ |
120 Public method to add a viewer page to our list. |
117 Public method to add a viewer page to our list. |
121 |
118 |
122 @param viewer reference to the viewer object |
119 @param viewer reference to the viewer object |
123 @type HelpViewerImpl |
120 @type HelpViewerImpl |
124 @param background flag indicating to not change the current page |
121 @param background flag indicating to not change the current page |
125 (defaults to False) |
122 (defaults to False) |
126 @type bool (optional) |
123 @type bool (optional) |
127 """ |
124 """ |
128 self.addItem(viewer.pageTitle()) |
125 self.addItem(viewer.pageTitle()) |
129 viewer.titleChanged.connect( |
126 viewer.titleChanged.connect(lambda: self.__viewerTitleChanged(viewer)) |
130 lambda: self.__viewerTitleChanged(viewer)) |
127 |
131 |
|
132 if not background: |
128 if not background: |
133 self.setCurrentRow( |
129 self.setCurrentRow(self.count() - 1) |
134 self.count() - 1) |
|
135 if self.count() == 1: |
130 if self.count() == 1: |
136 self.__currentPageChanged(0) |
131 self.__currentPageChanged(0) |
137 |
132 |
138 def insertPage(self, index, viewer, background=False): |
133 def insertPage(self, index, viewer, background=False): |
139 """ |
134 """ |
140 Public method to insert a viewer page into our list. |
135 Public method to insert a viewer page into our list. |
141 |
136 |
142 @param index index to insert at |
137 @param index index to insert at |
143 @type int |
138 @type int |
144 @param viewer reference to the viewer object |
139 @param viewer reference to the viewer object |
145 @type HelpViewerImpl |
140 @type HelpViewerImpl |
146 @param background flag indicating to not change the current page |
141 @param background flag indicating to not change the current page |
147 (defaults to False) |
142 (defaults to False) |
148 @type bool (optional) |
143 @type bool (optional) |
149 """ |
144 """ |
150 currentRow = self.currentRow() |
145 currentRow = self.currentRow() |
151 self.insertItem(index, viewer.pageTitle()) |
146 self.insertItem(index, viewer.pageTitle()) |
152 viewer.titleChanged.connect( |
147 viewer.titleChanged.connect(lambda: self.__viewerTitleChanged(viewer)) |
153 lambda: self.__viewerTitleChanged(viewer)) |
148 |
154 |
|
155 if not background: |
149 if not background: |
156 self.setCurrentRow(index) |
150 self.setCurrentRow(index) |
157 else: |
151 else: |
158 self.setCurrentRow(currentRow) |
152 self.setCurrentRow(currentRow) |
159 |
153 |
160 def __viewerTitleChanged(self, viewer): |
154 def __viewerTitleChanged(self, viewer): |
161 """ |
155 """ |
162 Private method to handle the change of a viewer title. |
156 Private method to handle the change of a viewer title. |
163 |
157 |
164 @param viewer reference to the viewer that change title |
158 @param viewer reference to the viewer that change title |
165 @type HelpViewerImpl |
159 @type HelpViewerImpl |
166 """ |
160 """ |
167 index = self.__stack.indexOf(viewer) |
161 index = self.__stack.indexOf(viewer) |
168 itm = self.item(index) |
162 itm = self.item(index) |
169 itm.setText(viewer.pageTitle()) |
163 itm.setText(viewer.pageTitle()) |
170 self.currentPageChanged.emit(index) |
164 self.currentPageChanged.emit(index) |
171 |
165 |
172 ####################################################################### |
166 ####################################################################### |
173 ## Context menu action methods |
167 ## Context menu action methods |
174 ####################################################################### |
168 ####################################################################### |
175 |
169 |
176 @pyqtSlot() |
170 @pyqtSlot() |
177 def __contextMenuClose(self): |
171 def __contextMenuClose(self): |
178 """ |
172 """ |
179 Private slot to close a page via the context menu. |
173 Private slot to close a page via the context menu. |
180 """ |
174 """ |
181 self.closeCurrentPage() |
175 self.closeCurrentPage() |
182 |
176 |
183 @pyqtSlot() |
177 @pyqtSlot() |
184 def __contextMenuCloseOthers(self): |
178 def __contextMenuCloseOthers(self): |
185 """ |
179 """ |
186 Private slot to close all other pages via the context menu. |
180 Private slot to close all other pages via the context menu. |
187 """ |
181 """ |
188 self.closeOtherPages() |
182 self.closeOtherPages() |
189 |
183 |
190 @pyqtSlot() |
184 @pyqtSlot() |
191 def __contextMenuCloseAll(self): |
185 def __contextMenuCloseAll(self): |
192 """ |
186 """ |
193 Private slot to close all pages via the context menu. |
187 Private slot to close all pages via the context menu. |
194 """ |
188 """ |
195 self.closeAllPages() |
189 self.closeAllPages() |
196 |
190 |
197 @pyqtSlot() |
191 @pyqtSlot() |
198 def __contextMenuCopyUrlToClipboard(self): |
192 def __contextMenuCopyUrlToClipboard(self): |
199 """ |
193 """ |
200 Private slot to copy the URL to the clipboard. |
194 Private slot to copy the URL to the clipboard. |
201 """ |
195 """ |
202 row = self.currentRow() |
196 row = self.currentRow() |
203 viewer = self.__stack.widget(row) |
197 viewer = self.__stack.widget(row) |
204 url = viewer.link() |
198 url = viewer.link() |
205 if url.isValid(): |
199 if url.isValid(): |
206 urlStr = url.toString() |
200 urlStr = url.toString() |
207 |
201 |
208 # copy the URL to both clipboard areas |
202 # copy the URL to both clipboard areas |
209 QGuiApplication.clipboard().setText( |
203 QGuiApplication.clipboard().setText(urlStr, QClipboard.Mode.Clipboard) |
210 urlStr, QClipboard.Mode.Clipboard) |
204 QGuiApplication.clipboard().setText(urlStr, QClipboard.Mode.Selection) |
211 QGuiApplication.clipboard().setText( |
205 |
212 urlStr, QClipboard.Mode.Selection) |
|
213 |
|
214 def __removeViewer(self, row): |
206 def __removeViewer(self, row): |
215 """ |
207 """ |
216 Private method to remove a viewer page. |
208 Private method to remove a viewer page. |
217 |
209 |
218 @param row row associated with the viewer |
210 @param row row associated with the viewer |
219 @type int |
211 @type int |
220 """ |
212 """ |
221 viewer = self.__stack.widget(row) |
213 viewer = self.__stack.widget(row) |
222 self.__stack.removeWidget(viewer) |
214 self.__stack.removeWidget(viewer) |
223 viewer.deleteLater() |
215 viewer.deleteLater() |
224 |
216 |
225 itm = self.takeItem(row) |
217 itm = self.takeItem(row) |
226 del itm |
218 del itm |
227 |
219 |
228 ####################################################################### |
220 ####################################################################### |
229 ## Slots for external access below |
221 ## Slots for external access below |
230 ####################################################################### |
222 ####################################################################### |
231 |
223 |
232 @pyqtSlot() |
224 @pyqtSlot() |
233 def closeCurrentPage(self): |
225 def closeCurrentPage(self): |
234 """ |
226 """ |
235 Public slot to close the current page. |
227 Public slot to close the current page. |
236 """ |
228 """ |
237 row = self.currentRow() |
229 row = self.currentRow() |
238 self.__removeViewer(row) |
230 self.__removeViewer(row) |
239 |
231 |
240 if self.count() == 0: |
232 if self.count() == 0: |
241 self.__helpViewer.addPage() |
233 self.__helpViewer.addPage() |
242 |
234 |
243 @pyqtSlot() |
235 @pyqtSlot() |
244 def closeOtherPages(self): |
236 def closeOtherPages(self): |
245 """ |
237 """ |
246 Public slot to close all other pages. |
238 Public slot to close all other pages. |
247 """ |
239 """ |
248 currentRow = self.currentRow() |
240 currentRow = self.currentRow() |
249 for row in range(self.count() - 1, -1, -1): |
241 for row in range(self.count() - 1, -1, -1): |
250 if row != currentRow: |
242 if row != currentRow: |
251 self.__removeViewer(row) |
243 self.__removeViewer(row) |
252 |
244 |
253 @pyqtSlot() |
245 @pyqtSlot() |
254 def closeAllPages(self): |
246 def closeAllPages(self): |
255 """ |
247 """ |
256 Public slot to close all pages. |
248 Public slot to close all pages. |
257 """ |
249 """ |