8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QEvent |
10 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QEvent |
11 from PyQt6.QtHelp import QHelpLink |
11 from PyQt6.QtHelp import QHelpLink |
12 from PyQt6.QtWidgets import ( |
12 from PyQt6.QtWidgets import ( |
13 QWidget, QVBoxLayout, QLabel, QLineEdit, QMenu, QDialog, QApplication |
13 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QMenu, QDialog, |
|
14 QApplication |
14 ) |
15 ) |
15 |
16 |
16 |
17 |
17 class HelpIndexWidget(QWidget): |
18 class HelpIndexWidget(QWidget): |
18 """ |
19 """ |
29 openUrl = pyqtSignal(QUrl) |
30 openUrl = pyqtSignal(QUrl) |
30 newTab = pyqtSignal(QUrl) |
31 newTab = pyqtSignal(QUrl) |
31 newBackgroundTab = pyqtSignal(QUrl) |
32 newBackgroundTab = pyqtSignal(QUrl) |
32 newWindow = pyqtSignal(QUrl) |
33 newWindow = pyqtSignal(QUrl) |
33 |
34 |
34 def __init__(self, engine, parent=None): |
35 def __init__(self, engine, internal=False, parent=None): |
35 """ |
36 """ |
36 Constructor |
37 Constructor |
37 |
38 |
38 @param engine reference to the help engine |
39 @param engine reference to the help engine |
39 @type QHelpEngine |
40 @type QHelpEngine |
|
41 @param internal flag indicating the internal help viewer |
|
42 @type bool |
40 @param parent reference to the parent widget |
43 @param parent reference to the parent widget |
41 @type QWidget |
44 @type QWidget |
42 """ |
45 """ |
43 super().__init__(parent) |
46 super().__init__(parent) |
44 |
47 |
45 self.__engine = engine |
48 self.__engine = engine |
|
49 self.__internal = internal |
46 |
50 |
47 self.__searchEdit = None |
51 self.__searchEdit = None |
48 self.__index = None |
52 self.__index = None |
49 |
53 |
50 self.__layout = QVBoxLayout(self) |
54 self.__layout = QVBoxLayout(self) |
|
55 if internal: |
|
56 # no margins for the internal variant |
|
57 self.__layout.setContentsMargins(0, 0, 0, 0) |
|
58 |
|
59 self.__searchEditLayout = QHBoxLayout() |
51 label = QLabel(self.tr("&Look for:")) |
60 label = QLabel(self.tr("&Look for:")) |
52 self.__layout.addWidget(label) |
61 self.__searchEditLayout.addWidget(label) |
53 |
62 |
54 self.__searchEdit = QLineEdit() |
63 self.__searchEdit = QLineEdit() |
|
64 self.__searchEdit.setClearButtonEnabled(True) |
55 label.setBuddy(self.__searchEdit) |
65 label.setBuddy(self.__searchEdit) |
56 self.__searchEdit.textChanged.connect(self.__filterIndices) |
66 self.__searchEdit.textChanged.connect(self.__filterIndices) |
57 self.__searchEdit.installEventFilter(self) |
67 self.__searchEdit.installEventFilter(self) |
58 self.__layout.addWidget(self.__searchEdit) |
68 self.__searchEditLayout.addWidget(self.__searchEdit) |
|
69 self.__layout.addLayout(self.__searchEditLayout) |
59 |
70 |
60 self.__index = self.__engine.indexWidget() |
71 self.__index = self.__engine.indexWidget() |
61 self.__index.setContextMenuPolicy( |
72 self.__index.setContextMenuPolicy( |
62 Qt.ContextMenuPolicy.CustomContextMenu) |
73 Qt.ContextMenuPolicy.CustomContextMenu) |
63 |
74 |
94 Qt.KeyboardModifier.ControlModifier |
105 Qt.KeyboardModifier.ControlModifier |
95 ): |
106 ): |
96 self.newBackgroundTab.emit(document.url) |
107 self.newBackgroundTab.emit(document.url) |
97 elif modifiers & Qt.KeyboardModifier.ControlModifier: |
108 elif modifiers & Qt.KeyboardModifier.ControlModifier: |
98 self.newTab.emit(document.url) |
109 self.newTab.emit(document.url) |
99 elif modifiers & Qt.KeyboardModifier.ShiftModifier: |
110 elif ( |
|
111 modifiers & Qt.KeyboardModifier.ShiftModifier and |
|
112 not self.__internal |
|
113 ): |
100 self.newWindow.emit(document.url) |
114 self.newWindow.emit(document.url) |
101 else: |
115 else: |
102 self.openUrl.emit(document.url) |
116 self.openUrl.emit(document.url) |
103 |
117 |
104 def __documentsActivated(self, documents, helpKeyword): |
118 def __documentsActivated(self, documents, helpKeyword): |
130 @type str |
144 @type str |
131 @return selected document |
145 @return selected document |
132 @rtype QHelpLink |
146 @rtype QHelpLink |
133 """ |
147 """ |
134 document = QHelpLink() |
148 document = QHelpLink() |
|
149 |
135 from .HelpTopicDialog import HelpTopicDialog |
150 from .HelpTopicDialog import HelpTopicDialog |
136 dlg = HelpTopicDialog(self, helpKeyword, documents) |
151 dlg = HelpTopicDialog(self, helpKeyword, documents) |
137 if dlg.exec() == QDialog.DialogCode.Accepted: |
152 if dlg.exec() == QDialog.DialogCode.Accepted: |
138 document = dlg.document() |
153 document = dlg.document() |
|
154 |
139 return document |
155 return document |
140 |
156 |
141 def __filterIndices(self, indexFilter): |
157 def __filterIndices(self, indexFilter): |
142 """ |
158 """ |
143 Private slot to filter the indexes according to the given filter. |
159 Private slot to filter the indexes according to the given filter. |
214 """ |
230 """ |
215 idx = self.__index.indexAt(pos) |
231 idx = self.__index.indexAt(pos) |
216 if idx.isValid(): |
232 if idx.isValid(): |
217 menu = QMenu() |
233 menu = QMenu() |
218 curTab = menu.addAction(self.tr("Open Link")) |
234 curTab = menu.addAction(self.tr("Open Link")) |
219 newTab = menu.addAction(self.tr("Open Link in New Tab")) |
235 if self.__internal: |
220 newBackgroundTab = menu.addAction( |
236 newTab = menu.addAction(self.tr("Open Link in New Page")) |
221 self.tr("Open Link in Background Tab")) |
237 newBackgroundTab = menu.addAction( |
222 newWindow = menu.addAction(self.tr("Open Link in New Window")) |
238 self.tr("Open Link in Background Page")) |
|
239 else: |
|
240 newTab = menu.addAction(self.tr("Open Link in New Tab")) |
|
241 newBackgroundTab = menu.addAction( |
|
242 self.tr("Open Link in Background Tab")) |
|
243 newWindow = menu.addAction(self.tr("Open Link in New Window")) |
223 menu.move(self.__index.mapToGlobal(pos)) |
244 menu.move(self.__index.mapToGlobal(pos)) |
224 |
245 |
225 act = menu.exec() |
246 act = menu.exec() |
226 model = self.__index.model() |
247 model = self.__index.model() |
227 if model is not None: |
248 if model is not None: |
228 helpKeyword = model.data(idx, Qt.ItemDataRole.DisplayRole) |
249 helpKeyword = model.data(idx, Qt.ItemDataRole.DisplayRole) |
229 helpLinks = self.__engine.documentsForKeyword(helpKeyword, "") |
250 helpLinks = self.__engine.documentsForKeyword(helpKeyword, "") |
230 if len(helpLinks) == 1: |
251 if len(helpLinks) == 1: |
231 link = helpLinks[0].url |
252 link = helpLinks[0].url |
232 else: |
253 else: |
233 link = self.__selectDocument(helpLinks, helpKeyword) |
254 link = self.__selectDocument(helpLinks, helpKeyword).url |
234 |
255 |
235 if not link.isEmpty() and link.isValid(): |
256 if not link.isEmpty() and link.isValid(): |
236 if act == curTab: |
257 if act == curTab: |
237 self.openUrl.emit(link) |
258 self.openUrl.emit(link) |
238 elif act == newTab: |
259 elif act == newTab: |
239 self.newTab.emit(link) |
260 self.newTab.emit(link) |
240 elif act == newBackgroundTab: |
261 elif act == newBackgroundTab: |
241 self.newBackgroundTab.emit(link) |
262 self.newBackgroundTab.emit(link) |
242 elif act == newWindow: |
263 elif not self.__internal and act == newWindow: |
243 self.newWindow.emit(link) |
264 self.newWindow.emit(link) |