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

//#define DJ_DBG
#include "djImageOpXformWidget.h"
#include <djLabelWidget.h>

namespace dj {

ImageOpMirrorWidget::ImageOpMirrorWidget()
{
  LabelWidget * label = new LabelWidget("Mirror:");
  _widget = new EnumWidget<ImageOpMirror::MIRROR>(imageOpMirrorStr());
  
  VLayout * layout = new VLayout(this);
  HLayout * subLayout = new HLayout(layout);
  subLayout->margin(0);
  subLayout->add(label);
  subLayout->add(_widget);
  layout->stretchAdd();
  
  widgetUpdate();
  
  _widget->sig().set(this, widgetCallback);
}

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

void ImageOpMirrorWidget::widgetUpdate()
{
  ImageOpMirror::MIRROR value = ImageOpMirror::MIRROR(0);
  if (_op) {
    StrList data = _op->attr(imageOpMirrorAttrStr()[ImageOpMirror::ATTR_VALUE]);
    inflateStr(data, &value, imageOpMirrorStr());
  }
  _widget->set(value);
}

void ImageOpMirrorWidget::widgetCallback(ImageOpMirror::MIRROR in)
{
  if (! _op) return;
  _op->attr(
    imageOpMirrorAttrStr()[ImageOpMirror::ATTR_VALUE],
    deflateStr(in, imageOpMirrorStr())
  );
  sig().emit(true);
  widgetUpdate();
}

}
