Helpviewer/History/HistoryDialog.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to manage history.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from E4Gui.E4TreeSortFilterProxyModel import E4TreeSortFilterProxyModel
14
15 import Helpviewer.HelpWindow
16 from HistoryModel import HistoryModel
17
18 from Ui_HistoryDialog import Ui_HistoryDialog
19
20 import UI.PixmapCache
21
22 class HistoryDialog(QDialog, Ui_HistoryDialog):
23 """
24 Class implementing a dialog to manage history.
25
26 @signal openUrl(const QUrl&, const QString&) emitted to open a URL in the current
27 tab
28 @signal newUrl(const QUrl&, const QString&) emitted to open a URL in a new tab
29 """
30 def __init__(self, parent = None, manager = None):
31 """
32 Constructor
33
34 @param parent reference to the parent widget (QWidget
35 @param manager reference to the history manager object (HistoryManager)
36 """
37 QDialog.__init__(self, parent)
38 self.setupUi(self)
39
40 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png"))
41
42 self.__historyManager = manager
43 if self.__historyManager is None:
44 self.__historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager()
45
46 self.__model = self.__historyManager.historyTreeModel()
47 self.__proxyModel = E4TreeSortFilterProxyModel(self)
48 self.__proxyModel.setSortRole(HistoryModel.DateTimeRole)
49 self.__proxyModel.setFilterKeyColumn(-1)
50 self.__proxyModel.setSourceModel(self.__model)
51 self.historyTree.setModel(self.__proxyModel)
52 self.historyTree.expandAll()
53 fm = QFontMetrics(self.font())
54 header = fm.width("m") * 40
55 self.historyTree.header().resizeSection(0, header)
56 self.historyTree.header().setStretchLastSection(True)
57 self.historyTree.setContextMenuPolicy(Qt.CustomContextMenu)
58
59 self.connect(self.historyTree, SIGNAL("activated(const QModelIndex&)"),
60 self.__activated)
61 self.connect(self.historyTree,
62 SIGNAL("customContextMenuRequested(const QPoint &)"),
63 self.__customContextMenuRequested)
64
65 self.connect(self.searchEdit, SIGNAL("textChanged(QString)"),
66 self.__proxyModel.setFilterFixedString)
67 self.connect(self.removeButton, SIGNAL("clicked()"),
68 self.historyTree.removeSelected)
69 self.connect(self.removeAllButton, SIGNAL("clicked()"),
70 self.__historyManager.clear)
71
72 self.connect(self.__proxyModel, SIGNAL("modelReset()"), self.__modelReset)
73
74 def __modelReset(self):
75 """
76 Private slot handling a reset of the tree view's model.
77 """
78 self.historyTree.expandAll()
79
80 def __customContextMenuRequested(self, pos):
81 """
82 Private slot to handle the context menu request for the bookmarks tree.
83
84 @param pos position the context menu was requested (QPoint)
85 """
86 menu = QMenu()
87 idx = self.historyTree.indexAt(pos)
88 idx = idx.sibling(idx.row(), 0)
89 if idx.isValid() and not self.historyTree.model().hasChildren(idx):
90 menu.addAction(self.trUtf8("&Open"), self.__openHistoryInCurrentTab)
91 menu.addAction(self.trUtf8("Open in New &Tab"), self.__openHistoryInNewTab)
92 menu.addSeparator()
93 menu.addAction(self.trUtf8("&Copy"), self.__copyHistory)
94 menu.addAction(self.trUtf8("&Remove"), self.historyTree.removeSelected)
95 menu.exec_(QCursor.pos())
96
97 def __activated(self, idx):
98 """
99 Private slot to handle the activation of an entry.
100
101 @param idx reference to the entry index (QModelIndex)
102 """
103 self.__openHistory(QApplication.keyboardModifiers() & Qt.ControlModifier)
104
105 def __openHistoryInCurrentTab(self):
106 """
107 Private slot to open a history entry in the current browser tab.
108 """
109 self.__openHistory(False)
110
111 def __openHistoryInNewTab(self):
112 """
113 Private slot to open a history entry in a new browser tab.
114 """
115 self.__openHistory(True)
116
117 def __openHistory(self, newTab):
118 """
119 Private method to open a history entry.
120
121 @param newTab flag indicating to open the history entry in a new tab (boolean)
122 """
123 idx = self.historyTree.currentIndex()
124 if newTab:
125 self.emit(SIGNAL("newUrl(const QUrl&, const QString&)"),
126 idx.data(HistoryModel.UrlRole).toUrl(),
127 idx.data(HistoryModel.TitleRole).toString())
128 else:
129 self.emit(SIGNAL("openUrl(const QUrl&, const QString&)"),
130 idx.data(HistoryModel.UrlRole).toUrl(),
131 idx.data(HistoryModel.TitleRole).toString())
132
133 def __copyHistory(self):
134 """
135 Private slot to copy a history entry's URL to the clipboard.
136 """
137 idx = self.historyTree.currentIndex()
138 if not idx.parent().isValid():
139 return
140
141 url = idx.data(HistoryModel.UrlStringRole).toString()
142
143 clipboard = QApplication.clipboard()
144 clipboard.setText(url)

eric ide

mercurial