MainWindow::MainWindow()
{
	openAction = new QAction(tr("&Open"), this);
	saveAction = new QAction(tr("&Save"), this);
	exitAction = new QAction(tr("E&xit"), this);
	equalAction = new QAction(tr("&Equalization"), this);
	otsuAction = new QAction(tr("&otsu"), this);
	isodataAction = new QAction(tr("&Isodata"), this);
	manualAction = new QAction(tr("&Manual"), this);
	gammaAction = new QAction(tr("&Gamma"), this);
	stretchingAction = new QAction(tr("&Stretching"), this);
	sigmaAction = new QAction(tr("&Sigma"), this);
	medianAction = new QAction(tr("&Median"), this);
	lineAction = new QAction(tr("&Lines"), this);
	pixelAction = new QAction(tr("&Pixels"), this);
	gaussianAction = new QAction(tr("&Gaussian"), this);
	sobelAction = new QAction(tr("&Sobel"), this);	
	horizontalAction = new QAction(tr("&Line Intensity"), this);
	cannyAction = new QAction(tr("&Canny"),this);
	sumAction = new QAction(tr("&Add"),this);
	resAction = new QAction(tr("&Substract"),this);
	multAction = new QAction(tr("&Multiply"),this);
	divAction = new QAction(tr("&Divide"),this);
	avgAction = new QAction(tr("A&verage"),this);
	andAction = new QAction(tr("&And"),this);
	orAction = new QAction(tr("&Or"),this);
	xorAction = new QAction(tr("&Xor"),this);
	notAction = new QAction(tr("&Not"),this);
	minAction = new QAction(tr("M&in"),this);
	maxAction = new QAction(tr("M&ax"),this);
	kmeansAction = new QAction(tr("&Kmeans"),this);

	saveAction->setEnabled(false);

	connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
	connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
	connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
	connect(equalAction, SIGNAL(triggered()), this, SLOT(equalization()));
	connect(otsuAction, SIGNAL(triggered()), this, SLOT(otsuThresh()));
	connect(isodataAction, SIGNAL(triggered()), this, SLOT(isodataSlot()));
	connect(manualAction, SIGNAL(triggered()), this, SLOT(manual()));
	connect(gammaAction,SIGNAL(triggered()),this,SLOT(gamma()));
	connect(stretchingAction,SIGNAL(triggered()),this,SLOT(stretching()));
	connect(sigmaAction, SIGNAL(triggered()), this, SLOT(sigma()));
	connect(medianAction, SIGNAL(triggered()), this, SLOT(median()));
	connect(lineAction, SIGNAL(triggered()), this, SLOT(line()));
	connect(pixelAction, SIGNAL(triggered()), this, SLOT(pixel()));
	connect(gaussianAction, SIGNAL(triggered()), this, SLOT(gaussian()));
	connect(sobelAction, SIGNAL(triggered()), this, SLOT(sobelEdges()));
	connect(horizontalAction,SIGNAL(triggered()),this,SLOT(horizontal()));
	connect(cannyAction,SIGNAL(triggered()),this,SLOT(cannySlot()));
	connect(sumAction,SIGNAL(triggered()),this,SLOT(sum()));
	connect(resAction,SIGNAL(triggered()),this,SLOT(res()));
	connect(multAction,SIGNAL(triggered()),this,SLOT(mult()));
	connect(divAction,SIGNAL(triggered()),this,SLOT(div()));
	connect(avgAction,SIGNAL(triggered()),this,SLOT(avg()));
	connect(andAction,SIGNAL(triggered()),this,SLOT(andSlot()));
	connect(orAction,SIGNAL(triggered()),this,SLOT(orSlot()));
	connect(xorAction,SIGNAL(triggered()),this,SLOT(xorSlot()));
	connect(notAction,SIGNAL(triggered()),this,SLOT(notSlot()));
	connect(minAction,SIGNAL(triggered()),this,SLOT(minSlot()));
	connect(maxAction,SIGNAL(triggered()),this,SLOT(maxSlot()));
	connect(kmeansAction,SIGNAL(triggered()),this,SLOT(kmeansSlot()));
	
	fileMenu = menuBar()->addMenu(tr("&File"));
	equalizationMenu = menuBar()->addMenu(tr("&Equalization"));
	thresholdMenu = menuBar()->addMenu(tr("&Thresholding"));
	contrastMenu = menuBar()->addMenu(tr("&Contrast"));
	noiseMenu = menuBar()->addMenu(tr("&Noise"));
	edgeMenu = menuBar()->addMenu(tr("E&dge"));
	operationMenu = menuBar()->addMenu(tr("&Operation"));
	boolMenu = operationMenu->addMenu(tr("&Boolean"));
	arithMenu = operationMenu->addMenu(tr("&Arithmetic"));
	relMenu = operationMenu->addMenu(tr("&Relational"));
	segmentationMenu = menuBar()->addMenu(tr("&Segmentation"));
	
	equalizationMenu->setEnabled(false);
	thresholdMenu->setEnabled(false);
	contrastMenu->setEnabled(false);
	noiseMenu->setEnabled(false);
	edgeMenu->setEnabled(false);
	operationMenu->setEnabled(false);
	segmentationMenu->setEnabled(false);
	
	fileMenu->addAction(openAction);
	fileMenu->addAction(saveAction);
	fileMenu->addSeparator();
	fileMenu->addAction(exitAction);

	equalizationMenu->addAction(equalAction);
	
	thresholdMenu->addAction(otsuAction);
	thresholdMenu->addAction(isodataAction);
	thresholdMenu->addAction(manualAction);
	
	contrastMenu->addAction(gammaAction);
	contrastMenu->addAction(stretchingAction);
	
	noiseMenu->addAction(sigmaAction);
	noiseMenu->addAction(medianAction);
	noiseMenu->addAction(lineAction);
	noiseMenu->addAction(pixelAction);
	noiseMenu->addAction(gaussianAction);
	
	edgeMenu->addAction(sobelAction);
	edgeMenu->addAction(horizontalAction);
	edgeMenu->addAction(cannyAction);

	boolMenu->addAction(andAction);
	boolMenu->addAction(orAction);
	boolMenu->addAction(xorAction);
	boolMenu->addAction(notAction);
	
	arithMenu->addAction(sumAction);
	arithMenu->addAction(resAction);
	arithMenu->addAction(multAction);
	arithMenu->addAction(divAction);
	arithMenu->addAction(avgAction);
	
	relMenu->addAction(minAction);
	relMenu->addAction(maxAction);
	
	segmentationMenu->addAction(kmeansAction);
	//-----

	viewer = new ImageViewer(this);
	
	QScrollArea * scrollArea = new QScrollArea;
	scrollArea->setWidget(viewer);
	scrollArea->setFixedWidth(600);
    scrollArea->setWidgetResizable(true);
    
 	boxW = new QSpinBox();
 	boxW->setEnabled(false);
 	boxW->setMaximum(65535);
 	
 	boxC = new QSpinBox();
 	boxC->setEnabled(false);
 	boxC->setMaximum(65535);
	
	histoViewer = new ImageViewer(this);
	QScrollArea * histoArea = new QScrollArea;
	histoArea->setWidget(histoViewer);
	histoArea->setFixedSize(268,278);
    histoArea->setWidgetResizable(false);
	
	QVBoxLayout * rightLayout = new QVBoxLayout;
	rightLayout->addWidget(new QLabel("Window:",this));
	rightLayout->addWidget(boxW);
	rightLayout->addWidget(new QLabel("Level:",this));
	rightLayout->addWidget(boxC);
	rightLayout->addWidget(histoArea);
	
	connect(boxW,SIGNAL(valueChanged(int)),this,SLOT(changeW(int)));
	connect(boxC,SIGNAL(valueChanged(int)),this,SLOT(changeC(int)));
	
	QWidget * rightSide = new QWidget;
	rightSide->setLayout(rightLayout);
	
	QHBoxLayout *mainLayout = new QHBoxLayout;
	mainLayout->addWidget(scrollArea);
	mainLayout->addWidget(rightSide);	

	
	QWidget * centralWidget = new QWidget();
	centralWidget->setLayout(mainLayout);
	
	
	setCentralWidget(centralWidget);

	setWindowTitle(tr("DICOM Image Processor"));
    setFixedSize(QSize(900,600));
}
void CLjz153View::OnEqual() 
{
	// TODO: Add your command handler code here
	equalization();
	Invalidate();
}