#ifndef MAINFRM_H
#define MAINFRM_H

#include <QDialog>
#include <QProcess>
#include <QScrollArea>
#include "ui_mainfrm.h"
#include "menu.h"
#include "menu_th.h"
#include "media.h"
#include "thani.h"
#include "thblend.h"
#include "thimg.h"
#include "thptra.h"
#include "thmenu.h"
#include "pictureflow.h"
#include "flag.h"
#include "myfileopen.h"
#include "widgets/colorpickerwidget.h"
#include "back_syno.h"
#include "item_menu.h"
#include "item_media.h"
#include "helpfrm.h"

class mainfrm : public QMainWindow, public Ui::mainfrm
{
	Q_OBJECT
	public:
		mainfrm(QWidget *parent = 0);

		// *** VARIABLES D'INTERFACE ***
		QString name_application;
		QString path_background;
		QString path_img_menu;
		QString path_save;
		QString path_capture;
		QString path_language;
		QString dvd_standard;
		QString dvd_format;
		QString wg_str_int_001;
		QString wg_str_int_002;
		QString wg_str_int_003;
		QString wg_str_int_004;
		QString wg_str_int_005;
		QString wg_str_int_006;
		QString logstring;
		QString path_always_save;
		QString global_audio;

		QPixmap fond_application;
		QPixmap fond_application_2;

		int dvdxsize;
		int dvdysize;
		int wl_vmax;
		int must_update;
		int dvd_total_size;
		int dvd_actual_size;
		int current_tool;
		int iserror;
		int special_delete;
		int current_loop;
		int loop_length;
		int is_new_create;
		int nbre_threads;
		int dvdzone;
		int isnotify;
		int draw_contours;

		QString current_menu_background;
		int scale_current_menu_background;

		QString current_menu_audio;
		QString current_menu_intro;
		QString current_intro_zik;

		//QScrollArea *scrollArea_editor;
		//QScrollArea *scrollArea_lstmedia;

		PictureFlow *hdlpf;

		// *** VARIABLES CHEMINS ***
		QString path_media_import;
		QString path_project;

		// *** VARIABLES MEDIAS ***
		int nbre_medias;
		int current_media;
		media *table_hdl_medias[60];
		media *hdl_current_media;
		menu *hdl_current_menu;
		menu_th *hdl_current_menuth;
		menu_th *table_hdl_menuth[30];

		// *** VARIABLES MENUS BOUTONS ***
		int nbre_menus;
		int nbre_menus_wo_label;
		menu *table_hdl_menus[20];
		flag *table_hdl_flags[20];

		int nbre_menuth;
		QString table_menus[30][20][25];
		QString copy_table_menus[25];

		QString table_menus_property[30][9];

		// *** VARIABLES TEMPORAIRES GLOBALES ***
		QString wg_string_001;
		QString wg_string_002;
		QString wg_string_003;
		QString wg_string_004;
		QString wg_string_005;
		QString wg_string_006;

		int wg_int_001;
		int wg_int_002;
		int wg_int_003;
		int wg_int_004;
		int wg_int_005;
		int wg_int_006;
		int wg_int_007;
		int wg_int_008;
		int step_render;
		int ismultiplex;

		int position_dispatch;
		int position_media_dispatch;

		int nbre_vignettes;

		float wg_float_001;

		QPixmap wg_pix_001;
		QPixmap wg_pix_002;
		QPixmap wg_pix_003;

		QByteArray Process_Data;

		QTime mysynctime;

		// *** MPLAYER ***
		QTimer *mplayer_timer;
		bool player_isplaying;
		float player_position;
		int oldseek;

		// *** WHEELS ***
		ColorPickerWidget *pntwheel1;
		ColorPickerWidget *pntwheel2;
		ColorPickerWidget *pntwheel3;
		ColorPickerWidget *pntwheel4;
		ColorPickerWidget *pntwheel5;

		myfileopen *pntfiled;

	public slots:
		// *** FONCTIONS PROJETS ***
		void f_valide_new_projet();
		bool f_create_env();
		void f_find_place();
		void f_open_from_start();
		void f_open_ext(QString);

		// *** OPENFILEDIALOG ***
		void f_open_ipreview(QString);
		void f_close_ipreview( const QStringList );
		void f_cancel_ipreview();

		// *** TOOLBAR ***
		void f_showhide_regle();
		void f_showhide_coor();
		void f_showhide_safe();
		void f_view_zone();
		void f_view_tabulation();
		void f_screengrab_menu();
		void f_documentation();

		// *** ARBORESCENCE ***
		void f_view_arborescence();
		void f_item_move(item_menu*);
		void f_item_select(item_menu*);
		void f_affiche_info_arbo(item_menu*);
		void f_edit_menu_tree(item_menu*);
		void f_hide_info_arbo(item_menu*);
		void f_add_link(item_menu*,int);
		void f_add_link_media(item_menu*,QString);
		void f_itemmedia_move(item_media*);
		void f_affiche_info_mediaarbo(item_media*);
		void f_hide_info_mediaarbo(item_media*);
		void f_itemmedia_ren(media*);

