7 Module implementing a window for showing the QtHelp index. |
7 Module implementing a window for showing the QtHelp index. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSignal, Qt, QEvent, QUrl |
12 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl |
13 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextBrowser, QApplication, \ |
13 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextBrowser, QApplication, \ |
14 QMenu |
14 QMenu |
15 |
15 |
16 |
16 |
17 class HelpSearchWidget(QWidget): |
17 class HelpSearchWidget(QWidget): |
46 self.__layout.addWidget(self.__result) |
46 self.__layout.addWidget(self.__result) |
47 |
47 |
48 self.setFocusProxy(self.__query) |
48 self.setFocusProxy(self.__query) |
49 |
49 |
50 self.__query.search.connect(self.__search) |
50 self.__query.search.connect(self.__search) |
51 self.__result.requestShowLink.connect(self.linkActivated) |
51 self.__result.requestShowLink.connect(self.__linkActivated) |
52 |
52 |
53 self.__engine.searchingStarted.connect(self.__searchingStarted) |
53 self.__engine.searchingStarted.connect(self.__searchingStarted) |
54 self.__engine.searchingFinished.connect(self.__searchingFinished) |
54 self.__engine.searchingFinished.connect(self.__searchingFinished) |
55 |
55 |
56 self.__browser = self.__result.findChildren(QTextBrowser)[0] |
56 self.__browser = self.__result.findChildren(QTextBrowser)[0] |
57 if self.__browser: |
|
58 self.__browser.viewport().installEventFilter(self) |
|
59 |
57 |
60 def __search(self): |
58 def __search(self): |
61 """ |
59 """ |
62 Private slot to perform a search of the database. |
60 Private slot to perform a search of the database. |
63 """ |
61 """ |
76 |
74 |
77 @param hits number of hits (integer) (unused) |
75 @param hits number of hits (integer) (unused) |
78 """ |
76 """ |
79 QApplication.restoreOverrideCursor() |
77 QApplication.restoreOverrideCursor() |
80 |
78 |
81 def eventFilter(self, watched, event): |
79 @pyqtSlot(QUrl) |
|
80 def __linkActivated(self, url): |
82 """ |
81 """ |
83 Public method called to filter the event queue. |
82 Private slot handling the activation of an entry. |
84 |
83 |
85 @param watched the QObject being watched (QObject) |
84 @param url URL of the activated entry |
86 @param event the event that occurred (QEvent) |
85 @type QUrl |
87 @return flag indicating whether the event was handled (boolean) |
|
88 """ |
86 """ |
89 if self.__browser and watched == self.__browser.viewport() and \ |
87 if not url.isEmpty() and url.isValid(): |
90 event.type() == QEvent.MouseButtonRelease: |
88 buttons = QApplication.mouseButtons() |
91 link = self.__result.linkAt(event.pos()) |
89 modifiers = QApplication.keyboardModifiers() |
92 if not link.isEmpty() and link.isValid(): |
90 |
93 ctrl = event.modifiers() & Qt.ControlModifier |
91 if buttons & Qt.MidButton: |
94 if (event.button() == Qt.LeftButton and ctrl) or \ |
92 self.__mw.newTab(url) |
95 event.button() == Qt.MidButton: |
93 else: |
96 self.__mw.newTab(link) |
94 if modifiers & Qt.ControlModifier: |
97 |
95 self.__mw.newTab(url) |
98 return QWidget.eventFilter(self, watched, event) |
96 else: |
|
97 self.linkActivated.emit(url) |
99 |
98 |
100 def keyPressEvent(self, evt): |
99 def keyPressEvent(self, evt): |
101 """ |
100 """ |
102 Protected method handling key press events. |
101 Protected method handling key press events. |
103 |
102 |