# -*- coding: latin-1 -*-

from PySide.QtCore import Qt

class Posicion :
    def __init__( self, x=0, y=0, ancho=0, alto=0, angulo=0, orden=15 ) :
        self.x = x
        self.y = y
        self.ancho = ancho
        self.alto = alto
        self.angulo = angulo
        self.orden = int(orden)

    def copia( self ) :
        p = Posicion( self.x, self.y, self.ancho, self.alto, self.angulo, self.orden )
        return p

class TipoLetra :
    def __init__( self, nombre="", puntos=8, peso=50, siCursiva=False, siSubrayado=False, siTachado=False ) :
        self.nombre = nombre
        self.puntos = puntos
        self.peso = peso # 50 = normal, 75 = negrita, 25 = light,...
        self.siCursiva = siCursiva
        self.siSubrayado = siSubrayado
        self.siTachado = siTachado

    def __str__( self ) :
        cursiva = 1 if self.siCursiva else 0
        subrayado = 1 if self.siSubrayado else 0
        tachado = 1 if self.siTachado else 0
        return "%s,%d,-1,5,%d,%d,%d,%d,0,0"%( self.nombre, self.puntos, self.peso, cursiva, subrayado, tachado )

    def copia( self ) :
        t = TipoLetra( self.nombre, self.puntos, self.peso, self.siCursiva, self.siSubrayado, self.siTachado )
        return t

class Bloque :
    def __init__( self ) :
        self.siMovible = False
        for num, dato in enumerate(self.liVars) :
            var, tipo, ini = dato
            exec( "self.%s=ini"%var )
            self.liVars[num] = ( var, tipo )
    def tipoqt( self ) :
        return { 1:Qt.SolidLine, 2:Qt.DashLine, 3:Qt.DotLine, 4:Qt.DashDotLine, 5:Qt.DashDotDotLine, 0:Qt.NoPen }.get(self.tipo, Qt.SolidLine)

class Texto( Bloque ) :
    def __init__( self ) :
        self.liVars = [
                        ( "tipoLetra", "o", TipoLetra() ),
                        ( "posicion", "o", Posicion( 0, 0, 80, 16, 0 )),
                        ( "alineacion", "t", "i" ),
                        ( "colorTexto", "n", 0 ),
                        ( "colorFondo", "n", 0xFFFFFF ),
                        ( "valor", "tn", "")
                    ]
        Bloque.__init__( self )

    def copia( self ) :
        t = Texto()
        t.tipoLetra = self.tipoLetra.copia()
        t.posicion = self.posicion.copia()
        t.alineacion = self.alineacion
        t.colorTexto = self.colorTexto
        t.colorFondo = self.colorFondo
        t.valor = self.valor
        return t

class Imagen( Bloque ) :

    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 80, 0 ) ),
                        ( "pixmap", "t", None )
                    ]
        Bloque.__init__( self )

class Caja( Bloque ) :

    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 80, 0 ) ),
                        ( "color", "n", 0 ),
                        ( "colorRelleno", "n", -1 ),
                        ( "grosor", "n", 1 ),
                        ( "redEsquina", "n", 0 ),
                        ( "tipo", "n", 1 ), #1=SolidLine, 2=DashLine, 3=DotLine, 4=DashDotLine, 5=DashDotDotLine, 0=NoPen
                    ]
        Bloque.__init__( self )

    def copia( self ) :
        c = Caja()
        c.posicion = self.posicion.copia()
        c.color = self.color
        c.colorRelleno = self.colorRelleno
        c.grosor = self.grosor
        c.redEsquina = self.redEsquina
        c.tipo = self.tipo
        return c

class Circulo( Bloque ) :

    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 80, 0 ) ),
                        ( "color", "n", 0 ),
                        ( "colorRelleno", "n", -1 ),
                        ( "grosor", "n", 1 ),
                        ( "grados", "n", 0 ),
                        ( "tipo", "n", 1 ), #1=SolidLine, 2=DashLine, 3=DotLine, 4=DashDotLine, 5=DashDotDotLine, 0=Sin borde
                    ]
        Bloque.__init__( self )

class Pieza( Bloque ) :

    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 1, 0 ) ),
                        ( "pieza", "t", "p" ),
                        ( "fila", "n", 1 ),
                        ( "columna", "n", 1 ),
                    ]
        Bloque.__init__( self )

class Flecha( Bloque ) :
    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 1, 0 ) ),
                        ( "a1h8", "c", "a1h8" ),
                        ( "grosor", "n", 1 ), # ancho del trazo
                        ( "altocabeza", "n", 15 ), # alto de la cabeza
                        ( "tipo", "n", 1 ), #1=SolidLine, 2=DashLine, 3=DotLine, 4=DashDotLine, 5=DashDotDotLine
                        ( "destino", "t", "c" ), # c = centro, m = minimo
                        ( "anchoCasilla", "n", 1 ),
                        ( "color", "n", 0 ),
                        ( "colorinterior", "n", -1 ), # si es cerrada
                        ( "colorinterior2", "n", -1 ), # para el gradiente
                        ( "opacidad", "n", 1.0 ),
                        ( "redondeos", "l", False ),
                        ( "forma", "t", "a" ), # a = abierta -> , c = cerrada la cabeza, 1 = poligono cuadrado, 2 = poligono 1 punto base, 3 = poligono 1 punto base cabeza
                        ( "ancho", "n", 10 ), # ancho de la base de la flecha si es un poligono
                        ( "vuelo", "n", 5 ), # ancho adicional en la base
                        ( "descuelgue", "n", 2 ), # angulo de la base de la cabeza
                    ]
        Bloque.__init__( self )

class Marco( Bloque ) :

    def __init__( self ) :
        self.liVars = [
                        ( "posicion", "o", Posicion( 0, 0, 80, 80, 0 ) ),
                        ( "a1h8", "c", "a1h8" ),
                        ( "color", "n", 0 ),
                        ( "colorinterior", "n", -1 ),
                        ( "colorinterior2", "n", -1 ), # para el gradiente
                        ( "grosor", "n", 1 ),
                        ( "redEsquina", "n", 0 ),
                        ( "tipo", "n", 1 ), #1=SolidLine, 2=DashLine, 3=DotLine, 4=DashDotLine, 5=DashDotDotLine, 0=Sin borde
                        ( "opacidad", "n", 1.0 ),
                        ( "anchoCasilla", "n", 1 ),
                    ]
        Bloque.__init__( self )

