/***************************************************************************
 *   Copyright (c) 2009  Peter Mylemans <peter.mylemans@gmail.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) 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include "MovieView.h"
#include "models/Movie.h"

MovieView::MovieView()
{
    setupUi(this);
    viewPoster->setScene(new QGraphicsScene(viewPoster));
    viewPoster->scene()->setBackgroundBrush(palette().background());
}

MovieView::~MovieView()
{
}

bool MovieView::supportsModelType(const QString &identifier) const
{
    Q_UNUSED(identifier);

    // TODO: use identifier. must be falkor-movie.
    return true;
}

void MovieView::updateForModel(ContextModel *model)
{
    Movie *movie = static_cast<Movie*>(model);
    lblTitle->setText(movie->title());
    lblTagline->setText(movie->tagline());
    lblPlot->setText(movie->plot());

    viewPoster->scene()->addPixmap(movie->poster());
    QSize s = movie->poster().size();
    viewPoster->fitInView(-5,-5, s.width() + 5, s.height() + 5, Qt::KeepAspectRatio);

    QString details;
    bool first = true;
    foreach (Movie::Genre genre, movie->genres())
    {
        if (!first) details.append(", ");
        details.append(Movie::genreString(genre));
        if (first) first = false;
    }
    details.append("\n");
    details.append(QString("Released in %1").arg(movie->year()));
    details.append("\n");
    details.append("\n");
    details.append(QString("Runtime: %1 min").arg(movie->runtime()));
    details.append("\n");
    details.append(QString("Rating: %1 / 10").arg((float)movie->rating() / 10));
    details.append("\n");
    lblDetails->setText(details);

    QString actors;
    foreach (Movie::ActorRole actor, movie->actors())
    {
        actors.append(QString("%1 (%2)\n").arg(actor.actor).arg(actor.role));
    }
    lblActors->setText(actors);

    // TODO: use other fields
}

void MovieView::add()
{
}

void MovieView::edit()
{
}
