#include <QtGui>
#include "mainfrm.h"
//#include "texteditor.h"

void mainfrm::f_open_title(int numtab)
{
	pntmygl->element = 0;
	pnttimeline->tabposition = numtab;
	if ( numtab == 2 )
	{
		// *** EDITION DE LA LEGENDE ***
		//pntmygl->ismblur = 0;
		menubar->setDisabled(true);
		toolBar->setDisabled(true);
		top_timeline->setDisabled(true);
		toolsmenu->hide();
		pntmygl->state_mode = 0;
		pntmygl->updateGL();
		QImage wl_cur01 = pntmygl->grabFrameBuffer ( false );
		pntlabeltxt->img2fond = QPixmap::fromImage ( wl_cur01, Qt::AutoColor ) ;
		//QPixmap wl_cur01(wpathprojet + "/" + table_photos[current_diapo][0]);
		//pntlabeltxt->img2fond = wl_cur01.scaledToHeight(size_dia_y, Qt::FastTransformation);
		spindurleg->setMaximum(table_photos[current_diapo][16].toInt());
		if ( table_photos[current_diapo][23].left(1) == "1" )
		{
			chk_fondu_entrant->setChecked(true);
		}
		else
		{
			chk_fondu_entrant->setChecked(false);
		}
		if ( table_photos[current_diapo][23].mid(1,1) == "1" )
		{
			chk_fondu_sortant->setChecked(true);
		}
		else
		{
			chk_fondu_sortant->setChecked(false);
		}
		spindurleg->setValue(table_photos[current_diapo][23].mid(2,table_photos[current_diapo][23].length()-2).toInt());
		if ( table_photos[current_diapo][17] != "" )
		{
			tmpint_1 = table_photos[current_diapo][17].lastIndexOf( "PY=" );
			tmpint_2 = table_photos[current_diapo][17].lastIndexOf( "TEXT=" );
			tmpint_3 = table_photos[current_diapo][17].lastIndexOf( "FONT=" );
			tmpint_4 = table_photos[current_diapo][17].lastIndexOf( "COLORRED=" );

			wg_tmp_002 = table_photos[current_diapo][17].mid(3, tmpint_1-3);
			pntlabeltxt->textx = wg_tmp_002.toInt();

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_1 + 3, tmpint_2-(3 + tmpint_1));
			pntlabeltxt->texty = wg_tmp_002.toInt();

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_2 + 5, tmpint_3-(5 + tmpint_2));
			pntlabeltxt->current_text = wg_tmp_002;
			txtondiapo->setText(wg_tmp_002);

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_3 + 5, tmpint_4-(5 + tmpint_3));
			pntlabeltxt->myfont.fromString(wg_tmp_002);
			fontlegende->setCurrentFont(pntlabeltxt->myfont);

			tmpint_1 = table_photos[current_diapo][17].lastIndexOf( "COLORRED=" );
			tmpint_2 = table_photos[current_diapo][17].lastIndexOf( "COLORGREEN=" );
			tmpint_3 = table_photos[current_diapo][17].lastIndexOf( "COLORBLUE=" );
			tmpint_4 = table_photos[current_diapo][17].lastIndexOf( "SIZE=" );

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_1 + 9, tmpint_2-(9 + tmpint_1));
			pntlabeltxt->mycolor.setRed(wg_tmp_002.toInt());
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_2 + 11, tmpint_3-(11 + tmpint_2));
			pntlabeltxt->mycolor.setGreen(wg_tmp_002.toInt());
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_3 + 10, tmpint_4-(10 + tmpint_3));
			pntlabeltxt->mycolor.setBlue(wg_tmp_002.toInt());

			tmpint_1 = table_photos[current_diapo][17].lastIndexOf( "BOLD=" );
			tmpint_2 = table_photos[current_diapo][17].lastIndexOf( "ITALIC=" );

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_4 + 5, tmpint_1-(5 + tmpint_4));
			pntlabeltxt->size = wg_tmp_002.toInt();
			legend_size->setValue(pntlabeltxt->size);
			pntlabeltxt->myfont.setPixelSize(pntlabeltxt->size);
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_1 + 5, 1);
			if ( wg_tmp_002 == "1" )
			{
				pntlabeltxt->myfont.setBold(true);
				bt_leg_bold->setChecked(true);
			}
			else
			{
				pntlabeltxt->myfont.setBold(false);
				bt_leg_bold->setChecked(false);
			}
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_2 + 7, 1);
			if ( wg_tmp_002 == "1" )
			{
				pntlabeltxt->myfont.setItalic(true);
				bt_leg_italic->setChecked(true);
			}
			else
			{
				pntlabeltxt->myfont.setItalic(false);
				bt_leg_italic->setChecked(false);
			}
			tmpint_1 = table_photos[current_diapo][17].lastIndexOf( "BACKRED=" );
			tmpint_2 = table_photos[current_diapo][17].lastIndexOf( "BACKGREEN=" );
			tmpint_3 = table_photos[current_diapo][17].lastIndexOf( "BACKBLUE=" );
			tmpint_4 = table_photos[current_diapo][17].lastIndexOf( "BACKOPACITY=" );

			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_1 + 8, tmpint_2-(8 + tmpint_1));
			pntlabeltxt->backcolor.setRed(wg_tmp_002.toInt());
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_2 + 10, tmpint_3-(10 + tmpint_2));
			pntlabeltxt->backcolor.setGreen(wg_tmp_002.toInt());
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_3 + 9, tmpint_4-(9 + tmpint_3));
			pntlabeltxt->backcolor.setBlue(wg_tmp_002.toInt());
			wg_tmp_002 = table_photos[current_diapo][17].mid(tmpint_4 + 12, wg_tmp_002.length() -(12 + tmpint_4));
			pntlabeltxt->opacity = wg_tmp_002.toInt();
			slider_backtxt->setValue(pntlabeltxt->opacity);
			//
			f_font_comment(pntlabeltxt->myfont);
			pntlabeltxt->repaint();
		}
		else
		{
			spindurleg->setValue(table_photos[current_diapo][16].toInt());
			pntlabeltxt->opacity = 0;
			slider_backtxt->setValue(0);
			pntlabeltxt->backcolor.setRed(0);
			pntlabeltxt->backcolor.setGreen(0);
			pntlabeltxt->backcolor.setBlue(0);
			pntlabeltxt->current_text = "";
			txtondiapo->setText("");
			pntlabeltxt->size = 40;
			legend_size->setValue(40);
			fontlegende->setCurrentIndex(1);
			pntlabeltxt->myfont = fontlegende->currentFont();
			pntlabeltxt->mycolor.setRed(255);
			pntlabeltxt->mycolor.setGreen(255);
			pntlabeltxt->mycolor.setBlue(255);
			pntlabeltxt->mycolor.setAlpha(255);
			f_font_comment(pntlabeltxt->myfont);
		}
		// *** INFORMATIONS POSITION DE LA LEGENDE ***
		tmpint_1 = table_photos[current_diapo][4].lastIndexOf( "A" );
		tmpint_2 = table_photos[current_diapo][4].lastIndexOf( "Z" );
		tmpint_3 = table_photos[current_diapo][4].lastIndexOf( "E" );

		wg_tmp_002 = table_photos[current_diapo][4].mid(0, tmpint_1);
		pntlabeltxt->textx = wg_tmp_002.toInt();
		startx_legani = wg_tmp_002.toInt();
		wg_tmp_002 = table_photos[current_diapo][4].mid(tmpint_1 + 1, tmpint_2-(tmpint_1+1));
		pntlabeltxt->texty = wg_tmp_002.toInt();
		starty_legani = wg_tmp_002.toInt();
		//
		wg_tmp_002 = table_photos[current_diapo][4].mid(tmpint_2 + 1, tmpint_3-(tmpint_2+1));
		endx_legani = wg_tmp_002.toInt();
		wg_tmp_002 = table_photos[current_diapo][4].mid(tmpint_3 + 1, tmpint_3-(table_photos[current_diapo][4].length()+1));
		endy_legani = wg_tmp_002.toInt();
		//
		if ( table_photos[current_diapo][3] == "0" )
		{
			bt_leg_align_1->setChecked(true);
			pntlabeltxt->alignement = 0;
		}
		else
		{
			if ( table_photos[current_diapo][3] == "1" )
			{
				bt_leg_align_2->setChecked(true);
				pntlabeltxt->alignement = 1;
			}
			else
			{
				if ( table_photos[current_diapo][3] == "2" )
				{
					bt_leg_align_3->setChecked(true);
					pntlabeltxt->alignement = 2;
				}
				else
				{
					bt_leg_align_4->setChecked(true);
					pntlabeltxt->alignement = 3;
				}
			}
		}
		pntlabeltxt->setMyText(pntlabeltxt->current_text);
		pntlabeltxt->repaint();
		//
		frame_widget_txt->show();
		frame_widget_txt->raise();
		old_tab = numtab;
	}
	else
	{
		if ( old_tab == 2 )
		{
			frame_widget_txt->hide();
			menubar->setEnabled(true);
			toolBar->setEnabled(true);
			toolsmenu->show();
			if ( pntlabeltxt->current_text != "" )
			{
				if ( startx_legani == 0 && starty_legani == 0 && endx_legani == 0 && endy_legani == 0 )
				{
					startx_legani = pntlabeltxt->textx;
					starty_legani = pntlabeltxt->texty;
					endx_legani = pntlabeltxt->textx;
					endy_legani = pntlabeltxt->texty;
				}
				table_photos[current_diapo][4] = QString::number(startx_legani) + "A" + QString::number(starty_legani) + "Z" + QString::number(endx_legani) + "E" + QString::number(endy_legani);
				QFontMetrics fm(pntlabeltxt->myfont);
				QPixmap wlpix1(size_dia_x*2,(pntlabeltxt->current_text.count(QRegExp("\n")) + 1) * (fm.height()+pntlabeltxt->leading));
				wlpix1.fill(QColor(255,255,255,0));
				//
				QPainter p;
				p.begin(&wlpix1);
				p.setRenderHint(QPainter::Antialiasing,true);
				p.setPen (pntlabeltxt->mycolor);
				p.setFont(pntlabeltxt->myfont);
				//p.fillRect ( 0, pntlabeltxt->texty, size_dia_x, (pntlabeltxt->current_text.count(QRegExp("\n")) + 1) * (fm.height()+pntlabeltxt->leading), QBrush( QColor(pntlabeltxt->backcolor.red(),pntlabeltxt->backcolor.green(),pntlabeltxt->backcolor.blue(),pntlabeltxt->opacity), Qt::SolidPattern ) );
				//p.drawText ( QRect(pntlabeltxt->textx,pntlabeltxt->texty,size_dia_x,size_dia_y), (Qt::AlignLeft | Qt::AlignTop),pntlabeltxt->current_text );
				p.fillRect ( 0, 0, size_dia_x*2, (pntlabeltxt->current_text.count(QRegExp("\n")) + 1) * (fm.height()+pntlabeltxt->leading), QBrush( QColor(pntlabeltxt->backcolor.red(),pntlabeltxt->backcolor.green(),pntlabeltxt->backcolor.blue(),pntlabeltxt->opacity), Qt::SolidPattern ) );
				//p.drawText ( QRect(size_dia_x,0,size_dia_x,size_dia_y), (Qt::AlignLeft | Qt::AlignTop),pntlabeltxt->current_text );
				if ( pntlabeltxt->alignement == 0 )
				{
					p.drawText ( QRect(size_dia_x,0,pntlabeltxt->myrect.width(),size_dia_y), (Qt::AlignLeft | Qt::AlignTop | Qt::TextExpandTabs),pntlabeltxt->current_text );
				}
				else
				{
					if ( pntlabeltxt->alignement == 1 )
					{
						p.drawText ( QRect(size_dia_x,0,pntlabeltxt->myrect.width(),size_dia_y), (Qt::AlignHCenter | Qt::AlignTop | Qt::TextExpandTabs),pntlabeltxt->current_text );
					}
					else
					{
						if ( pntlabeltxt->alignement == 2 )
						{
							p.drawText ( QRect(size_dia_x,0,pntlabeltxt->myrect.width(),size_dia_y), (Qt::AlignJustify | Qt::AlignTop | Qt::TextExpandTabs),pntlabeltxt->current_text );
						}
						else
						{
							p.drawText ( QRect(size_dia_x,0,pntlabeltxt->myrect.width(),size_dia_y), (Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs),pntlabeltxt->current_text );
						}
					}
				}
				p.end();
				old_tab = numtab;
				QString isbold = "0";
				QString isitalic = "0";
				if ( bt_leg_bold->isChecked() == true )
				{
					isbold = "1";
				}
				if ( bt_leg_italic->isChecked() == true )
				{
					isitalic = "1";
				}
				wlpix1.save(wpathprojet + "/TITLE_" + table_photos[current_diapo][0] + ".png","PNG");
				table_photos[current_diapo][17] = "PX=" + QString::number(pntlabeltxt->textx) + "PY=" + QString::number(pntlabeltxt->texty) + "TEXT=" + pntlabeltxt->current_text + "FONT=" + pntlabeltxt->myfont.toString() + "COLORRED=" + QString::number(pntlabeltxt->mycolor.red()) + "COLORGREEN=" + QString::number(pntlabeltxt->mycolor.green()) + "COLORBLUE=" + QString::number(pntlabeltxt->mycolor.blue()) + "SIZE=" + QString::number(pntlabeltxt->size) + "BOLD=" + isbold + "ITALIC=" + isitalic + "BACKRED=" + QString::number(pntlabeltxt->backcolor.red()) + "BACKGREEN=" + QString::number(pntlabeltxt->backcolor.green()) + "BACKBLUE=" + QString::number(pntlabeltxt->backcolor.blue()) + "BACKOPACITY=" + QString::number(pntlabeltxt->opacity);
				affichage_diapo();
				top_timeline->setEnabled(true);
			}
			else
			{
				table_photos[current_diapo][17] = "";
				old_tab = numtab;
				affichage_diapo();
				top_timeline->setEnabled(true);
			}
		}
		else
		{
			old_tab = numtab;
		}
		if ( numtab == 1 )
		{
			//pntmygl->ismblur = 0;
			if ( table_photos[current_diapo][12] == "" )
			{
				slider_size_anim->setValue(15);
				slider_rot_anim->setValue(0);
				dial_percent_blending->setValue(100);
				dial_percent_blending_2->setValue(100);
			}
			menubar->setDisabled(true);
			toolBar->setDisabled(true);
			bt_complex->setDisabled(true);
			frame_xperttimeline->hide();
			toolsmenu->hide();
		}
		else
		{
			/*if  (check_mblur->isChecked() == true)
			{
				pntmygl->ismblur = 1;
			}
			else
			{
				pntmygl->ismblur = 0;
			}*/
			menubar->setEnabled(true);
			toolBar->setEnabled(true);
			bt_complex->setEnabled(true);
			if ( state_timeline == 1 )
			{
				frame_xperttimeline->show();
			}
			toolsmenu->show();
		}
	}

	if (numtab == 1 )
	{
		//pntmygl->ismblur = 0;
		pntmygl->element = 1;
		toolsmenu->hide();
	}
	this->setFocus();
}

