/* ============================================================
 * File  : menu_editor.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 "menu_editor.h"

menu_editor::menu_editor ( QWidget * parent )
    : QLabel(parent)
{
	this->setAttribute(Qt::WA_DeleteOnClose);

	is_copy = 0;
	has_sound = 0;
	has_intro = 0;

	action_addone = new QAction(tr("Ajouter un bouton"), this);
	action_addone->setIcon ( QIcon(":/Interface/Interface/new.png") );
	action_addmul = new QAction(tr("Ajouter plusieurs boutons"), this);
	action_addmul->setIcon ( QIcon(":/Interface/Interface/newm.png") );

	action_customize = new QAction(tr("Image d'arriere plan"), this);
	action_customize->setIcon ( QIcon(":/Interface/Interface/btimg.png") );

	action_intro_load = new QAction(tr("Charger un media"), this);
	action_intro_load->setIcon ( QIcon(":/Interface/Interface/finder.png") );

	action_intro_calc = new QAction(tr("Transition animee"), this);
	action_intro_calc->setIcon ( QIcon(":/Interface/Interface/execute.png") );

	action_intro_cancel = new QAction(tr("Supprimer la video d'introduction"), this);
	action_intro_cancel->setIcon ( QIcon(":/Interface/Interface/trash.png") );
	action_paste = new QAction(tr("Coller le bouton"), this);
	action_paste->setIcon ( QIcon(":/Interface/Interface/paste.png") );

	action_zik_load = new QAction(tr("Charger une bande son"), this);
	action_zik_load->setIcon ( QIcon(":/Interface/Interface/finder.png") );
	action_zik_cancel = new QAction(tr("Supprimer la bande son"), this);
	action_zik_cancel->setIcon ( QIcon(":/Interface/Interface/trash.png") );

	action_color_overlays = new QAction(tr("Couleurs des overlays"), this);
	action_color_overlays->setIcon ( QIcon(":/Interface/Interface/customize.png") );

	connect(action_addone, SIGNAL(triggered()), this, SLOT(f_addone()));
	connect(action_addmul, SIGNAL(triggered()), this, SLOT(f_addmul()));
	connect(action_customize, SIGNAL(triggered()), this, SLOT(customize()));

	connect(action_intro_load, SIGNAL(triggered()), this, SLOT(f_load_intro()));
	connect(action_intro_cancel, SIGNAL(triggered()), this, SLOT(f_cancel_intro()));
	connect(action_zik_load, SIGNAL(triggered()), this, SLOT(f_load_zik()));
	connect(action_zik_cancel, SIGNAL(triggered()), this, SLOT(f_cancel_zik()));
	connect(action_paste, SIGNAL(triggered()), this, SLOT(f_paste()));
	connect(action_intro_calc, SIGNAL(triggered()), this, SLOT(f_calc()));
	connect(action_color_overlays, SIGNAL(triggered()), this, SLOT(f_coverl()));
}

void menu_editor::f_coverl()
{
	emit color_overlays();
}

void menu_editor::f_calc()
{
	emit intro_calc();
}

void menu_editor::f_paste()
{
	emit paste_menu();
}

void menu_editor::f_load_intro()
{
	emit loadintro();
}

void menu_editor::f_cancel_intro()
{
	emit cancelintro();
}

void menu_editor::f_load_zik()
{
	emit loadzik();
}

void menu_editor::f_cancel_zik()
{
	emit cancelzik();
}

void menu_editor::f_addone()
{
	emit addone();
}

void menu_editor::f_addmul()
{
	emit addmul();
}

void menu_editor::customize()
{
	emit customize_background();
}

void menu_editor::contextMenuEvent(QContextMenuEvent *event)
{
	xevent = event->x();
	yevent = event->y();

	QMenu menu(this);
	menu.addAction(action_addone);
	menu.addAction(action_addmul);
	menu.addSeparator();
	menu.addAction(action_customize);
	menu.addSeparator();
	menu.addAction(action_color_overlays);
	menu.addSeparator();
	QMenu *menuintro = menu.addMenu(QIcon(":/Interface/Interface/media.png"),tr("Video d'introduction"));
	menuintro->addAction(action_intro_load);
	menuintro->addAction(action_intro_calc);
	menuintro->addSeparator();
	menuintro->addAction(action_intro_cancel);
	QMenu *menuzik = menu.addMenu(QIcon(":/Interface/Interface/son.png"),tr("Bande son"));
	menuzik->addAction(action_zik_load);
	menuzik->addAction(action_zik_cancel);
	menu.addSeparator();
	if ( is_copy == 0 )
	{
		action_paste->setDisabled(true);
	}
	else
	{
		action_paste->setEnabled(true);
	}

	if ( has_sound == 1 )
	{
		action_zik_load->setDisabled(true);
		action_zik_cancel->setEnabled(true);
	}
	else
	{
		action_zik_load->setEnabled(true);
		action_zik_cancel->setDisabled(true);
	}

	if ( has_intro == 1 )
	{
		action_intro_cancel->setEnabled(true);
	}
	else
	{
		action_intro_cancel->setDisabled(true);
	}

	menu.addAction(action_paste);
	menu.exec(event->globalPos());
}

