#include "FeatherMain.qo.h"
#include <guitools/Feather/PlotHolder.qo.h>
#include <guitools/Feather/FeatherDataType.h>
#include <guitools/Feather/FeatherManager.qo.h>
#include <images/Images/ImageUtilities.h>
#include <casa/Utilities/PtrHolder.h>
using namespace casacore;
const int FeatherMain::DISH_DIAMETER_DEFAULT = -1;
const int FeatherMain::SINGLE_DISH_FACTOR_DEFAULT = 1;
FeatherMain::FeatherMain(QWidget *parent)
: QMainWindow(parent), fileLoader( this ),
preferences( this ), preferencesColor( this ),
plotHolder(NULL), progressMeter(this), overWriteFileDialog( this ),
logger(LogOrigin("CASA", "Feather")){
ui.outputLabel->setText("");
dataManager = new FeatherManager();
connect( dataManager, SIGNAL(featheringDone()), this, SLOT( featheringDone()));
plotHolder = new PlotHolder( this );
QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget( plotHolder );
ui.plotHolderWidget->setLayout( layout );
connect( plotHolder, SIGNAL(dishDiameterChangedX(double)), this, SLOT(dishDiameterXChanged(double)));
connect( plotHolder, SIGNAL(dishDiameterChangedY(double)), this, SLOT(dishDiameterYChanged(double)));
progressMeter.setWindowTitle( "Feather");
progressMeter.setLabelText( "Feathering Images...");
progressMeter.setWindowModality( Qt::WindowModal );
progressMeter.setCancelButton( 0 );
progressMeter.setMinimum( 0 );
progressMeter.setMaximum( 0 );
connect( this, SIGNAL( featherFinished()), &progressMeter, SLOT(cancel()));
connect( &overWriteFileDialog, SIGNAL( overWriteOK()), this, SLOT( overWriteOK()));
QDoubleValidator* validator = new QDoubleValidator( 0, std::numeric_limits<double>::max(), 10, this );
ui.dishDiameterXLineEdit->setValidator( validator );
ui.dishDiameterYLineEdit->setValidator( validator );
ui.singleDishFactorLineEdit->setValidator( validator );
initializeDishDiameterLimit( ui.dishDiameterXLimitLabel );
initializeDishDiameterLimit( ui.dishDiameterYLimitLabel );
connect( ui.dishDiameterXLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(dishDiameterXChanged(const QString&)));
connect( ui.dishDiameterYLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(dishDiameterYChanged(const QString&)));
ui.featherButton->setEnabled( false );
QActionGroup* paletteGroup = new QActionGroup(this );
ui.actionDiameterSelector->setActionGroup( paletteGroup );
ui.actionRectangleZoom->setActionGroup( paletteGroup );