/*------------------------------------------------------------------------------
 src/lib/djWidget/imageOpRotate90Widget.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 {

ImageOpRotate90Widget::ImageOpRotate90Widget()
{
  LabelWidget * label = new LabelWidget("Rotate:");
  _widget = new EnumWidget<ImageOpRotate90::ROTATE>(imageOpRotate90Str());
  
  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 ImageOpRotate90Widget::set(ImageOp * in)
{
  ImageOpWidget::set(in);
  widgetUpdate();
}

void ImageOpRotate90Widget::widgetUpdate()
{
  ImageOpRotate90::ROTATE value = ImageOpRotate90::ROTATE(0);
  if (_op) {
    StrList data = _op->attr(
      imageOpRotate90AttrStr()[ImageOpRotate90::ATTR_VALUE]
    );
    inflateStr(data, &value, imageOpRotate90Str());
  }
  _widget->set(value);
}

void ImageOpRotate90Widget::widgetCallback(ImageOpRotate90::ROTATE in)
{
  if (! _op) return;
  _op->attr(
    imageOpRotate90AttrStr()[ImageOpRotate90::ATTR_VALUE],
    deflateStr(in, imageOpRotate90Str())
  );
  sig().emit(true);
  widgetUpdate();
}

}
