#include "quizevaluation.h"

QuizEvaluation::QuizEvaluation( Controller *controller, QWidget *parent ) : QWidget( parent )
{
  setupUi( this );
  this->controller = controller;

  tlNumberOfQuestion->setText( QString::number( this->controller->getNumberOfQuestions() ) );
  tlTimePerQuestion->setText( this->controller->getTimePerQuestion() == 0
                              ? tr( "Unlimited" )
                              : QString::number( this->controller->getTimePerQuestion() ) + " s" );
  //Kategorienamen setzen
  QList< int > currentCategoryIds = this->controller->getCurrentCategoryIds();
  QString currentCategoryNames( "" );
  for( int i = 0; i < currentCategoryIds.length(); i++ )
    currentCategoryNames += this->controller->getCategoryNameAt( currentCategoryIds[ i ] ) + "; ";
  tlCategories->setText( currentCategoryNames );

  connect( pbMenu, SIGNAL( clicked( bool ) ), this->controller, SLOT( showMenu() ) );
  connect( pbRestart, SIGNAL( clicked( bool ) ), this->controller, SLOT( showQuiz() ) );
}

void QuizEvaluation::setValues( int numberOfTrueAnsweredQuestions, int numberOfQuestions, int totalTime )
{
  tlCorrect->setText( QString::number( numberOfTrueAnsweredQuestions ) + " / " + QString::number( numberOfQuestions ) );
  tlCorrectPercent->setText( QString::number( ( double )  numberOfTrueAnsweredQuestions / numberOfQuestions * 100 ) + " %" );
  tlTotalTime->setText( QString::number( totalTime ) + " s" );
  tlAverageTimePerQuestion->setText( QString::number( totalTime / numberOfQuestions ) + " s" );
}