void mainfrm::f_align_1()
{
	pntlabeltxt->alignement = 0;
	table_photos[current_diapo][3]="0";
	pntlabeltxt->repaint();
}

void mainfrm::f_align_2()
{
	pntlabeltxt->alignement = 1;
	table_photos[current_diapo][3]="1";
	pntlabeltxt->repaint();
}

void mainfrm::f_align_3()
{
	pntlabeltxt->alignement = 2;
	table_photos[current_diapo][3]="2";
	pntlabeltxt->repaint();
}

void mainfrm::f_align_4()
{
	pntlabeltxt->alignement = 3;
	table_photos[current_diapo][3]="3";
	pntlabeltxt->repaint();
}

void mainfrm::f_go_start_legani()
{
	pntlabeltxt->textx = startx_legani;
	pntlabeltxt->texty = starty_legani;
	pntlabeltxt->repaint();
}

void mainfrm::f_go_end_legani()
{
	pntlabeltxt->textx = endx_legani;
	pntlabeltxt->texty = endy_legani;
	pntlabeltxt->repaint();
}

void mainfrm::f_mk_start_legani()
{
	startx_legani = pntlabeltxt->textx;
	starty_legani = pntlabeltxt->texty;
	if ( endx_legani == 0 && endy_legani == 0 )
	{
		endx_legani = pntlabeltxt->textx;
		endy_legani = pntlabeltxt->texty;
		pntlabeltxt->posend.setX(endx_legani);
		pntlabeltxt->posend.setY(endy_legani);
	}
	pntlabeltxt->posdep.setX(startx_legani);
	pntlabeltxt->posdep.setY(starty_legani);
	pntlabeltxt->repaint();
}

