/*

Copyright (C) 2009, Etienne Moutot <e.moutot@gmail.com>

This file is part of colorPickerWidget.

    colorPickerWidget 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 3 of the License, or
    (at your option) any later version.

    colorPickerWidget 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.

    You should have received a copy of the GNU General Public License
    along with colorPickerWidget.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "colorpickerwidget.h"

ColorPickerWidget::ColorPickerWidget(QWidget *parent)
    : QWidget(parent)
{
    this->setGeometry(0,0,parent->width(),parent->height());
    ecran=0;
    colorTriangle = new QtColorTriangle(this);
    connect(colorTriangle, SIGNAL(colorChanged(QColor)), this, SLOT(changeColor(QColor)));
    //this->setGeometry(0,0,150,150);

    /*colorView = new ColorViewer(this);
    colorView->setColor(colorTriangle->color());
        connect(colorTriangle, SIGNAL(colorChanged(QColor)), colorView, SLOT(changeColor(QColor)));

    pickColor = new QPushButton(tr("Pick a color"), this);
        connect(pickColor, SIGNAL(released()), this, SLOT(pickMode()));*/

    //layout = new QGridLayout;
    //layout->addWidget(  colorTriangle,  0, 0, 0, 0);
    //layout->addWidget(  colorView,      0, 2, 2, 1);
    //layout->addWidget(  pickColor,      2, 2, 1, 1);

    //setLayout(layout);
}

ColorPickerWidget::~ColorPickerWidget()
{
}

void ColorPickerWidget::changeColor(QColor mycol)
{
	red = mycol.red();
	green = mycol.green();
	blue = mycol.blue();
	emit finchange();
}

void ColorPickerWidget::setColor(int wlred, int wlgreen, int wlblue)
{
	colorTriangle->setColor(QColor(wlred,wlgreen,wlblue));
	red = wlred;
	green = wlgreen;
	blue = wlblue;
}

void ColorPickerWidget::pickMode()
{
    if(ecran!=0)
        delete ecran;
    ecran = new screen;
        connect( ecran, SIGNAL(colorSelected(QColor)), colorTriangle, SLOT(setColor(QColor)) );
}
