/* ============================================================
 * File  : tetrahedron.cpp
 * Author: Stephane Gibault
 * Date  : Sun Feb 4 2007
 * Description :
 *
 * 
 *  (C) 2007 by Stephane Gibault
 *
 * 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, 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.
 *
 * ============================================================ */
#include <QtGui>
#include <QDropEvent>
#include "panelmedia.h"
#include "media.h"

panelmedia::panelmedia ( QWidget * parent )
    : QFrame(parent)
{
	myparent = parent;
	this->setAcceptDrops(true);
	this->setMouseTracking(true);
	this->setAutoFillBackground(false);
	wg_pix_001.load(":/Interface/Interface/fond_media.png");
	islocked = 0;

	action_load = new QAction(tr("Ajouter des medias"), this);
	action_load->setIcon ( QIcon(":/Interface/Interface/open.png") );

	connect(action_load, SIGNAL(triggered()), this, SLOT(f_load_media()));
}

void panelmedia::f_load_media()
{
	emit load_media();
}

void panelmedia::contextMenuEvent(QContextMenuEvent *event)
{
	if ( islocked == 0 )
	{
		QMenu menu(this);
		menu.addAction(action_load);
		menu.exec(event->globalPos());
	}
}

void panelmedia::dragEnterEvent(QDragEnterEvent *event)
{
	event->acceptProposedAction();
}

// **********************************
// *** AJOUTER LE MEDIA AU PROJET ***
// **********************************
void panelmedia::dropEvent(QDropEvent *event)
{
	drop_x = event->pos().x();
	drop_y = event->pos().y();

	if ( event->mimeData()->hasUrls() == true )
	{
		QList<QUrl> myurl = event->mimeData()->urls();
		wl_pathname = myurl[0].toString(QUrl::None);
		emit drop_to_panel();
	}
}

Qt::DropActions panelmedia::supportedDropActions () const
{
	// returns what actions are supported when dropping
	return Qt::CopyAction | Qt::MoveAction;
}

// ********************************
// *** DESSIN DU FOND DU WIDGET ***
// ********************************

void panelmedia::paintEvent(QPaintEvent *)
{
	QPainter p;
	p.begin(this);
	p.setPen(Qt::NoPen);
	p.drawPixmap((this->width() - wg_pix_001.width())/2,((this->height() - wg_pix_001.height())/2)-20,wg_pix_001);
	p.setPen(QColor(250,250,250));
	p.drawText(QRect(0,((this->height() - wg_pix_001.height())/2)+wg_pix_001.height()+20,this->width(),20), Qt::AlignCenter,tr("Deposez les medias de votre DVD ici"));
	p.end();
}

