/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/

//-- Temporairement --
#include <ctime>
#include <cstdlib>

QLabel* Labels[4][18];
QLabel* NomsJoueurs[8];
QLabel* lblTotal1[4];
QLabel* lblTotal2[4];
QLabel* lblTotal3[4];
int Total1[4];
int Total2[4];
int Total3[4];

void frmScoreCard::init()
{
    int i;
    for (i = 0; i < 4; i++)
    {
	NomsJoueurs[i] = new QLabel( "", this );
	NomsJoueurs[i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	NomsJoueurs[i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	NomsJoueurs[i]->setGeometry( refNoms9->x(), refNoms9->y()+i*35.0f, refNoms9->width(), refNoms9->height());
	NomsJoueurs[i]->setBackgroundOrigin( QWidget::ParentOrigin );		
	NomsJoueurs[i+4] = new QLabel( "", this );
	NomsJoueurs[i+4]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	NomsJoueurs[i+4]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	NomsJoueurs[i+4]->setGeometry( refNoms18->x(), refNoms18->y()+i*35.0f, refNoms18->width(), refNoms18->height());
	NomsJoueurs[i+4]->setBackgroundOrigin( QWidget::ParentOrigin );		

	lblTotal1[i] = new QLabel( "", this );
	lblTotal1[i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	lblTotal1[i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	lblTotal1[i]->setGeometry( refTotal1->x(), refTotal1->y()+i*refTotal1->height(), refTotal1->width(), refTotal1->height());
	lblTotal1[i]->setBackgroundOrigin( QWidget::ParentOrigin );		
	lblTotal2[i] = new QLabel( "", this );
	lblTotal2[i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	lblTotal2[i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	lblTotal2[i]->setGeometry( refTotal2->x(), refTotal2->y()+i*refTotal2->height(), refTotal2->width(), refTotal2->height());
	lblTotal2[i]->setBackgroundOrigin( QWidget::ParentOrigin );		
	lblTotal3[i] = new QLabel( "", this );
	lblTotal3[i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	lblTotal3[i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	lblTotal3[i]->setGeometry( refTotal3->x(), refTotal3->y()+i*refTotal3->height(), refTotal3->width(), refTotal3->height());
	lblTotal3[i]->setBackgroundOrigin( QWidget::ParentOrigin );		
	}
    for (i = 0; i < 9; i++)
    {
	Labels[0][i] = new QLabel( "", this );
	Labels[0][i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[0][i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[0][i]->setGeometry( lblRef1->x()+i*lblRef1->width(), lblRef1->y(), lblRef1->width(), lblRef1->height());
	Labels[0][i]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[0][i+9] = new QLabel( "", this );
	Labels[0][i+9]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[0][i+9]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[0][i+9]->setGeometry( lblRef2->x()+i*lblRef2->width(), lblRef2->y(), lblRef2->width(), lblRef2->height());
	Labels[0][i+9]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[1][i] = new QLabel( "", this );
	Labels[1][i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[1][i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[1][i]->setGeometry( lblRef1->x()+i*lblRef1->width(), lblRef1->y()+lblRef1->height(), lblRef1->width(), lblRef1->height());
	Labels[1][i]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[1][i+9] = new QLabel( "", this );
	Labels[1][i+9]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[1][i+9]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[1][i+9]->setGeometry( lblRef2->x()+i*lblRef2->width(), lblRef2->y()+lblRef2->height(), lblRef2->width(), lblRef2->height());
	Labels[1][i+9]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[2][i] = new QLabel( "", this );
	Labels[2][i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[2][i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[2][i]->setGeometry( lblRef1->x()+i*lblRef1->width(), lblRef1->y()+2*lblRef1->height(), lblRef1->width(), lblRef1->height());
	Labels[2][i]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[2][i+9] = new QLabel( "", this );
	Labels[2][i+9]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[2][i+9]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[2][i+9]->setGeometry( lblRef2->x()+i*lblRef2->width(), lblRef2->y()+2*lblRef2->height(), lblRef2->width(), lblRef2->height());
	Labels[2][i+9]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[3][i] = new QLabel( "", this );
	Labels[3][i]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[3][i]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[3][i]->setGeometry( lblRef1->x()+i*lblRef1->width(), lblRef1->y()+3*lblRef1->height(), lblRef1->width(), lblRef1->height());
	Labels[3][i]->setBackgroundOrigin( QWidget::ParentOrigin );
	Labels[3][i+9] = new QLabel( "", this );
	Labels[3][i+9]->setFont(QFont("Comic Sans MS",12,QFont::Bold));
	Labels[3][i+9]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
	Labels[3][i+9]->setGeometry( lblRef2->x()+i*lblRef2->width(), lblRef2->y()+3*lblRef2->height(), lblRef2->width(), lblRef2->height());
	Labels[3][i+9]->setBackgroundOrigin( QWidget::ParentOrigin );
    }
}

void frmScoreCard::setup(CPartie* Partie)
{
    int i,j;
    if (Partie->getJoueurs().size() == 1)
    {
	txtOrdre1->hide();
	txtOrdre2->hide();
    } else {
	txtOrdre1->show();
	txtOrdre2->show();	
    }
	if (Partie->getTerrains().size() == Partie->getJoueurs()[0].getPointage().size())
	{
		txtOrdre1->setText("Positions finales!");
		txtOrdre2->setText("Positions finales!");
	}
	else
	{
		txtOrdre1->setText("Prochain ordre de jeu");
		txtOrdre2->setText("Prochain ordre de jeu");
	}
	for (i = 0; i < 4; i++)
	{
		Total1[i] = 0;
		Total2[i] = 0;
		Total3[i] = 0;
	}
    std::vector<CJoueur>::const_iterator itjoueur;
    std::vector<int>::const_iterator itpointage;
    if (Partie->getTerrains().size() == 9)
    {
	lblTrousHaut->setText( QString( "Total de tous\nles trous." ) );
	this->setMinimumSize( QSize(675,280) );
	this->setMaximumSize( QSize(675,280) );
	btnQuit->setGeometry( 674/2-btnQuit->width()/2, 240, 210, 30 );
    } else {
	lblTrousHaut->setText( QString( "Total des\ntrous 1 à 9." ) );
	this->setMinimumSize( QSize(780,500) );	
	this->setMaximumSize( QSize(780,500) );
	btnQuit->setGeometry( 780/2-btnQuit->width()/2, 460,210, 30 );
    }
    i = 0;
    j = 0;
	QPixmap TmpPixmap;
	QPainter TmpPainter;
    for (itjoueur = Partie->getJoueurs().begin(); itjoueur != Partie->getJoueurs().end(); ++itjoueur)
    {
		TmpPixmap.load("editeur/images/framenoms.png");
		TmpPainter.begin( &TmpPixmap );
		TmpPainter.setFont( QFont("Comis Sans MS",12,QFont::Bold) );
		int x = NomsJoueurs[i]->width()/2.0f - TmpPainter.fontMetrics().width((*itjoueur).getNom())/2.0f;
		TmpPainter.drawText( x, NomsJoueurs[i]->height()-12, (*itjoueur).getNom() );
		TmpPainter.end();
		NomsJoueurs[i]->setPixmap(TmpPixmap);
		NomsJoueurs[i+4]->setPixmap(TmpPixmap);
		j=0;
		for (itpointage = (*itjoueur).getPointage().begin(); itpointage != (*itjoueur).getPointage().end(); ++itpointage)
		{
			if (j < 9) Total1[i]+=(*itpointage);
			else Total2[i]+=(*itpointage);
			Total3[i]+=(*itpointage);
			lblTotal1[i]->setText(QString::number(Total1[i]));
			lblTotal2[i]->setText(QString::number(Total2[i]));
			lblTotal3[i]->setText(QString::number(Total3[i]));
			Labels[i][j]->setText(QString::number(*itpointage));
			j++;
		}
		i++;
    }
}
