14 |
14 |
15 class HelpIndexWidget(QWidget): |
15 class HelpIndexWidget(QWidget): |
16 """ |
16 """ |
17 Class implementing a window for showing the QtHelp index. |
17 Class implementing a window for showing the QtHelp index. |
18 |
18 |
19 @signal linkActivated(const QUrl&) emitted when an index entry is activated |
19 @signal linkActivated(const QUrl&) emitted when an index entry is activated |
|
20 @signal linksActivated(links, keyword) emitted when an index entry referencing |
|
21 multiple targets is activated |
20 @signal escapePressed() emitted when the ESC key was pressed |
22 @signal escapePressed() emitted when the ESC key was pressed |
21 """ |
23 """ |
22 def __init__(self, engine, mainWindow, parent = None): |
24 def __init__(self, engine, mainWindow, parent = None): |
23 """ |
25 """ |
24 Constructor |
26 Constructor |
50 self.__index.installEventFilter(self) |
52 self.__index.installEventFilter(self) |
51 self.connect(self.__engine.indexModel(), SIGNAL("indexCreationStarted()"), |
53 self.connect(self.__engine.indexModel(), SIGNAL("indexCreationStarted()"), |
52 self.__disableSearchEdit) |
54 self.__disableSearchEdit) |
53 self.connect(self.__engine.indexModel(), SIGNAL("indexCreated()"), |
55 self.connect(self.__engine.indexModel(), SIGNAL("indexCreated()"), |
54 self.__enableSearchEdit) |
56 self.__enableSearchEdit) |
55 self.connect(self.__index, SIGNAL("linkActivated(const QUrl&, const QString&)"), |
57 self.connect(self.__index, SIGNAL("activated(const QModelIndex&)"), |
56 self, SIGNAL("linkActivated(const QUrl&)")) |
58 self.__activated) |
57 self.connect(self.__index, |
|
58 SIGNAL("linksActivated(const QMap<QString, QUrl>&, const QString&)"), |
|
59 self, |
|
60 SIGNAL("linksActivated(const QMap<QString, QUrl>&, const QString&)")) |
|
61 self.connect(self.__searchEdit, SIGNAL("returnPressed()"), |
59 self.connect(self.__searchEdit, SIGNAL("returnPressed()"), |
62 self.__index, SLOT("activateCurrentItem()")) |
60 self.__index, SLOT("activateCurrentItem()")) |
63 self.__layout.addWidget(self.__index) |
61 self.__layout.addWidget(self.__index) |
64 |
62 |
65 self.__index.viewport().installEventFilter(self) |
63 self.__index.viewport().installEventFilter(self) |
|
64 |
|
65 def __activated(self, idx): |
|
66 """ |
|
67 Private slot to handle the activation of a keyword entry. |
|
68 |
|
69 @param idx index of the activated entry (QModelIndex) |
|
70 """ |
|
71 model = self.__index.model() |
|
72 if model is not None: |
|
73 keyword = model.data(idx, Qt.DisplayRole) |
|
74 links = model.linksForKeyword(keyword) |
|
75 if len(links) == 1: |
|
76 self.emit(SIGNAL("linkActivated(const QUrl&)"), |
|
77 QUrl(links[list(links.keys())[0]])) |
|
78 else: |
|
79 self.emit(SIGNAL("linksActivated"), links, keyword) |
66 |
80 |
67 def __filterIndices(self, filter): |
81 def __filterIndices(self, filter): |
68 """ |
82 """ |
69 Private slot to filter the indices according to the given filter. |
83 Private slot to filter the indices according to the given filter. |
70 |
84 |
130 newTab = menu.addAction(self.trUtf8("Open Link in New Tab")) |
144 newTab = menu.addAction(self.trUtf8("Open Link in New Tab")) |
131 menu.move(self.__index.mapToGlobal(event.pos())) |
145 menu.move(self.__index.mapToGlobal(event.pos())) |
132 |
146 |
133 act = menu.exec_() |
147 act = menu.exec_() |
134 if act == curTab: |
148 if act == curTab: |
135 self.__index.activateCurrentItem() |
149 self.__activated(idx) |
136 elif act == newTab: |
150 elif act == newTab: |
137 model = self.__index.model() |
151 model = self.__index.model() |
138 if model is not None: |
152 if model is not None: |
139 keyword = model.data(idx, Qt.DisplayRole) |
153 keyword = model.data(idx, Qt.DisplayRole) |
140 links = model.linksForKeyword(keyword) |
154 links = model.linksForKeyword(keyword) |