/*
Copyright (c) 2007 Matt Williams matt@milliams.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License or (at
your option) version 3 or, at the discretion of KDE e.V. (which shall
act as a proxy as in section 14 of the GPLv3), any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "keducaassessmentitemeditor.h"

#include "kqtiassessmentitem.h"
#include "kqtiitembody.h"
#include "kqtichoiceinteraction.h"

#include "block.h"

#include <QGraphicsWidget>
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <QLabel>
#include <QSpinBox>
#include <QTextEdit>

#include <kdebug.h>

KEducaAssessmentItemEditor::KEducaAssessmentItemEditor(QWidget* parent) : QWidget(parent), mModified(false)
{
    setupUi(this);
}

KEducaAssessmentItemEditor::~KEducaAssessmentItemEditor()
{
    
}

void KEducaAssessmentItemEditor::setItem(KQtiAssessmentItem* item)
{
    mItem = item;
    
    titleWidget->setText(mItem->title());
    
    if(itemBodyEditor->scene())
    {
        delete itemBodyEditor->scene();
    }
    QGraphicsScene* scene = new QGraphicsScene(itemBodyEditor);
    itemBodyEditor->setScene(scene);
    
    Block* baseBlock = new Block();
    baseBlock->setTitle("Item Body");
    scene->addItem(baseBlock);
    
    //QGraphicsLinearLayout* layout = dynamic_cast<QGraphicsLinearLayout*>(baseBlock->layout());
    
    QSpinBox* spinBox = new QSpinBox();
    QGraphicsProxyWidget *proxySpin = scene->addWidget(spinBox);
    baseBlock->addItem(proxySpin);
    proxySpin->show();
    //qDebug() << "spinBox->pos()" << spinBox->pos(); // = 0,0
    /*qDebug() << "proxySpin->pos()" << proxySpin->pos(); // = 0,0
    qDebug() << "proxySpin->scenePos()" << proxySpin->scenePos(); // = 0,0*/
    
    QLabel* label = new QLabel("jazz1");
    QGraphicsProxyWidget *proxy = scene->addWidget(label);
    baseBlock->addItem(proxy);
    label->show();
    
    //qDebug() << "label->pos()" << label->pos();
    //qDebug() << "proxy->pos()" << proxy->pos();
    //qDebug() << "proxy->scenePos()" << proxy->scenePos();
    
    QLabel* label2 = new QLabel("jazz2");
    /*QGraphicsProxyWidget *proxy2 = scene->addWidget(label2);
    baseBlock->addItem(proxy2);
    label2->show();*/
    
    //qDebug() << "label2->pos()" << label2->pos();
    //qDebug() << "proxy2->pos()" << proxy2->pos();
    
    QLabel* label3 = new QLabel("jazz3");
    /*QGraphicsProxyWidget *proxy3 = scene->addWidget(label3);
    baseBlock->addItem(proxy3);
    label3->show();*/
    //qDebug() << "proxy3->pos()" << proxy3->pos();
    
    QTextEdit* textEdit = new QTextEdit("");
    /*QGraphicsProxyWidget *proxy4 = scene->addWidget(textEdit);
    baseBlock->addItem(proxy4);
    textEdit->show();*/
    //qDebug() << "proxy4->pos()" << proxy4->pos();
    
    Block* block2 = new Block();
    block2->setTitle("Paragraph");
    /*baseBlock->addItem(block2);
    qDebug() << "block2->pos()" << block2->pos();
    qDebug() << "block2->scenePos()" << block2->scenePos();*/
    
    /*Block* block3 = new Block();
    block3->setTitle("Question");
    baseBlock->addItem(block3);*/
    
    baseBlock->addStretch();
    
    if(mItem->itemBody()) //If the itemBody is set..
    {
        foreach(KQtiBlock* block, mItem->itemBody()->blocks())
        {
            qDebug("Adding widget");
            
            if(dynamic_cast<KQtiChoiceInteraction*>(block))
            {
                qDebug("Adding KQtiChoiceInteraction");
                
                Block* block = new Block();
                block->setTitle("choiceInteraction");
                baseBlock->addItem(block);
            }
        }
    }
}

