track underMouse

This commit is contained in:
dries.k
2022-08-28 21:24:41 +02:00
parent bb6aa70890
commit 6dc97dda27
2 changed files with 24 additions and 10 deletions

View File

@@ -313,6 +313,7 @@ class MainApplication(QtWidgets.QApplication):
def image_popup_callback(self, link: str, pos: QtCore.QPoint): 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 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 = ImagePopup(filename, pos, link)
self.image_popup.show()
else: else:
# TODO # TODO
logger.warning(f"Image {link} is not in the cache") logger.warning(f"Image {link} is not in the cache")

View File

@@ -20,18 +20,31 @@ class ImagePopup(QtWidgets.QLabel):
self.setWindowFlags(QtCore.Qt.WindowType.ToolTip) self.setWindowFlags(QtCore.Qt.WindowType.ToolTip)
self.installEventFilter(self) self.installEventFilter(self)
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
)
self.setPixmap(pixmap)
self.move(pos - QtCore.QPoint(pixmap.width()/2, pixmap.height()/2)) # Prevent leaving the pop-up open when moving quickly out of the widget
self.show() 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,
)
self.setPixmap(pixmap)
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: def eventFilter(self, object: QtCore.QObject, event: QtCore.QEvent) -> bool:
if event.type() == QtCore.QEvent.Type.Leave: if event.type() == QtCore.QEvent.Type.Leave:
# Close the pop-up on mouse leave # Close the pop-up on mouse leave