track underMouse
This commit is contained in:
@@ -313,6 +313,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
def image_popup_callback(self, link: str, pos: QtCore.QPoint):
|
||||
if (filename := self.cache.lookup(link)) or (filename := self.downloader.get_filename(link)): # TODO: preload links
|
||||
self.image_popup = ImagePopup(filename, pos, link)
|
||||
self.image_popup.show()
|
||||
else:
|
||||
# TODO
|
||||
logger.warning(f"Image {link} is not in the cache")
|
||||
|
||||
@@ -21,16 +21,29 @@ class ImagePopup(QtWidgets.QLabel):
|
||||
self.setWindowFlags(QtCore.Qt.WindowType.ToolTip)
|
||||
self.installEventFilter(self)
|
||||
|
||||
# Prevent leaving the pop-up open when moving quickly out of the widget
|
||||
self.popup_timer = QtCore.QTimer()
|
||||
self.popup_timer.timeout.connect(self.check_mouse)
|
||||
|
||||
pixmap = QtGui.QPixmap(filename).scaled(
|
||||
settings.value("ImagePopup/w", type=int),
|
||||
settings.value("ImagePopup/h", type=int),
|
||||
aspectRatioMode=QtCore.Qt.AspectRatioMode.KeepAspectRatio,
|
||||
transformMode=QtCore.Qt.TransformationMode.SmoothTransformation
|
||||
)
|
||||
settings.value("ImagePopup/w", type=int),
|
||||
settings.value("ImagePopup/h", type=int),
|
||||
aspectRatioMode=QtCore.Qt.AspectRatioMode.KeepAspectRatio,
|
||||
transformMode=QtCore.Qt.TransformationMode.SmoothTransformation,
|
||||
)
|
||||
self.setPixmap(pixmap)
|
||||
|
||||
self.move(pos - QtCore.QPoint(pixmap.width()/2, pixmap.height()/2))
|
||||
self.show()
|
||||
self.move(pos - QtCore.QPoint(15, 15))
|
||||
|
||||
self.popup_timer.start(500)
|
||||
|
||||
def check_mouse(self):
|
||||
if not self.underMouse():
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
self.popup_timer.stop()
|
||||
super(ImagePopup, self).close()
|
||||
|
||||
def eventFilter(self, object: QtCore.QObject, event: QtCore.QEvent) -> bool:
|
||||
if event.type() == QtCore.QEvent.Type.Leave:
|
||||
|
||||
Reference in New Issue
Block a user