#from __future__ import unicode_literals
# -*- coding: utf-8 -*-
from __future__ import division

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Cache(QGraphicsPolygonItem):
    """cache place sur le plateau"""
    def __init__(self, plateau, numCache = 0, parent=None):
        """initialisation de la fenetre"""
        super (Cache, self).__init__()
        self.parent = plateau
        self.plateau = plateau
        self.numCache = numCache
        self.transparence = 130
        self.setVisible(False)
        self.plateau.addItem(self)
        self.setFlag(QGraphicsItem.ItemIsFocusable)
        self.setAcceptHoverEvents(True)

    def afficher(self, actif, listeCases = []):
        """affiche le cache sur la liste des cases en parametre"""
        """met a jour l'affichage des cases selon les parametres enregistres pour le cache"""
        if actif and len(listeCases) > 0:
            if not self.isVisible():
                self.setPolygon(self.plateau.polygoneAgglo(listeCases))
                self.setBrush(QColor(0,0,0,130))
                pinceau = QPen(QColor("black"))
                pinceau.setWidth(10)
                self.setPen(pinceau)
                text = QGraphicsTextItem(QString.fromUtf8(str(self.numCache)))
                pos = self.plateau.cases[self.plateau.coordCentreListeCases(listeCases)].centreGraphique
                text.setPos(self.mapFromScene(pos))
                police = QFont("Arial",30)
                police.setBold(True)
                text.setFont(police)
                text.setDefaultTextColor(QColor(50,50,50,180))     
                text.setParentItem(self)

        self.setVisible(actif and len(listeCases) > 0)
    
    def mousePressEvent(self, event):
        event.accept()

    def mouseReleaseEvent(self, event):
        event.accept()

    def mouseMoveEvent(self, event):
        event.accept()        

    def mouseDoubleClickEvent(self, event):
        event.accept()

    def hoverEnterEvent(self, event):
        event.accept()

    def hoverLeaveEvent(self, event):
        event.accept()

    def hoverMoveEvent(self, event):
        event.accept()
