from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

from panda3d.core import *

__all__ = ["QMouseWatcherNode"]


class QMouseWatcherNode(MouseWatcher):
    def __init__(self, parent):
        super().__init__()

        self.parent = parent

    def getMouse(self, *args, **kwargs):
        pos = self.parent.mapFromGlobal(QCursor.pos())

        rel_x = -1 + 2 * pos.x() / self.parent.width()
        rel_y = -1 + 2 * pos.y() / self.parent.height()

        rel_y = -rel_y

        return LPoint2(rel_x, rel_y)

    def hasMouse(self):
        return isinstance(self.parent, QWidget)