void mainfrm::f_mk_end_legani()
{
	endx_legani = pntlabeltxt->textx;
	endy_legani = pntlabeltxt->texty;
	if ( startx_legani == 0 && starty_legani == 0 )
	{
		startx_legani = pntlabeltxt->textx;
		starty_legani = pntlabeltxt->texty;
		pntlabeltxt->posdep.setX(startx_legani);
		pntlabeltxt->posdep.setY(starty_legani);
	}
	pntlabeltxt->posend.setX(endx_legani);
	pntlabeltxt->posend.setY(endy_legani);
	pntlabeltxt->repaint();
}

void mainfrm::f_change_color_txt()
{
	QColor wlcolor(pntwheeltxt->red,pntwheeltxt->green,pntwheeltxt->blue);
	if ( wlcolor.isValid() == true )
	{
		pntlabeltxt->mycolor = wlcolor;
		pntlabeltxt->repaint();
	}
}

void mainfrm::f_font_comment(const QFont & font)
{
	pntlabeltxt->myfont = font;
	pntlabeltxt->myfont.setPixelSize(pntlabeltxt->size);
	QFontMetrics fm(pntlabeltxt->myfont);
	pntlabeltxt->myrect = fm.size ( Qt::TextExpandTabs, pntlabeltxt->current_text, 0, 0 );
	//pntlabeltxt->size = pntlabeltxt->size; //fm.height();
	pntlabeltxt->leading = fm.leading();
	pntlabeltxt->repaint();
}

