/*

  Copyright (C) 2009 Pierre Ducroquet <pinaraf@pinaraf.info>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "qfxvideo.h"
#include <QPainter>
#include <QRect>
#include <QDebug>
#include <Phonon/VideoWidget>
#include <Phonon/MediaSource>
#include <Phonon/VideoPlayer>

QFxVideo::QFxVideo(QFxItem *parent)
        : QFxItem(parent)
{
    setFlag(QGraphicsItem::ItemHasNoContents, false);

    m_player = new Phonon::VideoPlayer(Phonon::VideoCategory);
    connect(this, SIGNAL(destroyed()), m_player, SLOT(deleteLater()));

    m_proxy = new QGraphicsProxyWidget(this);
    m_proxy->setWidget(m_player);
    m_proxy->setVisible(true);
    m_proxy->resize(50, 50);
}

QFxVideo::QFxVideo(const QFxVideo & other)
        : QFxItem(qobject_cast<QFxItem*>(other.parent()))
{
}

void QFxVideo::setSource (const QString &src) {
    m_src = src;
    m_player->play(m_src);
    emit sourceChanged(src);
}

void QFxVideo::geometryChanged ( const QRectF & newGeometry, const QRectF & oldGeometry ) {
    m_proxy->resize(newGeometry.size());
}


QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Video,QFxVideo);
