19 from .HistoryModel import HistoryModel |
19 from .HistoryModel import HistoryModel |
20 from .HistoryDialog import HistoryDialog |
20 from .HistoryDialog import HistoryDialog |
21 |
21 |
22 import UI.PixmapCache |
22 import UI.PixmapCache |
23 |
23 |
|
24 |
24 class HistoryMenuModel(QAbstractProxyModel): |
25 class HistoryMenuModel(QAbstractProxyModel): |
25 """ |
26 """ |
26 Class implementing a model for the history menu. |
27 Class implementing a model for the history menu. |
27 |
28 |
28 It maps the first bunch of items of the source model to the root. |
29 It maps the first bunch of items of the source model to the root. |
29 """ |
30 """ |
30 MOVEDROWS = 15 |
31 MOVEDROWS = 15 |
31 |
32 |
32 def __init__(self, sourceModel, parent = None): |
33 def __init__(self, sourceModel, parent=None): |
33 """ |
34 """ |
34 Constructor |
35 Constructor |
35 |
36 |
36 @param sourceModel reference to the source model (QAbstractItemModel) |
37 @param sourceModel reference to the source model (QAbstractItemModel) |
37 @param parent reference to the parent object (QObject) |
38 @param parent reference to the parent object (QObject) |
51 first = self.__treeModel.index(0, 0) |
52 first = self.__treeModel.index(0, 0) |
52 if not first.isValid(): |
53 if not first.isValid(): |
53 return 0 |
54 return 0 |
54 return min(self.__treeModel.rowCount(first), self.MOVEDROWS) |
55 return min(self.__treeModel.rowCount(first), self.MOVEDROWS) |
55 |
56 |
56 def columnCount(self, parent = QModelIndex()): |
57 def columnCount(self, parent=QModelIndex()): |
57 """ |
58 """ |
58 Public method to get the number of columns. |
59 Public method to get the number of columns. |
59 |
60 |
60 @param parent index of parent (QModelIndex) |
61 @param parent index of parent (QModelIndex) |
61 @return number of columns (integer) |
62 @return number of columns (integer) |
62 """ |
63 """ |
63 return self.__treeModel.columnCount(self.mapToSource(parent)) |
64 return self.__treeModel.columnCount(self.mapToSource(parent)) |
64 |
65 |
65 def rowCount(self, parent = QModelIndex()): |
66 def rowCount(self, parent=QModelIndex()): |
66 """ |
67 """ |
67 Public method to determine the number of rows. |
68 Public method to determine the number of rows. |
68 |
69 |
69 @param parent index of parent (QModelIndex) |
70 @param parent index of parent (QModelIndex) |
70 @return number of rows (integer) |
71 @return number of rows (integer) |
113 return QModelIndex() |
114 return QModelIndex() |
114 |
115 |
115 if proxyIndex.internalId() == sys.maxsize: |
116 if proxyIndex.internalId() == sys.maxsize: |
116 bumpedItems = self.bumpedRows() |
117 bumpedItems = self.bumpedRows() |
117 if proxyIndex.row() < bumpedItems: |
118 if proxyIndex.row() < bumpedItems: |
118 return self.__treeModel.index(proxyIndex.row(), proxyIndex.column(), |
119 return self.__treeModel.index(proxyIndex.row(), proxyIndex.column(), |
119 self.__treeModel.index(0, 0)) |
120 self.__treeModel.index(0, 0)) |
120 if bumpedItems <= self.MOVEDROWS and \ |
121 if bumpedItems <= self.MOVEDROWS and \ |
121 bumpedItems == self.sourceModel().rowCount(self.__treeModel.index(0, 0)): |
122 bumpedItems == self.sourceModel().rowCount(self.__treeModel.index(0, 0)): |
122 bumpedItems -= 1 |
123 bumpedItems -= 1 |
123 return self.__treeModel.index(proxyIndex.row() - bumpedItems, |
124 return self.__treeModel.index(proxyIndex.row() - bumpedItems, |
124 proxyIndex.column()) |
125 proxyIndex.column()) |
125 |
126 |
126 historyIndex = self.__treeModel.sourceModel()\ |
127 historyIndex = self.__treeModel.sourceModel()\ |
127 .index(proxyIndex.internalId(), proxyIndex.column()) |
128 .index(proxyIndex.internalId(), proxyIndex.column()) |
128 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
129 treeIndex = self.__treeModel.mapFromSource(historyIndex) |
129 return treeIndex |
130 return treeIndex |
130 |
131 |
131 def index(self, row, column, parent = QModelIndex()): |
132 def index(self, row, column, parent=QModelIndex()): |
132 """ |
133 """ |
133 Public method to create an index. |
134 Public method to create an index. |
134 |
135 |
135 @param row row number for the index (integer) |
136 @param row row number for the index (integer) |
136 @param column column number for the index (integer) |
137 @param column column number for the index (integer) |
177 bumpedItems = self.bumpedRows() |
178 bumpedItems = self.bumpedRows() |
178 if bumpedItems <= self.MOVEDROWS and \ |
179 if bumpedItems <= self.MOVEDROWS and \ |
179 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)): |
180 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)): |
180 bumpedItems -= 1 |
181 bumpedItems -= 1 |
181 |
182 |
182 return self.createIndex(bumpedItems + treeIndexParent.row(), |
183 return self.createIndex(bumpedItems + treeIndexParent.row(), |
183 treeIndexParent.column(), |
184 treeIndexParent.column(), |
184 sourceRow) |
185 sourceRow) |
185 |
186 |
186 def mimeData(self, indexes): |
187 def mimeData(self, indexes): |
187 """ |
188 """ |
188 Public method to return the mime data. |
189 Public method to return the mime data. |
207 @signal newUrl(QUrl, str) emitted to open a URL in a new tab |
209 @signal newUrl(QUrl, str) emitted to open a URL in a new tab |
208 """ |
210 """ |
209 openUrl = pyqtSignal(QUrl, str) |
211 openUrl = pyqtSignal(QUrl, str) |
210 newUrl = pyqtSignal(QUrl, str) |
212 newUrl = pyqtSignal(QUrl, str) |
211 |
213 |
212 def __init__(self, parent = None): |
214 def __init__(self, parent=None): |
213 """ |
215 """ |
214 Constructor |
216 Constructor |
215 |
217 |
216 @param parent reference to the parent widget (QWidget) |
218 @param parent reference to the parent widget (QWidget) |
217 """ |
219 """ |
232 |
234 |
233 @param idx index of the activated item (QModelIndex) |
235 @param idx index of the activated item (QModelIndex) |
234 """ |
236 """ |
235 if self._keyboardModifiers & Qt.ControlModifier: |
237 if self._keyboardModifiers & Qt.ControlModifier: |
236 self.newUrl.emit( |
238 self.newUrl.emit( |
237 idx.data(HistoryModel.UrlRole), |
239 idx.data(HistoryModel.UrlRole), |
238 idx.data(HistoryModel.TitleRole)) |
240 idx.data(HistoryModel.TitleRole)) |
239 else: |
241 else: |
240 self.openUrl.emit( |
242 self.openUrl.emit( |
241 idx.data(HistoryModel.UrlRole), |
243 idx.data(HistoryModel.UrlRole), |
242 idx.data(HistoryModel.TitleRole)) |
244 idx.data(HistoryModel.TitleRole)) |
243 |
245 |
244 def prePopulated(self): |
246 def prePopulated(self): |
245 """ |
247 """ |
246 Public method to add any actions before the tree. |
248 Public method to add any actions before the tree. |
267 Public method to add any actions after the tree. |
269 Public method to add any actions after the tree. |
268 """ |
270 """ |
269 if len(self.__historyManager.history()) > 0: |
271 if len(self.__historyManager.history()) > 0: |
270 self.addSeparator() |
272 self.addSeparator() |
271 |
273 |
272 act = self.addAction(UI.PixmapCache.getIcon("history.png"), |
274 act = self.addAction(UI.PixmapCache.getIcon("history.png"), |
273 self.trUtf8("Show All History...")) |
275 self.trUtf8("Show All History...")) |
274 act.triggered[()].connect(self.__showHistoryDialog) |
276 act.triggered[()].connect(self.__showHistoryDialog) |
275 act = self.addAction(UI.PixmapCache.getIcon("historyClear.png"), |
277 act = self.addAction(UI.PixmapCache.getIcon("historyClear.png"), |
276 self.trUtf8("Clear History...")) |
278 self.trUtf8("Clear History...")) |
277 act.triggered[()].connect(self.__clearHistoryDialog) |
279 act.triggered[()].connect(self.__clearHistoryDialog) |
278 |
280 |
279 def setInitialActions(self, actions): |
281 def setInitialActions(self, actions): |
280 """ |
282 """ |