from __future__ import annotations

from silx.gui import qt
from tomwer.gui import icons


class LinkInfoFrame(qt.QLabel):

    def __init__(self, parent=None):
        super().__init__(parent)

        self._lockedIcon = icons.getQIcon("link")
        self._unlockedIcon = icons.getQIcon("link-slash")
        self._pixmapSize = qt.QSize(24, 24)

        lockIcon = qt.QLabel()
        lockIcon.setFrameShape(qt.QFrame.Shape.Box)
        self.setLocked(True)

    def setPixmapSize(self, w: int, h: int) -> None:
        self._pixmapSize = qt.QSize(w, h)

    def setLocked(self, locked: bool):
        icon = self._lockedIcon if locked else self._unlockedIcon
        pixmap = icon.pixmap(self._pixmapSize)
        self.setPixmap(pixmap)
        self._locked: bool = locked

    def isLocked(self) -> bool:
        return self._locked
