/*------------------------------------------------------------------------------
 src/lib/djWidget/imageOpColorWidget.cxx
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djImageOpColorWidget.h"
#include <djGroupBoxWidget.h>
#include <djColorWidget.h>

namespace dj {

ImageOpColorWidget::ImageOpColorWidget()
{
  _widget = new ColorWidget;
  _widget->floatMax(2.0);
  
  VLayout * layout = new VLayout(this);
  layout->add(_widget);
  layout->stretchAdd();
  
  widgetUpdate();
  
  _widget->sig().set(this, widgetCallback);
}

void ImageOpColorWidget::set(ImageOp * in)
{
  ImageOpWidget::set(in);
  widgetUpdate();
}

void ImageOpColorWidget::widgetCallback(const Color & in)
{
  if (! _op) return;
  _op->attr(imageOpColorAttrStr()[ImageOpColor::ATTR_VALUE], deflateStr(in));
  sig().emit(true);
  widgetUpdate();
}

void ImageOpColorWidget::widgetUpdate()
{
  Color value;
  if (_op) {
    StrList data = _op->attr(imageOpColorAttrStr()[ImageOpColor::ATTR_VALUE]);
    inflateStr(data, &value);
  }
  _widget->set(value);
}

ImageOpColor2Widget::ImageOpColor2Widget()
{
  _widget = new ColorWidget;
  _widget->floatMax(2.0);
  _widget2 = new ColorWidget;
  _widget2->floatMax(2.0);
  
  VLayout * layout = new VLayout(this);
  layout->add(_widget);
  layout->add(_widget2);
  layout->stretchAdd();
  
  widgetUpdate();
  
  _widget->sig().set(this, widgetCallback);
  _widget2->sig().set(this, widget2Callback);
}

void ImageOpColor2Widget::set(ImageOp * in)
{
  ImageOpWidget::set(in);
  widgetUpdate();
}

void ImageOpColor2Widget::widgetCallback(const Color & in)
{
  if (! _op) return;
  _op->attr(
    imageOpColor2AttrStr()[ImageOpColor2::ATTR_VALUE], deflateStr(in)
  );
  sig().emit(true);
  widgetUpdate();
}

void ImageOpColor2Widget::widget2Callback(const Color & in)
{
  if (! _op) return;
  _op->attr(
    imageOpColor2AttrStr()[ImageOpColor2::ATTR_VALUE_2], deflateStr(in)
  );
  sig().emit(true);
  widgetUpdate();
}

void ImageOpColor2Widget::widgetUpdate()
{
  Color value, value2;
  if (_op) {
    StrList data = _op->attr(imageOpColor2AttrStr()[ImageOpColor2::ATTR_VALUE]);
    inflateStr(data, &value);
    data = _op->attr(imageOpColor2AttrStr()[ImageOpColor2::ATTR_VALUE_2]);
    inflateStr(data, &value2);
  }
  _widget->set(value);
  _widget2->set(value2);
}

ImageOpHueWidget::ImageOpHueWidget()
{
  widget()->floatMax(1.0);
}

ImageOpLevelsInWidget::ImageOpLevelsInWidget()
{
  widget()->floatMax(1.0);
  widget2()->floatMax(1.0);
}

ImageOpLevelsOutWidget::ImageOpLevelsOutWidget()
{
  widget()->floatMax(1.0);
  widget2()->floatMax(1.0);
}

ImageOpSoftClipWidget::ImageOpSoftClipWidget()
{
  widget()->floatMax(1.0);
}

}