void mainfrm::f_leg_bold()
{
	if ( bt_leg_bold->isChecked() == true )
	{
		pntlabeltxt->myfont.setBold(true);
	}
	else
	{
		pntlabeltxt->myfont.setBold(false);
	}
	pntlabeltxt->setMyText(pntlabeltxt->current_text);
	pntlabeltxt->repaint();
}

void mainfrm::f_leg_italic()
{
	if ( bt_leg_italic->isChecked() == true )
	{
		pntlabeltxt->myfont.setItalic(true);
	}
	else
	{
		pntlabeltxt->myfont.setItalic(false);
	}
	pntlabeltxt->setMyText(pntlabeltxt->current_text);
	pntlabeltxt->repaint();
}

void mainfrm::f_leg_size(int size)
{
	pntlabeltxt->myfont.setPixelSize(size);
	QFontMetrics fm(pntlabeltxt->myfont);
	pntlabeltxt->myrect = fm.size ( Qt::TextExpandTabs, pntlabeltxt->current_text, 0, 0 );
	pntlabeltxt->size = size; //height();
	pntlabeltxt->leading = fm.leading();
	pntlabeltxt->repaint();
}

void mainfrm::f_leg_filename()
{
	int k = table_photos[current_diapo][0].indexOf( '$' );
	txtondiapo->setText(txtondiapo->toPlainText() + table_photos[current_diapo][0].mid(k + 1, table_photos[current_diapo][0].length() - (k + 5)));
	//pntlabeltxt->setMyText(txtondiapo->toPlainText());
	pntlabeltxt->repaint();
}

