src/eric7/WebBrowser/UrlBar/FavIconLabel.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 14
15 class FavIconLabel(QLabel): 15 class FavIconLabel(QLabel):
16 """ 16 """
17 Class implementing the label to show the web site icon. 17 Class implementing the label to show the web site icon.
18 """ 18 """
19
19 def __init__(self, parent=None): 20 def __init__(self, parent=None):
20 """ 21 """
21 Constructor 22 Constructor
22 23
23 @param parent reference to the parent widget (QWidget) 24 @param parent reference to the parent widget (QWidget)
24 """ 25 """
25 super().__init__(parent) 26 super().__init__(parent)
26 27
27 self.__browser = None 28 self.__browser = None
28 self.__dragStartPos = QPoint() 29 self.__dragStartPos = QPoint()
29 30
30 self.setFocusPolicy(Qt.FocusPolicy.NoFocus) 31 self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
31 self.setCursor(Qt.CursorShape.ArrowCursor) 32 self.setCursor(Qt.CursorShape.ArrowCursor)
32 self.setMinimumSize(16, 16) 33 self.setMinimumSize(16, 16)
33 self.resize(16, 16) 34 self.resize(16, 16)
34 35
35 self.__browserIconChanged() 36 self.__browserIconChanged()
36 37
37 def __browserIconChanged(self): 38 def __browserIconChanged(self):
38 """ 39 """
39 Private slot to set the icon. 40 Private slot to set the icon.
40 """ 41 """
41 if self.__browser: 42 if self.__browser:
42 self.setPixmap( 43 self.setPixmap(self.__browser.icon().pixmap(16, 16))
43 self.__browser.icon().pixmap(16, 16)) 44
44
45 def __clearIcon(self): 45 def __clearIcon(self):
46 """ 46 """
47 Private slot to clear the icon. 47 Private slot to clear the icon.
48 """ 48 """
49 self.setPixmap(QPixmap()) 49 self.setPixmap(QPixmap())
50 50
51 def setBrowser(self, browser): 51 def setBrowser(self, browser):
52 """ 52 """
53 Public method to set the browser connection. 53 Public method to set the browser connection.
54 54
55 @param browser reference to the browser widegt (HelpBrowser) 55 @param browser reference to the browser widegt (HelpBrowser)
56 """ 56 """
57 self.__browser = browser 57 self.__browser = browser
58 self.__browser.loadFinished.connect(self.__browserIconChanged) 58 self.__browser.loadFinished.connect(self.__browserIconChanged)
59 self.__browser.faviconChanged.connect(self.__browserIconChanged) 59 self.__browser.faviconChanged.connect(self.__browserIconChanged)
60 self.__browser.loadStarted.connect(self.__clearIcon) 60 self.__browser.loadStarted.connect(self.__clearIcon)
61 61
62 def mousePressEvent(self, evt): 62 def mousePressEvent(self, evt):
63 """ 63 """
64 Protected method to handle mouse press events. 64 Protected method to handle mouse press events.
65 65
66 @param evt reference to the mouse event (QMouseEvent) 66 @param evt reference to the mouse event (QMouseEvent)
67 """ 67 """
68 if evt.button() == Qt.MouseButton.LeftButton: 68 if evt.button() == Qt.MouseButton.LeftButton:
69 self.__dragStartPos = evt.position().toPoint() 69 self.__dragStartPos = evt.position().toPoint()
70 super().mousePressEvent(evt) 70 super().mousePressEvent(evt)
71 71
72 def mouseReleaseEvent(self, evt): 72 def mouseReleaseEvent(self, evt):
73 """ 73 """
74 Protected method to handle mouse release events. 74 Protected method to handle mouse release events.
75 75
76 @param evt reference to the mouse event (QMouseEvent) 76 @param evt reference to the mouse event (QMouseEvent)
77 """ 77 """
78 if evt.button() == Qt.MouseButton.LeftButton: 78 if evt.button() == Qt.MouseButton.LeftButton:
79 self.__showPopup(evt.globalPosition().toPoint()) 79 self.__showPopup(evt.globalPosition().toPoint())
80 super().mouseReleaseEvent(evt) 80 super().mouseReleaseEvent(evt)
81 81
82 def mouseMoveEvent(self, evt): 82 def mouseMoveEvent(self, evt):
83 """ 83 """
84 Protected method to handle mouse move events. 84 Protected method to handle mouse move events.
85 85
86 @param evt reference to the mouse event (QMouseEvent) 86 @param evt reference to the mouse event (QMouseEvent)
87 """ 87 """
88 if ( 88 if (
89 evt.button() == Qt.MouseButton.LeftButton and ( 89 evt.button() == Qt.MouseButton.LeftButton
90 (evt.position().toPoint() - 90 and (
91 self.__dragStartPos).manhattanLength() > 91 (evt.position().toPoint() - self.__dragStartPos).manhattanLength()
92 QApplication.startDragDistance() 92 > QApplication.startDragDistance()
93 ) and self.__browser is not None 93 )
94 and self.__browser is not None
94 ): 95 ):
95 drag = QDrag(self) 96 drag = QDrag(self)
96 mimeData = QMimeData() 97 mimeData = QMimeData()
97 title = self.__browser.title() 98 title = self.__browser.title()
98 if title == "": 99 if title == "":
102 p = self.pixmap() 103 p = self.pixmap()
103 if p: 104 if p:
104 drag.setPixmap(p) 105 drag.setPixmap(p)
105 drag.setMimeData(mimeData) 106 drag.setMimeData(mimeData)
106 drag.exec() 107 drag.exec()
107 108
108 def __showPopup(self, pos): 109 def __showPopup(self, pos):
109 """ 110 """
110 Private method to show the site info popup. 111 Private method to show the site info popup.
111 112
112 @param pos position the popup should be shown at 113 @param pos position the popup should be shown at
113 @type QPoint 114 @type QPoint
114 """ 115 """
115 if self.__browser is None: 116 if self.__browser is None:
116 return 117 return
117 118
118 url = self.__browser.url() 119 url = self.__browser.url()
119 if url.isValid() and url.scheme() not in [ 120 if url.isValid() and url.scheme() not in ["eric", "about", "data", "chrome"]:
120 "eric", "about", "data", "chrome"]:
121 from ..SiteInfo.SiteInfoWidget import SiteInfoWidget 121 from ..SiteInfo.SiteInfoWidget import SiteInfoWidget
122
122 info = SiteInfoWidget(self.__browser, self) 123 info = SiteInfoWidget(self.__browser, self)
123 info.showAt(pos) 124 info.showAt(pos)

eric ide

mercurial