|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a specialized tab bar for the web browser. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import Qt, QPoint, QTimer, QEvent |
|
13 from PyQt5.QtWidgets import QFrame, QLabel |
|
14 |
|
15 from E5Gui.E5TabWidget import E5WheelTabBar |
|
16 from E5Gui.E5PassivePopup import E5PassivePopup |
|
17 |
|
18 import Preferences |
|
19 |
|
20 |
|
21 class WebBrowserTabBar(E5WheelTabBar): |
|
22 """ |
|
23 Class implementing the tab bar of the web browser. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget (WebBrowserTabWidget) |
|
30 """ |
|
31 super(WebBrowserTabBar, self).__init__(parent) |
|
32 |
|
33 self.__tabWidget = parent |
|
34 |
|
35 self.__previewPopup = None |
|
36 self.__currentTabPreviewIndex = -1 |
|
37 |
|
38 self.setMouseTracking(True) |
|
39 |
|
40 def __showTabPreview(self): |
|
41 """ |
|
42 Private slot to show the tab preview. |
|
43 """ |
|
44 pass |
|
45 # TODO: page preview |
|
46 ## indexedBrowser = self.__tabWidget.browserAt( |
|
47 ## self.__currentTabPreviewIndex) |
|
48 ## currentBrowser = self.__tabWidget.currentBrowser() |
|
49 ## |
|
50 ## if indexedBrowser is None or currentBrowser is None: |
|
51 ## return |
|
52 ## |
|
53 ## # no previews during load |
|
54 ## if indexedBrowser.progress() != 0: |
|
55 ## return |
|
56 ## |
|
57 ## w = self.tabSizeHint(self.__currentTabPreviewIndex).width() |
|
58 ## h = int(w * currentBrowser.height() / currentBrowser.width()) |
|
59 ## |
|
60 ## self.__previewPopup = E5PassivePopup(self) |
|
61 ## self.__previewPopup.setFrameShape(QFrame.StyledPanel) |
|
62 ## self.__previewPopup.setFrameShadow(QFrame.Plain) |
|
63 ## self.__previewPopup.setFixedSize(w, h) |
|
64 ## |
|
65 ## from .HelpSnap import renderTabPreview |
|
66 ## label = QLabel() |
|
67 ## label.setPixmap(renderTabPreview(indexedBrowser.page(), w, h)) |
|
68 ## |
|
69 ## self.__previewPopup.setView(label) |
|
70 ## self.__previewPopup.layout().setAlignment(Qt.AlignTop) |
|
71 ## self.__previewPopup.layout().setContentsMargins(0, 0, 0, 0) |
|
72 ## |
|
73 ## tr = self.tabRect(self.__currentTabPreviewIndex) |
|
74 ## pos = QPoint(tr.x(), tr.y() + tr.height()) |
|
75 ## |
|
76 ## self.__previewPopup.show(self.mapToGlobal(pos)) |
|
77 |
|
78 def mouseMoveEvent(self, evt): |
|
79 """ |
|
80 Protected method to handle mouse move events. |
|
81 |
|
82 @param evt reference to the mouse move event (QMouseEvent) |
|
83 """ |
|
84 if self.count() == 1: |
|
85 return |
|
86 |
|
87 E5WheelTabBar.mouseMoveEvent(self, evt) |
|
88 |
|
89 # TODO: page preview |
|
90 ## if Preferences.getHelp("ShowPreview"): |
|
91 ## # Find the tab under the mouse |
|
92 ## i = 0 |
|
93 ## tabIndex = -1 |
|
94 ## while i < self.count() and tabIndex == -1: |
|
95 ## if self.tabRect(i).contains(evt.pos()): |
|
96 ## tabIndex = i |
|
97 ## i += 1 |
|
98 ## |
|
99 ## # If found and not the current tab then show tab preview |
|
100 ## if tabIndex != -1 and \ |
|
101 ## tabIndex != self.currentIndex() and \ |
|
102 ## self.__currentTabPreviewIndex != tabIndex and \ |
|
103 ## evt.buttons() == Qt.NoButton: |
|
104 ## self.__currentTabPreviewIndex = tabIndex |
|
105 ## QTimer.singleShot(200, self.__showTabPreview) |
|
106 ## |
|
107 ## # If current tab or not found then hide previous tab preview |
|
108 ## if tabIndex == self.currentIndex() or \ |
|
109 ## tabIndex == -1: |
|
110 ## if self.__previewPopup is not None: |
|
111 ## self.__previewPopup.hide() |
|
112 ## self.__currentTabPreviewIndex = -1 |
|
113 |
|
114 def leaveEvent(self, evt): |
|
115 """ |
|
116 Protected method to handle leave events. |
|
117 |
|
118 @param evt reference to the leave event (QEvent) |
|
119 """ |
|
120 # TODO: page preview |
|
121 ## if Preferences.getHelp("ShowPreview"): |
|
122 ## # If leave tabwidget then hide previous tab preview |
|
123 ## if self.__previewPopup is not None: |
|
124 ## self.__previewPopup.hide() |
|
125 ## self.__currentTabPreviewIndex = -1 |
|
126 |
|
127 E5WheelTabBar.leaveEvent(self, evt) |
|
128 |
|
129 def mousePressEvent(self, evt): |
|
130 """ |
|
131 Protected method to handle mouse press events. |
|
132 |
|
133 @param evt reference to the mouse press event (QMouseEvent) |
|
134 """ |
|
135 # TODO: page preview |
|
136 ## if Preferences.getHelp("ShowPreview"): |
|
137 ## if self.__previewPopup is not None: |
|
138 ## self.__previewPopup.hide() |
|
139 ## self.__currentTabPreviewIndex = -1 |
|
140 |
|
141 E5WheelTabBar.mousePressEvent(self, evt) |
|
142 |
|
143 def event(self, evt): |
|
144 """ |
|
145 Public method to handle event. |
|
146 |
|
147 This event handler just handles the tooltip event and passes the |
|
148 handling of all others to the superclass. |
|
149 |
|
150 @param evt reference to the event to be handled (QEvent) |
|
151 @return flag indicating, if the event was handled (boolean) |
|
152 """ |
|
153 # TODO: page preview |
|
154 ## if evt.type() == QEvent.ToolTip and \ |
|
155 ## Preferences.getHelp("ShowPreview"): |
|
156 ## # suppress tool tips if we are showing previews |
|
157 ## evt.setAccepted(True) |
|
158 ## return True |
|
159 |
|
160 return E5WheelTabBar.event(self, evt) |
|
161 |
|
162 def tabRemoved(self, index): |
|
163 """ |
|
164 Public slot to handle the removal of a tab. |
|
165 |
|
166 @param index index of the removed tab (integer) |
|
167 """ |
|
168 pass |
|
169 # TODO: page preview |
|
170 ## if Preferences.getHelp("ShowPreview"): |
|
171 ## if self.__previewPopup is not None: |
|
172 ## self.__previewPopup.hide() |
|
173 ## self.__currentTabPreviewIndex = -1 |