void mainfrm::f_txtedit_chtxt()
{
	pntlabeltxt->setMyText(txtondiapo->toPlainText());
}

void mainfrm::f_change_color_bac()
{
	QColor wlcolor(pntwheelbac->red,pntwheelbac->green,pntwheelbac->blue);
	if ( wlcolor.isValid() == true )
	{
		pntlabeltxt->backcolor = wlcolor;
		pntlabeltxt->repaint();
	}
}

void mainfrm::f_change_opacity_back(int opacity)
{
	pntlabeltxt->opacity = opacity;
	pntlabeltxt->repaint();
}

void mainfrm::f_change_color_deg_1()
{
	if ( pntmygl->path_fond == "$N$U$L$L" )
	{
		pntmygl->path_fond = "";
	}
	pntmygl->sl_fond_degrade(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue,pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue,slider_lngdeg->value());
}

void mainfrm::f_change_color_deg_2()
{
	if ( pntmygl->path_fond == "$N$U$L$L" )
	{
		pntmygl->path_fond = "";
	}
	pntmygl->sl_fond_degrade(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue,pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue,slider_lngdeg->value());
}

void mainfrm::f_deg1_couleur_valide()
{
	QPixmap wl_pix_2(size_dia_x,size_dia_y);
	QColor paintcolor(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue);
	QColor paintcolor2(pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue);
	if ( paintcolor.isValid() == true && paintcolor2.isValid() == true )
	{
		QLinearGradient mygradient(512,0,512,576);
		mygradient.setColorAt(0.0,paintcolor);
		mygradient.setColorAt((float)((float)slider_lngdeg->value()/(float)100),paintcolor2);
		QPainter p;
		p.begin(&wl_pix_2);
		p.fillRect ( 0, 0, 1024 ,1024, QBrush( mygradient ) );
		p.end();
		if (table_photos[current_diapo][13] == "$N$U$L$L")
		{
			outfilename = "fdcolor";
			wl_pix_2.save(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg","JPEG",75);
			//
			table_photos[current_diapo][13] = QString::number(nbre_imports) + "$" + outfilename + ".jpg";
			pntmygl->sl_change_fond(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg");
			pntmygl->updateGL();
			nbre_imports = nbre_imports + 1;
		}
		else
		{
	      		outfilename = table_photos[current_diapo][13];
			wl_pix_2.save(wpathprojet + "/" + outfilename,"JPEG",100);
			//
			pntmygl->sl_change_fond(wpathprojet + "/" + outfilename);
			pntmygl->updateGL();
		}
	}
}

void mainfrm::f_deg2_couleur_valide()
{
	QPixmap wl_pix_2(size_dia_x,size_dia_y);
	QColor paintcolor(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue);
	QColor paintcolor2(pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue);
	if ( paintcolor.isValid() == true && paintcolor2.isValid() == true )
	{
		QLinearGradient mygradient(512,0,512,576);
		mygradient.setColorAt(0.0,paintcolor);
		mygradient.setColorAt((float)((float)slider_lngdeg->value()/(float)100),paintcolor2);
		QPainter p;
		p.begin(&wl_pix_2);
		p.fillRect ( 0, 0, 1024 ,1024, QBrush( mygradient ) );
		p.end();
		if (table_photos[current_diapo][13] == "$N$U$L$L")
		{
			outfilename = "fdcolor";
			wl_pix_2.save(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg","JPEG",75);
			//
			table_photos[current_diapo][13] = QString::number(nbre_imports) + "$" + outfilename + ".jpg";
			pntmygl->sl_change_fond(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg");
			pntmygl->updateGL();
			nbre_imports = nbre_imports + 1;
		}
		else
		{
	      		outfilename = table_photos[current_diapo][13];
			wl_pix_2.save(wpathprojet + "/" + outfilename,"JPEG",100);
			//
			pntmygl->sl_change_fond(wpathprojet + "/" + outfilename);
			pntmygl->updateGL();
		}
	}
}

void mainfrm::f_lngdeg_valide()
{
	QPixmap wl_pix_2(size_dia_x,size_dia_y);
	QColor paintcolor(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue);
	QColor paintcolor2(pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue);
	if ( paintcolor.isValid() == true && paintcolor2.isValid() == true )
	{
		QLinearGradient mygradient(512,0,512,576);
		if ( slider_lngdeg->value() <= 100 )
		{
			mygradient.setColorAt(0.0,paintcolor);
			mygradient.setColorAt((float)((float)slider_lngdeg->value()/(float)100),paintcolor2);
		}
		else
		{
			mygradient.setColorAt((float)((float)(slider_lngdeg->value()-100)/(float)100),paintcolor);
			mygradient.setColorAt(1.0,paintcolor2);
		}
		QPainter p;
		p.begin(&wl_pix_2);
		p.fillRect ( 0, 0, 1024 ,1024, QBrush( mygradient ) );
		p.end();
		if (table_photos[current_diapo][13] == "$N$U$L$L")
		{
			outfilename = "fdcolor";
			wl_pix_2.save(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg","JPEG",75);
			//
			table_photos[current_diapo][13] = QString::number(nbre_imports) + "$" + outfilename + ".jpg";
			pntmygl->sl_change_fond(wpathprojet + "/" + QString::number(nbre_imports) + "$" + outfilename + ".jpg");
			pntmygl->updateGL();
			nbre_imports = nbre_imports + 1;
		}
		else
		{
	      		outfilename = table_photos[current_diapo][13];
			wl_pix_2.save(wpathprojet + "/" + outfilename,"JPEG",100);
			//
			pntmygl->sl_change_fond(wpathprojet + "/" + outfilename);
			pntmygl->updateGL();
		}
	}
} 

void mainfrm::f_lngdeg(int value)
{
	if ( pntmygl->path_fond == "$N$U$L$L" )
	{
		pntmygl->path_fond = "";
	}
	pntmygl->sl_fond_degrade(pntwheeldeg1->red,pntwheeldeg1->green,pntwheeldeg1->blue,pntwheeldeg2->red,pntwheeldeg2->green,pntwheeldeg2->blue,value);
}

void mainfrm::f_leg_fondu(int)
{
	QString wl_val1 = "0";
	QString wl_val2 = "0";
	if ( chk_fondu_entrant->isChecked() == true )
	{
		wl_val1 = "1";
	}
	if ( chk_fondu_sortant->isChecked() == true )
	{
		wl_val2 = "1";
	}
	table_photos[current_diapo][23] = wl_val1+wl_val2+QString::number(spindurleg->value());
}

void mainfrm::f_painter()
{
	if ( bt_painter->isChecked() == true )
	{
		pntmygl->isdraw = 0;
		pntmygl->updateGL();
		QImage wl_cur01 = pntmygl->grabFrameBuffer ( false );
		frame_painter->img2fond = QPixmap::fromImage ( wl_cur01, Qt::AutoColor ) ;

		if ( table_photos[current_diapo][9] == "1" )
		{
			frame_painter->mydraw.load(wpathprojet + "/_DRAW" + table_photos[current_diapo][0] + ".png");
		}
		else
		{
			frame_painter->mydraw.fill(0);
		}
		frame_painter->savedraw = frame_painter->mydraw;
		bt_deplace->setDisabled(true);
		bt_rotate1->setDisabled(true);
		bt_rotate2->setDisabled(true);
		bt_rotate3->setDisabled(true);
		bt_rotate4->setDisabled(true);
		bt_zoom->setDisabled(true);
		bt_pstart->setDisabled(true);
		bt_pend->setDisabled(true);
		tabmenus->setDisabled(true);
		menubar->setDisabled(true);
		toolBar->setDisabled(true);
		top_timeline->setDisabled(true);
		support_timeline->setDisabled(true);
		zone_painter->show();
		zone_painter->raise();
		frame_toolspainter->show();
		frame_toolspainter->raise();
		toolsmenu->raise();
	}
	else
	{
		bt_deplace->setEnabled(true);
		bt_rotate1->setEnabled(true);
		bt_rotate2->setEnabled(true);
		bt_rotate3->setEnabled(true);
		bt_rotate4->setEnabled(true);
		bt_zoom->setEnabled(true);
		bt_pstart->setEnabled(true);
		bt_pend->setEnabled(true);
		tabmenus->setEnabled(true);
		menubar->setEnabled(true);
		toolBar->setEnabled(true);
		top_timeline->setEnabled(true);
		support_timeline->setEnabled(true);
		zone_painter->hide();
		frame_toolspainter->hide();
		pntmygl->show();
		if ( frame_painter->mydraw.save(wpathprojet + "/_DRAW" + table_photos[current_diapo][0] + ".png","PNG") == true )
		{
			table_photos[current_diapo][9] = "1";
		}
		else
		{
			table_photos[current_diapo][9] = "0";
			qDebug() << "ERROR SAVING DRAW : " << wpathprojet + "/_DRAW" + table_photos[current_diapo][0] + ".png";
		}
		QTimer::singleShot(5, this, SLOT(affichage_diapo()));
	}
}

void mainfrm::f_painter_fermer()
{
	bt_deplace->setEnabled(true);
	bt_rotate1->setEnabled(true);
	bt_rotate2->setEnabled(true);
	bt_rotate3->setEnabled(true);
	bt_rotate4->setEnabled(true);
	bt_zoom->setEnabled(true);
	bt_pstart->setEnabled(true);
	bt_pend->setEnabled(true);
	tabmenus->setEnabled(true);
	menubar->setEnabled(true);
	toolBar->setEnabled(true);
	top_timeline->setEnabled(true);
	support_timeline->setEnabled(true);
	bt_painter->setChecked(false);
	zone_painter->hide();
	frame_toolspainter->hide();
	pntmygl->show();
	if ( frame_painter->mydraw.save(wpathprojet + "/_DRAW" + table_photos[current_diapo][0] + ".png","PNG") == true )
	{
		table_photos[current_diapo][9] = "1";
	}
	else
	{
		table_photos[current_diapo][9] = "0";
		qDebug() << "ERROR SAVING DRAW : " << wpathprojet + "/_DRAW" + table_photos[current_diapo][0] + ".png";
	}
	QTimer::singleShot(5, this, SLOT(affichage_diapo()));
}

void mainfrm::f_painter_init()
{
	frame_painter->mydraw = frame_painter->savedraw;
	frame_painter->repaint();
}

void mainfrm::f_change_color_painter()
{
	frame_painter->mycolor.setRed(pntwheelpaint->red);
	frame_painter->mycolor.setGreen(pntwheelpaint->green);
	frame_painter->mycolor.setBlue(pntwheelpaint->blue);
	frame_painter->mycolor.setAlpha(slider_paintopacity->value());
	frame_painter->dstcolor.setRed(pntwheelpaint->red);
	frame_painter->dstcolor.setGreen(pntwheelpaint->green);
	frame_painter->dstcolor.setBlue(pntwheelpaint->blue);
	frame_painter->dstcolor.setAlpha(slider_paintopacity->value());
}

void mainfrm::f_painteropa(int value)
{
	frame_painter->mycolor.setAlpha(value);
	label_27->setText(QString::number(int(((float)100 * (float)value)/(float)255)) + " %");
}

void mainfrm::f_paintersiz(int value)
{
	frame_painter->ptsize = value;
	label_18->setText(QString::number(value) + " px");
}

void mainfrm::f_painter_efface()
{
	if ( bt_painter_efface->isChecked() == true )
	{
		frame_painter->tool = 2;
		brush1->setChecked(true);
		frame_painter->brush = 1;
		frame_support_brush->setDisabled(true);
	}
	else
	{
		frame_support_brush->setEnabled(true);
	}
}

void mainfrm::f_painter_draw()
{
	if ( bt_painter_paint->isChecked() == true )
	{
		frame_painter->tool = 1;
		frame_support_brush->setEnabled(true);
	}
}

void mainfrm::f_painter_brush1()
{
	frame_painter->brush = 1;
}

void mainfrm::f_painter_brush2()
{
	frame_painter->brush = 2;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_coeur.png");
}

void mainfrm::f_painter_brush3()
{
	frame_painter->brush = 3;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_nuage.png");
}

void mainfrm::f_painter_brush4()
{
	frame_painter->brush = 4;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_fleur.png");
}

void mainfrm::f_painter_brush5()
{
	frame_painter->brush = 5;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_girl.png");
}

void mainfrm::f_painter_brush6()
{
	frame_painter->brush = 6;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_branche.png");
}

void mainfrm::f_painter_brush7()
{
	frame_painter->brush = 7;
	frame_painter->imgbrush.load(":/new/prefix2/Interface/Theme/brush_etoile.png");
}

void mainfrm::f_painter_brush8()
{
	QString wmyfic = QFileDialog::getOpenFileName(this, tr("Fichier image pour brosse"), "~", tr("Images (*.png *.PNG)"));
	if ( wmyfic.isNull() )
	{
		frame_painter->brush = 1;
		brush1->setChecked(true);
	}
	else
	{
		frame_painter->brush = 8;
		frame_painter->imgbrush.load(wmyfic);
	}
}

void mainfrm::f_documentation()
{
	helpfrm *hlpdialog = new helpfrm;
	hlpdialog->show();
}

