23 """ |
23 """ |
24 def __init__(self, subscription, parent=None): |
24 def __init__(self, subscription, parent=None): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param subscription reference to the subscription (AdBlockSubscription) |
28 @param subscription reference to the subscription |
29 @param parent reference to the parent widget (QWidget) |
29 @type AdBlockSubscription |
|
30 @param parent reference to the parent widget |
|
31 @type QWidget |
30 """ |
32 """ |
31 super(AdBlockTreeWidget, self).__init__(parent) |
33 super(AdBlockTreeWidget, self).__init__(parent) |
32 |
34 |
33 self.__subscription = subscription |
35 self.__subscription = subscription |
34 self.__topItem = None |
36 self.__topItem = None |
47 |
49 |
48 def subscription(self): |
50 def subscription(self): |
49 """ |
51 """ |
50 Public method to get a reference to the subscription. |
52 Public method to get a reference to the subscription. |
51 |
53 |
52 @return reference to the subscription (AdBlockSubscription) |
54 @return reference to the subscription |
|
55 @rtype AdBlockSubscription |
53 """ |
56 """ |
54 return self.__subscription |
57 return self.__subscription |
55 |
58 |
56 def showRule(self, rule): |
59 def showRule(self, rule): |
57 """ |
60 """ |
58 Public method to highlight the given rule. |
61 Public method to highlight the given rule. |
59 |
62 |
60 @param rule AdBlock rule to be shown (AdBlockRule) |
63 @param rule AdBlock rule to be shown |
61 """ |
64 @type AdBlockRule |
62 if rule: |
65 """ |
|
66 if not bool(self.__topItem) and bool(rule): |
63 self.__ruleToBeSelected = rule.filter() |
67 self.__ruleToBeSelected = rule.filter() |
64 if not self.__topItem: |
68 elif self.__ruleToBeSelected: |
65 return |
|
66 if self.__ruleToBeSelected: |
|
67 items = self.findItems(self.__ruleToBeSelected, Qt.MatchRecursive) |
69 items = self.findItems(self.__ruleToBeSelected, Qt.MatchRecursive) |
68 if items: |
70 if items: |
69 item = items[0] |
71 item = items[0] |
70 self.setCurrentItem(item) |
72 self.setCurrentItem(item) |
71 self.scrollToItem(item, QAbstractItemView.PositionAtCenter) |
73 self.scrollToItem(item, QAbstractItemView.PositionAtCenter) |
144 |
147 |
145 def __contextMenuRequested(self, pos): |
148 def __contextMenuRequested(self, pos): |
146 """ |
149 """ |
147 Private slot to show the context menu. |
150 Private slot to show the context menu. |
148 |
151 |
149 @param pos position for the menu (QPoint) |
152 @param pos position for the menu |
|
153 @type QPoint |
150 """ |
154 """ |
151 if not self.__subscription.canEditRules(): |
155 if not self.__subscription.canEditRules(): |
152 return |
156 return |
153 |
157 |
154 item = self.itemAt(pos) |
158 item = self.itemAt(pos) |
166 |
170 |
167 def __itemChanged(self, itm): |
171 def __itemChanged(self, itm): |
168 """ |
172 """ |
169 Private slot to handle the change of an item. |
173 Private slot to handle the change of an item. |
170 |
174 |
171 @param itm changed item (QTreeWidgetItem) |
175 @param itm changed item |
|
176 @type QTreeWidgetItem |
172 """ |
177 """ |
173 if itm is None or self.__itemChangingBlock: |
178 if itm is None or self.__itemChangingBlock: |
174 return |
179 return |
175 |
180 |
176 self.__itemChangingBlock = True |
181 self.__itemChangingBlock = True |
217 |
222 |
218 def __adjustItemFeatures(self, itm, rule): |
223 def __adjustItemFeatures(self, itm, rule): |
219 """ |
224 """ |
220 Private method to adjust an item. |
225 Private method to adjust an item. |
221 |
226 |
222 @param itm item to be adjusted (QTreeWidgetItem) |
227 @param itm item to be adjusted |
223 @param rule rule for the adjustment (AdBlockRule) |
228 @type QTreeWidgetItem |
|
229 @param rule rule for the adjustment |
|
230 @type AdBlockRule |
224 """ |
231 """ |
225 if not rule.isEnabled(): |
232 if not rule.isEnabled(): |
226 font = QFont() |
233 font = QFont() |
227 font.setItalic(True) |
234 font.setItalic(True) |
228 itm.setForeground(0, QColor(Qt.gray)) |
235 itm.setForeground(0, QColor(Qt.gray)) |
249 |
256 |
250 def keyPressEvent(self, evt): |
257 def keyPressEvent(self, evt): |
251 """ |
258 """ |
252 Protected method handling key presses. |
259 Protected method handling key presses. |
253 |
260 |
254 @param evt key press event (QKeyEvent) |
261 @param evt key press event |
|
262 @type QKeyEvent |
255 """ |
263 """ |
256 if evt.key() == Qt.Key_C and \ |
264 if evt.key() == Qt.Key_C and \ |
257 evt.modifiers() & Qt.ControlModifier: |
265 evt.modifiers() & Qt.ControlModifier: |
258 self.__copyFilter() |
266 self.__copyFilter() |
259 elif evt.key() == Qt.Key_Delete: |
267 elif evt.key() == Qt.Key_Delete: |