		// *** OBJETS ***
		void f_select_object();

		// *** TABULATION ***
		//void f_change_order_tab();

		// *** LABEL ***
		void f_ajoute_label();

		// *** ZONES ***
		void f_aff_zone_0();
		void f_aff_zone_1();
		void f_aff_zone_2();
		void f_aff_zone_3();
		void f_aff_zone_4();
		void f_aff_zone_5();
		void f_aff_zone_6();
		void f_valide_zone();

		// *** BIBLIOTHEQUE DE MEDIAS ***
		void f_lecture_console_extract();

		void f_change_directory(QString);
		void f_move_directory();
		void f_generation_vignette(int, QProcess::ExitStatus);
		void f_ident_media(int, QProcess::ExitStatus);
		void f_drop_to_panel();
		void f_drop_dble();

		void f_open_import_media();
		void f_close_import_media();
		void f_open_import_bibmedia();
		void f_close_import_bibmedia();

		void f_delete_media(media*);
		void f_encode_media(media*);
		void f_chapitre_media(media*);
		void f_select_media(media*, int);
		void f_affiche_info(media*);
		void f_thumbnail_media(media*);
		void f_cache_info(media*);
		void f_introdvd(media*);

		void f_bt_chapitre_media();
		void f_bt_remove_media();
		void f_generation_thu(int, QProcess::ExitStatus);

		void f_next_thumb();
		void f_prev_thumb();
		void f_valid_thumb();

		void f_close_reencode();
		void f_bitarte_change(int);

		void f_select_quoifaire_after(menu*);
		void f_add_quoifaire_media();
		void f_close_quoifaire_media();
		void f_delete_quoifaire_media(int);

		void f_affiche_language(media*);
		void f_close_language();
		void f_search_language();
		void f_delete_language(int);
		void f_display_language();

		void f_effets_media(media*);

		// *** DVDNAV ***
		void f_dvdnav_1();
		void f_dvdnav_2();
		void f_dvdnav_3();
		void f_dvdnav_4();
		void f_dvdnav_5();
		void f_dvdnav_6();
		void f_dvdnav_7();
		void f_dvdnav_8();
		void f_dvdnav_9();

		// *** GESTION DES MENUS MEDIAS ***
		void f_ajoute_menu();
		void f_ajoute_menu_new(int,int,int,int);
		void f_dispatch_menu();
		void f_put_txt_on_bt();
		//void f_put_shadow(int);
		void f_shadowtext_angle(int);
		void f_shadowtext_opacity(int);
		void f_put_anim();
		void f_valide_color_txt();
		void f_valide_color_txt_shadow();
		void f_fmtfont_txt_on_bt_1();
		void f_fmtfont_txt_on_bt_2();
		void f_fmtfont_txt_on_bt_3();
		void f_fmtfont_txt_on_bt_4();
		void f_fmtfont_txt_on_bt_5();
		void f_fmtfont_txt_on_bt_6();
		void f_font_txt_on_bt(QFont);
		void f_import_mask();
		void f_dispatch_1();
		void f_dispatch_2();
		void f_dispatch_3();
		void f_dispatch_4();
		void f_dispatch_5();
		void f_cancel_dispatch();
		void f_combo_typehelp_changed(int);
		void f_combo_typehelpchapter_changed(int);
		void f_dispatch_declare();

		void f_delete_menu(menu*);
		void f_select_menu(menu*);
		void f_release_menu(menu*);
		void f_customize_menu(menu*);
		void f_menu_lower(menu*);
		void f_menu_front(menu*);
		void f_copy_menu(menu*);
		void f_goto_menu(menu*);
		void f_redraw_menu(menu*);
		void f_halign_menu(menu*);
		void f_valign_menu(menu*);
		void f_talign_menu(menu*);
		void f_tobt(menu*);
		void f_paste_menu();
		void f_select_mask();
		void f_valide_customize();
		void f_refresh_customize();
		void f_custo_red(int);
		void f_custo_green(int);
		void f_custo_blue(int);
		void f_custo_opacity(int);

		void f_menu_zoom();
		void f_menu_rotate();
		void f_menu_grab();
		void f_menu_shear();

		void f_menu_opacity(int);

		void f_select_background();
		void f_select_sound();
		void f_cancel_sound();
		void f_select_intro();
		void f_cancel_intro();
		void f_valide_scale_background_2();
		void f_valide_scale_background_1();
		void f_image_menu();
		void f_image_menu_video();
		void f_quoilire_changed(int);
		void f_quoilire_menu_changed(int);
		void f_quoilire_chapitre_changed(int);
		void f_quoilire_audio_changed(int);
		void f_add_menu();
		void f_select_menuth(menu_th*);
		void f_delete_menuth(menu_th*);
		void f_previous_menu();
		void f_next_menu();
		void f_overlay_menu();
		void f_preview_overlay();
		void f_valide_overlay();
		void f_edit_overlay(menu*);
		void f_close_editoverlay();
		void f_designer_brush_width(int);
		void f_tool_designer_1();
		void f_tool_designer_2();
		void f_tool_designer_3();
		void f_tool_designer_4();
		void f_tool_designer_5();

