void EvolutionGraphWidget::changeCurrentColor()
{
	if (!m_pSelectedKey || m_bIsNoColor)
		return;

	QColor oldColor;
	oldColor = Col2QColor( m_pSelectedKey->getColor() );

	QColor newColor = QColorDialog::getColor(oldColor, 0);
	if (newColor.isValid())
		changeCurrentColor(newColor);
}
ColorSelector::ColorSelector(QWidget *parent)
	: QWidget(parent)
{
    m_pressedButton = false;

    m_preferences =  PreferencesManager::getInstance();

    int rouge[48] = {255,255,128,0,128,0,255,255, 255,255,128,0,0,0,128,255, 128,255,0,0,0,128,128,255, 128,255,0,0,0,0,128,128, 64,128,0,0,0,0,64,64, 0,128,128,128,64,192,64,255};
    int vert[48] = {128,255,255,255,255,128,128,128, 0,255,255,255,255,128,128,0, 64,128,255,128,64,128,0,0, 0,128,128,128,0,0,0,0, 0,64,64,64,0,0,0,0, 0,128,128,128,128,192,64,255};
    int bleu[48] = {128,128,128,128,255,255,192,255, 0,0,0,64,255,192,192,255, 64,64,0,128,128,255,64,128, 0,0,0,64,255,160,128,255, 0,0,0,64,128,64,64,128, 0,0,64,128,128,192,64,255};


    // Creation du layout principale
    m_layoutSelector = new QVBoxLayout(this);
    m_layoutSelector->setMargin(2);
    m_layoutSelector->setSpacing(1);

    G_couleurCourante.type = ColorType;
    G_couleurCourante.color = QColor(rouge[40],vert[40],bleu[40]);

    m_currentColor = new QLabel(this);
    m_currentColor->setFrameStyle(QFrame::Panel | QFrame::Raised);
    m_currentColor->setLineWidth(1);
    m_currentColor->setMidLineWidth(1);

    m_currentColor->setFixedSize(45,40);
    setBackgroundColorToWidget(m_currentColor, G_couleurCourante.color);
    m_currentColor->setToolTip(tr("Predefine color 1"));
    m_currentColor->setAutoFillBackground(true);
    m_currentColor->setScaledContents(true);

    // Ajout de la couleur actuelle au layout principal
    m_layoutSelector->addWidget(m_currentColor);
    m_layoutSelector->setAlignment(m_currentColor, Qt::AlignHCenter | Qt::AlignTop);

    // Création du layout de la grille de couleurs predefinies
    m_predefinedGrid = new QGridLayout();
    m_predefinedGrid->setSpacing(1);
    m_predefinedGrid->setMargin(1);
    // Ajout de la grille de couleurs predefinies dans le layout principal
    m_layoutSelector->addLayout(m_predefinedGrid);

    // Creation des widgets pour les couleurs predefinies
    int i=0, x=0, y=0;
    for (; i<48; i++)
    {
        QColor couleur(rouge[i],vert[i],bleu[i]);

        m_predefinedColor.append(new ColorWidget(this));
        m_predefinedColor[i]->setColor(couleur);
        m_predefinedColor[i]->setAutoFillBackground(true);
        m_predefinedColor[i]->setFixedHeight(5);
        m_predefinedColor[i]->setToolTip(tr("Predefine color %1 ").arg(i+1));
        connect(m_predefinedColor[i],SIGNAL(clicked(QColor)),this, SLOT(changeCurrentColor(QColor)));

        QColorDialog::setStandardColor(x*6+y, couleur.rgb());
        m_predefinedGrid->addWidget(m_predefinedColor[i], y, x);

        x++;
        y = x>=8?y+1:y;
        x = x>=8?0:x;
    }

    // Ajout d'un separateur entre les couleurs predefinies et les couleurs personnelles
    m_separator1 = new QWidget(this);
    m_separator1->setMaximumHeight(2);
    m_layoutSelector->addWidget(m_separator1);

    // Création du layout de la grille de couleurs personnelles
    m_characterGrid = new QGridLayout();
    m_characterGrid->setSpacing(1);
    m_characterGrid->setMargin(1);
    // Ajout de la grille de couleurs personnelles dans le layout principal
    m_layoutSelector->addLayout(m_characterGrid);

    // Creation des widgets pour les couleurs personnelles
    for (i=0, x=0, y=7; i<16; i++)
    {
        // Creation d'un widget de couleur blanche
        m_personalColor.append(new ColorWidget(this));
        connect(m_personalColor[i],SIGNAL(clicked(QColor)),this, SLOT(changeCurrentColor(QColor)));
        m_personalColor[i]->setAutoFillBackground(true);
        m_personalColor[i]->setFixedHeight(5);
        m_personalColor[i]->setToolTip(tr("Custom Color %1 ").arg(i+1));

        // Mise a jour des couleurs personnelles de QColorDialog
        QColorDialog::setCustomColor(i, m_preferences->value(QString("customcolors%1").arg(i),QColor(Qt::white)).value<QColor>().rgb());

        // Ajout du widget au layout
        m_characterGrid->addWidget(m_personalColor[i], y, x);

        x++;
        y = x>=8?y+1:y;
        x = x>=8?0:x;
    }
    updatePersonalColor();

    // Ajout d'un separateur entre les couleurs personnelles et les couleurs speciales
    m_separator2 = new QWidget(this);
    m_separator2->setMaximumHeight(3);
    m_layoutSelector->addWidget(m_separator2);

    // Création du layout des couleurs speciales
    m_specialColor = new QHBoxLayout();
    m_specialColor->setSpacing(1);
    m_specialColor->setMargin(0);
    // Ajout du layout des couleurs specuales dans le layout principal
    m_layoutSelector->addLayout(m_specialColor);

    // Ajout de la couleur speciale qui efface
    m_eraseColor = new QLabel(this);
    m_eraseColor->setFrameStyle(QFrame::Box | QFrame::Raised);
    m_eraseColor->setLineWidth(0);
    m_eraseColor->setMidLineWidth(1);
    m_eraseColor->setFixedHeight(15);
    m_pixelErase = new QPixmap(":/resources/icons/erase.png");
    m_eraseColor->setPixmap(*m_pixelErase);
    setBackgroundColorToWidget(m_eraseColor,QColor(Qt::white));
    m_eraseColor->setScaledContents(true);
    m_eraseColor->setToolTip(tr("Erase"));
    m_eraseColor->setAutoFillBackground(true);
    m_specialColor->addWidget(m_eraseColor);

    // Ajout de la couleur speciale qui masque
    m_maskColor = new QLabel(this);
    m_maskColor->setFrameStyle(QFrame::Box | QFrame::Raised);
    m_maskColor->setLineWidth(0);
    m_maskColor->setMidLineWidth(1);
    m_maskColor->setFixedHeight(15);
    setBackgroundColorToWidget(m_maskColor,QColor(Qt::white));
    m_maskPixel = new QPixmap(":/resources/icons/hide.png");
    m_maskColor->setPixmap(*m_maskPixel);
    m_maskColor->setScaledContents(true);
    m_maskColor->setAutoFillBackground(true);
    m_specialColor->addWidget(m_maskColor);

    // Ajout de la couleur speciale qui demasque
    m_unveilColor = new QLabel(this);
    m_unveilColor->setFrameStyle(QFrame::Box | QFrame::Raised);
    m_unveilColor->setLineWidth(0);
    m_unveilColor->setMidLineWidth(1);
    m_unveilColor->setFixedHeight(15);
    setBackgroundColorToWidget(m_unveilColor,QColor(Qt::white));
    m_unveilPixel = new QPixmap(":/resources/icons/showMap.png");
    m_unveilColor->setPixmap(*m_unveilPixel);
    m_unveilColor->setScaledContents(true);
    m_unveilColor->setAutoFillBackground(true);
    m_specialColor->addWidget(m_unveilColor);

    // Taille de la palette
    setFixedHeight(126);

    m_maskColor->installEventFilter(this);
    m_unveilColor->installEventFilter(this);
    m_eraseColor->installEventFilter(this);
    m_currentColor->installEventFilter(this);

}
void EvolutionGraphWidget::mouseDoubleClickEvent(QMouseEvent *event) 
{
	event->accept();
	if (event->button() == Qt::LeftButton)
		changeCurrentColor();
}