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):
|
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")
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user