53 self.__searchEdit.textChanged.connect(self.__filterIndices) |
53 self.__searchEdit.textChanged.connect(self.__filterIndices) |
54 self.__searchEdit.installEventFilter(self) |
54 self.__searchEdit.installEventFilter(self) |
55 self.__layout.addWidget(self.__searchEdit) |
55 self.__layout.addWidget(self.__searchEdit) |
56 |
56 |
57 self.__index = self.__engine.indexWidget() |
57 self.__index = self.__engine.indexWidget() |
58 self.__index.setContextMenuPolicy(Qt.CustomContextMenu) |
58 self.__index.setContextMenuPolicy( |
|
59 Qt.ContextMenuPolicy.CustomContextMenu) |
59 |
60 |
60 self.__engine.indexModel().indexCreationStarted.connect( |
61 self.__engine.indexModel().indexCreationStarted.connect( |
61 self.__disableSearchEdit) |
62 self.__disableSearchEdit) |
62 self.__engine.indexModel().indexCreated.connect( |
63 self.__engine.indexModel().indexCreated.connect( |
63 self.__enableSearchEdit) |
64 self.__enableSearchEdit) |
83 """ |
84 """ |
84 if modifiers is None: |
85 if modifiers is None: |
85 modifiers = QApplication.keyboardModifiers() |
86 modifiers = QApplication.keyboardModifiers() |
86 if not url.isEmpty() and url.isValid(): |
87 if not url.isEmpty() and url.isValid(): |
87 if ( |
88 if ( |
88 modifiers & (Qt.ControlModifier | Qt.ShiftModifier) == |
89 modifiers & ( |
89 (Qt.ControlModifier | Qt.ShiftModifier) |
90 Qt.KeyboardModifier.ControlModifier | |
|
91 Qt.KeyboardModifier.ShiftModifier |
|
92 ) == ( |
|
93 Qt.KeyboardModifier.ControlModifier | |
|
94 Qt.KeyboardModifier.ShiftModifier |
|
95 ) |
90 ): |
96 ): |
91 self.newBackgroundTab.emit(url) |
97 self.newBackgroundTab.emit(url) |
92 elif modifiers & Qt.ControlModifier: |
98 elif modifiers & Qt.KeyboardModifier.ControlModifier: |
93 self.newTab.emit(url) |
99 self.newTab.emit(url) |
94 elif modifiers & Qt.ShiftModifier: |
100 elif modifiers & Qt.KeyboardModifier.ShiftModifier: |
95 self.newWindow.emit(url) |
101 self.newWindow.emit(url) |
96 else: |
102 else: |
97 self.openUrl.emit(url) |
103 self.openUrl.emit(url) |
98 |
104 |
99 def __linksActivated(self, links, keyword): |
105 def __linksActivated(self, links, keyword): |
125 @rtype QUrl |
131 @rtype QUrl |
126 """ |
132 """ |
127 link = QUrl() |
133 link = QUrl() |
128 from .HelpTopicDialog import HelpTopicDialog |
134 from .HelpTopicDialog import HelpTopicDialog |
129 dlg = HelpTopicDialog(self, keyword, links) |
135 dlg = HelpTopicDialog(self, keyword, links) |
130 if dlg.exec() == QDialog.Accepted: |
136 if dlg.exec() == QDialog.DialogCode.Accepted: |
131 link = dlg.link() |
137 link = dlg.link() |
132 return link |
138 return link |
133 |
139 |
134 def __filterIndices(self, indexFilter): |
140 def __filterIndices(self, indexFilter): |
135 """ |
141 """ |
159 """ |
165 """ |
160 Protected method handling focus in events. |
166 Protected method handling focus in events. |
161 |
167 |
162 @param evt reference to the focus event object (QFocusEvent) |
168 @param evt reference to the focus event object (QFocusEvent) |
163 """ |
169 """ |
164 if evt.reason() != Qt.MouseFocusReason: |
170 if evt.reason() != Qt.FocusReason.MouseFocusReason: |
165 self.__searchEdit.selectAll() |
171 self.__searchEdit.selectAll() |
166 self.__searchEdit.setFocus() |
172 self.__searchEdit.setFocus() |
167 |
173 |
168 def eventFilter(self, watched, event): |
174 def eventFilter(self, watched, event): |
169 """ |
175 """ |
173 @param event the event that occurred (QEvent) |
179 @param event the event that occurred (QEvent) |
174 @return flag indicating whether the event was handled (boolean) |
180 @return flag indicating whether the event was handled (boolean) |
175 """ |
181 """ |
176 if ( |
182 if ( |
177 self.__searchEdit and watched == self.__searchEdit and |
183 self.__searchEdit and watched == self.__searchEdit and |
178 event.type() == QEvent.KeyPress |
184 event.type() == QEvent.Type.KeyPress |
179 ): |
185 ): |
180 idx = self.__index.currentIndex() |
186 idx = self.__index.currentIndex() |
181 if event.key() == Qt.Key_Up: |
187 if event.key() == Qt.Key.Key_Up: |
182 idx = self.__index.model().index( |
188 idx = self.__index.model().index( |
183 idx.row() - 1, idx.column(), idx.parent()) |
189 idx.row() - 1, idx.column(), idx.parent()) |
184 if idx.isValid(): |
190 if idx.isValid(): |
185 self.__index.setCurrentIndex(idx) |
191 self.__index.setCurrentIndex(idx) |
186 elif event.key() == Qt.Key_Down: |
192 elif event.key() == Qt.Key.Key_Down: |
187 idx = self.__index.model().index( |
193 idx = self.__index.model().index( |
188 idx.row() + 1, idx.column(), idx.parent()) |
194 idx.row() + 1, idx.column(), idx.parent()) |
189 if idx.isValid(): |
195 if idx.isValid(): |
190 self.__index.setCurrentIndex(idx) |
196 self.__index.setCurrentIndex(idx) |
191 elif event.key() == Qt.Key_Escape: |
197 elif event.key() == Qt.Key.Key_Escape: |
192 self.escapePressed.emit() |
198 self.escapePressed.emit() |
193 |
199 |
194 return QWidget.eventFilter(self, watched, event) |
200 return QWidget.eventFilter(self, watched, event) |
195 |
201 |
196 def __showContextMenu(self, pos): |
202 def __showContextMenu(self, pos): |
210 menu.move(self.__index.mapToGlobal(pos)) |
216 menu.move(self.__index.mapToGlobal(pos)) |
211 |
217 |
212 act = menu.exec() |
218 act = menu.exec() |
213 model = self.__index.model() |
219 model = self.__index.model() |
214 if model is not None: |
220 if model is not None: |
215 keyword = model.data(idx, Qt.DisplayRole) |
221 keyword = model.data(idx, Qt.ItemDataRole.DisplayRole) |
216 links = model.linksForKeyword(keyword) |
222 links = model.linksForKeyword(keyword) |
217 if len(links) == 1: |
223 if len(links) == 1: |
218 link = QUrl(links[list(links.keys())[0]]) |
224 link = QUrl(links[list(links.keys())[0]]) |
219 else: |
225 else: |
220 link = self.__selectLink(links, keyword) |
226 link = self.__selectLink(links, keyword) |