		void f_copy_bt_2();
		void f_paste_bt_2();

		void f_color_overlays();

		void f_view_contours();

		// *** THEMES ***
		void f_add_theme();
		void f_cancel_add_theme();
		void f_select_them();
		void f_add_theme_categorie();

		// *** PREFERENCES ***
		void f_open_preferences();
		void f_close_preferences();

		// *** MPLAYER ***
		void player_open_video(QString);
		void player_play_video();
		void player_read_stdout();
		void player_add_chapter();
		void player_current_percent();
		void player_avance();
		void player_recule();
		void player_go_chapter(QString);
		void player_auto_chapter();
		void player_auto_chapter_thumb();
		void player_close();
		void player_mute();
		void player_capture();
		void player_start_seek();
		void player_stop_seek();
		void player_move_seek(int);
		void player_bri(int);
		void player_con(int);
		void player_sat(int);
		void f_init_effects();
		void f_close_effects();

		// *** RENDERING ***
		void f_go_render_dvd();
		void f_gene_dvdauthorxml();
		void render_end(int, QProcess::ExitStatus);
		void render_stdout();
		void f_gene_mencoder();
		void f_make_menus();
		void f_encoding_end();
		void f_close_endencoding();
		void f_view_result();
		void f_create_iso();
		void f_read_ffmpeg();

		// *** FONCTIONS CLES ***
		void f_affiche_info_pos(menu *hdlm);
		void f_lockbar();
		void f_delete_widgetonmenu();
		void f_save_widgetonmenu();
		void f_update_thumb_menu();
		void f_create_menu_movie();
		void f_calcul_jauge(long);
		void f_run_ani();
		void f_run_bld();
		void f_generation_scale();
		void f_update_blend();
		void f_end_blend();

		// *** GESTION PROJET ***
		void f_new_1();
		void f_save_1();
		void f_save_2();
		void f_open_1();
		void f_open_2();
		void f_init_proj();
		void f_create_new_menu();
		void projectend(int, QProcess::ExitStatus);

		// *** GRAVAGE ***
		void f_open_burn();
		void f_open_burn_2();
		void f_cancel_burn();
		void f_go_burn();
		void f_read_outidv();
		void f_idvd_end(int, QProcess::ExitStatus);

		// *** DIVERS ***
		void f_apropos_open();
		void f_apropos_close();
		void f_oclose_tim();
		void f_scroll_timeline(int);
		void thvi_end(int, QProcess::ExitStatus);
		void f_menu_navi_on(menu*);
		void f_menu_navi_off(menu*);

		void f_advanced_open();
		void f_advanced_close();
		void f_put_loop(int);

		void f_read_outiso();
		void f_giso_end(int, QProcess::ExitStatus);

		void f_show_frame_bk();
		void f_hide_frame_bk();

		// *** INTRO CALCULEES ***
		void f_intro_calc();
		void f_valide_intro_calc();
		void f_cancel_intro_calc();
		void f_update_trans();
		void f_restart_proc_trans();
		void f_change_transition(QListWidgetItem*);
		void f_find_intro_zik();

		// *** BLUR ***
		QImage blur_shadow(QImage);

		// *** EVENTS EXTERIEURS ***
		void extevent();
		void f_enter_editor_txt();
		void f_close_editor_txt();

	private slots:
		// *** GESTION DE LA FENETRE ***
		void f_resize(QResizeEvent *);
		void f_close();
		void keyPressEvent( QKeyEvent * );
		void keyReleaseEvent( QKeyEvent * );

	private:
		QProcess process_extract_img;
		QProcess process_import_background;
		QProcess process_one_shot;
		QProcess process_ident_media;
		QProcess process_extract_thu;

		QProcess mplayerProcess;
		QProcess renderProcess;
		QProcess projectProcess;
		QProcess nullProcess;
		QProcess thviProcess;
		QProcess isoProcess;
		QProcess idvProcess;
		QProcess proc_ffmpeg;

		thani *thread_ani;
		thblend *thread_blend;
		thimg *thread_img;
		thptra *thread_trans;
		thmenu *thread_menu;

	signals:
	protected:
		void paintEvent(QPaintEvent *);
		void resizeEvent(QResizeEvent *e)
		{
			QMainWindow::resizeEvent(e);
			emit f_resize(e);
		}
		virtual void closeEvent(QCloseEvent *e)
		{
			emit f_close();
			QMainWindow::closeEvent(e);
		}
};
#endif
