26 openUrl = pyqtSignal(QUrl) |
26 openUrl = pyqtSignal(QUrl) |
27 newTab = pyqtSignal(QUrl) |
27 newTab = pyqtSignal(QUrl) |
28 newBackgroundTab = pyqtSignal(QUrl) |
28 newBackgroundTab = pyqtSignal(QUrl) |
29 newWindow = pyqtSignal(QUrl) |
29 newWindow = pyqtSignal(QUrl) |
30 |
30 |
31 def __init__(self, engine, parent=None): |
31 def __init__(self, engine, internal=False, parent=None): |
32 """ |
32 """ |
33 Constructor |
33 Constructor |
34 |
34 |
35 @param engine reference to the help engine (QHelpEngine) |
35 @param engine reference to the help engine |
36 @param parent reference to the parent widget (QWidget) |
36 @type QHelpEngine |
|
37 @param internal flag indicating the internal help viewer |
|
38 @type bool |
|
39 @param parent reference to the parent widget |
|
40 @type QWidget |
37 """ |
41 """ |
38 super().__init__(parent) |
42 super().__init__(parent) |
39 |
43 |
40 self.__engine = engine |
44 self.__engine = engine |
41 self.__expandDepth = -2 |
45 self.__expandDepth = -2 |
|
46 |
|
47 self.__internal = internal |
42 |
48 |
43 self.__tocWidget = self.__engine.contentWidget() |
49 self.__tocWidget = self.__engine.contentWidget() |
44 self.__tocWidget.setContextMenuPolicy( |
50 self.__tocWidget.setContextMenuPolicy( |
45 Qt.ContextMenuPolicy.CustomContextMenu) |
51 Qt.ContextMenuPolicy.CustomContextMenu) |
46 self.__tocWidget.setSortingEnabled(True) |
52 self.__tocWidget.setSortingEnabled(True) |
47 |
53 |
48 self.__layout = QVBoxLayout(self) |
54 self.__layout = QVBoxLayout(self) |
49 self.__layout.addWidget(self.__tocWidget) |
55 self.__layout.addWidget(self.__tocWidget) |
|
56 self.__layout.setContentsMargins(0, 0, 0, 0) |
50 |
57 |
51 self.__tocWidget.customContextMenuRequested.connect( |
58 self.__tocWidget.customContextMenuRequested.connect( |
52 self.__showContextMenu) |
59 self.__showContextMenu) |
53 self.__tocWidget.linkActivated.connect(self.__linkActivated) |
60 self.__tocWidget.linkActivated.connect(self.__linkActivated) |
54 |
61 |
80 ) |
87 ) |
81 ): |
88 ): |
82 self.newBackgroundTab.emit(url) |
89 self.newBackgroundTab.emit(url) |
83 elif modifiers & Qt.KeyboardModifier.ControlModifier: |
90 elif modifiers & Qt.KeyboardModifier.ControlModifier: |
84 self.newTab.emit(url) |
91 self.newTab.emit(url) |
85 elif modifiers & Qt.KeyboardModifier.ShiftModifier: |
92 elif ( |
|
93 modifiers & Qt.KeyboardModifier.ShiftModifier and |
|
94 not self.__internal |
|
95 ): |
86 self.newWindow.emit(url) |
96 self.newWindow.emit(url) |
87 else: |
97 else: |
88 self.openUrl.emit(url) |
98 self.openUrl.emit(url) |
89 |
99 |
90 def __contentsCreated(self): |
100 def __contentsCreated(self): |
160 if link.isEmpty() or not link.isValid(): |
170 if link.isEmpty() or not link.isValid(): |
161 return |
171 return |
162 |
172 |
163 menu = QMenu() |
173 menu = QMenu() |
164 curTab = menu.addAction(self.tr("Open Link")) |
174 curTab = menu.addAction(self.tr("Open Link")) |
165 newTab = menu.addAction(self.tr("Open Link in New Tab")) |
175 if self.__internal: |
166 newBackgroundTab = menu.addAction( |
176 newTab = menu.addAction(self.tr("Open Link in New Page")) |
167 self.tr("Open Link in Background Tab")) |
177 newBackgroundTab = menu.addAction( |
168 newWindow = menu.addAction(self.tr("Open Link in New Window")) |
178 self.tr("Open Link in Background Page")) |
|
179 else: |
|
180 newTab = menu.addAction(self.tr("Open Link in New Tab")) |
|
181 newBackgroundTab = menu.addAction( |
|
182 self.tr("Open Link in Background Tab")) |
|
183 newWindow = menu.addAction(self.tr("Open Link in New Window")) |
169 menu.move(self.__tocWidget.mapToGlobal(pos)) |
184 menu.move(self.__tocWidget.mapToGlobal(pos)) |
170 |
185 |
171 act = menu.exec() |
186 act = menu.exec() |
172 if act == curTab: |
187 if act == curTab: |
173 self.openUrl.emit(link) |
188 self.openUrl.emit(link) |
174 elif act == newTab: |
189 elif act == newTab: |
175 self.newTab.emit(link) |
190 self.newTab.emit(link) |
176 elif act == newBackgroundTab: |
191 elif act == newBackgroundTab: |
177 self.newBackgroundTab.emit(link) |
192 self.newBackgroundTab.emit(link) |
178 elif act == newWindow: |
193 elif not self.__internal and act == newWindow: |
179 self.newWindow.emit(link) |
194 self.newWindow.emit(link) |