WebBrowser/WebBrowserTabBar.py

branch
QtWebEngine
changeset 4779
173e0d2ab1f9
parent 4726
c26e2a2dc0cb
child 4900
32f940762654
equal deleted inserted replaced
4776:7f4c8e5f3385 4779:173e0d2ab1f9
35 self.__previewPopup = None 35 self.__previewPopup = None
36 self.__currentTabPreviewIndex = -1 36 self.__currentTabPreviewIndex = -1
37 37
38 self.setMouseTracking(True) 38 self.setMouseTracking(True)
39 39
40 # TODO: page preview 40 def __showTabPreview(self):
41 ## def __showTabPreview(self): 41 """
42 ## """ 42 Private slot to show the tab preview.
43 ## Private slot to show the tab preview. 43 """
44 ## """ 44 indexedBrowser = self.__tabWidget.browserAt(
45 ## indexedBrowser = self.__tabWidget.browserAt( 45 self.__currentTabPreviewIndex)
46 ## self.__currentTabPreviewIndex) 46 currentBrowser = self.__tabWidget.currentBrowser()
47 ## currentBrowser = self.__tabWidget.currentBrowser() 47
48 ## 48 if indexedBrowser is None or currentBrowser is None:
49 ## if indexedBrowser is None or currentBrowser is None: 49 return
50 ## return 50
51 ## 51 # no previews during load
52 ## # no previews during load 52 if indexedBrowser.progress() != 0:
53 ## if indexedBrowser.progress() != 0: 53 return
54 ## return 54
55 ## 55 w = self.tabSizeHint(self.__currentTabPreviewIndex).width()
56 ## w = self.tabSizeHint(self.__currentTabPreviewIndex).width() 56 h = int(w * currentBrowser.height() / currentBrowser.width())
57 ## h = int(w * currentBrowser.height() / currentBrowser.width()) 57
58 ## 58 self.__previewPopup = E5PassivePopup(self)
59 ## self.__previewPopup = E5PassivePopup(self) 59 self.__previewPopup.setFrameShape(QFrame.StyledPanel)
60 ## self.__previewPopup.setFrameShape(QFrame.StyledPanel) 60 self.__previewPopup.setFrameShadow(QFrame.Plain)
61 ## self.__previewPopup.setFrameShadow(QFrame.Plain) 61 self.__previewPopup.setFixedSize(w, h)
62 ## self.__previewPopup.setFixedSize(w, h) 62
63 ## 63 from .WebBrowserSnap import renderTabPreview
64 ## from .HelpSnap import renderTabPreview 64 label = QLabel()
65 ## label = QLabel() 65 label.setPixmap(renderTabPreview(indexedBrowser, w, h))
66 ## label.setPixmap(renderTabPreview(indexedBrowser.page(), w, h)) 66
67 ## 67 self.__previewPopup.setView(label)
68 ## self.__previewPopup.setView(label) 68 self.__previewPopup.layout().setAlignment(Qt.AlignTop)
69 ## self.__previewPopup.layout().setAlignment(Qt.AlignTop) 69 self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0)
70 ## self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0) 70
71 ## 71 tr = self.tabRect(self.__currentTabPreviewIndex)
72 ## tr = self.tabRect(self.__currentTabPreviewIndex) 72 pos = QPoint(tr.x(), tr.y() + tr.height())
73 ## pos = QPoint(tr.x(), tr.y() + tr.height()) 73
74 ## 74 self.__previewPopup.show(self.mapToGlobal(pos))
75 ## self.__previewPopup.show(self.mapToGlobal(pos))
76 75
77 def mouseMoveEvent(self, evt): 76 def mouseMoveEvent(self, evt):
78 """ 77 """
79 Protected method to handle mouse move events. 78 Protected method to handle mouse move events.
80 79
83 if self.count() == 1: 82 if self.count() == 1:
84 return 83 return
85 84
86 super(WebBrowserTabBar, self).mouseMoveEvent(evt) 85 super(WebBrowserTabBar, self).mouseMoveEvent(evt)
87 86
88 # TODO: page preview 87 if Preferences.getWebBrowser("ShowPreview"):
89 ## if Preferences.getWebBrowser("ShowPreview"): 88 # Find the tab under the mouse
90 ## # Find the tab under the mouse 89 i = 0
91 ## i = 0 90 tabIndex = -1
92 ## tabIndex = -1 91 while i < self.count() and tabIndex == -1:
93 ## while i < self.count() and tabIndex == -1: 92 if self.tabRect(i).contains(evt.pos()):
94 ## if self.tabRect(i).contains(evt.pos()): 93 tabIndex = i
95 ## tabIndex = i 94 i += 1
96 ## i += 1 95
97 ## 96 # If found and not the current tab then show tab preview
98 ## # If found and not the current tab then show tab preview 97 if tabIndex != -1 and \
99 ## if tabIndex != -1 and \ 98 tabIndex != self.currentIndex() and \
100 ## tabIndex != self.currentIndex() and \ 99 self.__currentTabPreviewIndex != tabIndex and \
101 ## self.__currentTabPreviewIndex != tabIndex and \ 100 evt.buttons() == Qt.NoButton:
102 ## evt.buttons() == Qt.NoButton: 101 self.__currentTabPreviewIndex = tabIndex
103 ## self.__currentTabPreviewIndex = tabIndex 102 QTimer.singleShot(200, self.__showTabPreview)
104 ## QTimer.singleShot(200, self.__showTabPreview) 103
105 ## 104 # If current tab or not found then hide previous tab preview
106 ## # If current tab or not found then hide previous tab preview 105 if tabIndex == self.currentIndex() or \
107 ## if tabIndex == self.currentIndex() or \ 106 tabIndex == -1:
108 ## tabIndex == -1: 107 if self.__previewPopup is not None:
109 ## if self.__previewPopup is not None: 108 self.__previewPopup.hide()
110 ## self.__previewPopup.hide() 109 self.__currentTabPreviewIndex = -1
111 ## self.__currentTabPreviewIndex = -1
112 110
113 def leaveEvent(self, evt): 111 def leaveEvent(self, evt):
114 """ 112 """
115 Protected method to handle leave events. 113 Protected method to handle leave events.
116 114
117 @param evt reference to the leave event (QEvent) 115 @param evt reference to the leave event (QEvent)
118 """ 116 """
119 # TODO: page preview 117 if Preferences.getWebBrowser("ShowPreview"):
120 ## if Preferences.getWebBrowser("ShowPreview"): 118 # If leave tabwidget then hide previous tab preview
121 ## # If leave tabwidget then hide previous tab preview 119 if self.__previewPopup is not None:
122 ## if self.__previewPopup is not None: 120 self.__previewPopup.hide()
123 ## self.__previewPopup.hide() 121 self.__currentTabPreviewIndex = -1
124 ## self.__currentTabPreviewIndex = -1
125 122
126 super(WebBrowserTabBar, self).leaveEvent(evt) 123 super(WebBrowserTabBar, self).leaveEvent(evt)
127 124
128 def mousePressEvent(self, evt): 125 def mousePressEvent(self, evt):
129 """ 126 """
130 Protected method to handle mouse press events. 127 Protected method to handle mouse press events.
131 128
132 @param evt reference to the mouse press event (QMouseEvent) 129 @param evt reference to the mouse press event (QMouseEvent)
133 """ 130 """
134 # TODO: page preview 131 if Preferences.getWebBrowser("ShowPreview"):
135 ## if Preferences.getWebBrowser("ShowPreview"): 132 if self.__previewPopup is not None:
136 ## if self.__previewPopup is not None: 133 self.__previewPopup.hide()
137 ## self.__previewPopup.hide() 134 self.__currentTabPreviewIndex = -1
138 ## self.__currentTabPreviewIndex = -1
139 135
140 super(WebBrowserTabBar, self).mousePressEvent(evt) 136 super(WebBrowserTabBar, self).mousePressEvent(evt)
141 137
142 def event(self, evt): 138 def event(self, evt):
143 """ 139 """
147 handling of all others to the superclass. 143 handling of all others to the superclass.
148 144
149 @param evt reference to the event to be handled (QEvent) 145 @param evt reference to the event to be handled (QEvent)
150 @return flag indicating, if the event was handled (boolean) 146 @return flag indicating, if the event was handled (boolean)
151 """ 147 """
152 # TODO: page preview 148 if evt.type() == QEvent.ToolTip and \
153 ## if evt.type() == QEvent.ToolTip and \ 149 Preferences.getWebBrowser("ShowPreview"):
154 ## Preferences.getWebBrowser("ShowPreview"): 150 # suppress tool tips if we are showing previews
155 ## # suppress tool tips if we are showing previews 151 evt.setAccepted(True)
156 ## evt.setAccepted(True) 152 return True
157 ## return True
158 153
159 return super(WebBrowserTabBar, self).event(evt) 154 return super(WebBrowserTabBar, self).event(evt)
160 155
161 def tabRemoved(self, index): 156 def tabRemoved(self, index):
162 """ 157 """
163 Public slot to handle the removal of a tab. 158 Public slot to handle the removal of a tab.
164 159
165 @param index index of the removed tab (integer) 160 @param index index of the removed tab (integer)
166 """ 161 """
167 pass 162 if Preferences.getWebBrowser("ShowPreview"):
168 # TODO: page preview 163 if self.__previewPopup is not None:
169 ## if Preferences.getWebBrowser("ShowPreview"): 164 self.__previewPopup.hide()
170 ## if self.__previewPopup is not None: 165 self.__currentTabPreviewIndex = -1
171 ## self.__previewPopup.hide()
172 ## self.__currentTabPreviewIndex = -1

eric ide

mercurial