#include "answerexplanationwidget.h"

AnswerExplanationWidget::AnswerExplanationWidget( QWidget *parent ) : QWidget( parent )
{
  setupUi( this );

}

void AnswerExplanationWidget::setResultText( bool result )
{
  if( result ) tlResult->setText( tr( "You answered the question correctly!" ) );
  else tlResult->setText( tr( "You answered the question wrongly!" ) );
}

void AnswerExplanationWidget::setExplanationTexts( QList< QString > explanations )
{
  QGridLayout *gLayout = static_cast< QGridLayout* >( layout() );
  //delete explanations texts from last question
  while( gLayout->count() > 1 )
  {
    QWidget* widget = gLayout->itemAt( gLayout->count() - 1 )->widget();
    if( widget )
    {
      gLayout->removeWidget( widget );
      delete widget;
    }
  }

  //add explanation texts
  for( int i = 0; i < explanations.length(); i++ )
  {
    int rowCount = gLayout->rowCount();
    QLabel *label = new QLabel( explanations[ i ] );
    label->setWordWrap( true );
    gLayout->addWidget( label, rowCount, 0 );
  }
}


