www.pudn.com > snake_vc++.rar > MainWindow.cpp


#include "MainWindow.h" 
#include "ImageLabel.h" 
 
#include  
#include  
#include  
 
//////////////////////////////////////////////////////////////////////////// 
MainWindow::MainWindow(QWidget* parent /* = 0 */, Qt::WindowFlags flags /* = 0 */) 
: QMainWindow(parent, flags), 
m_scaleFactor(1), 
m_ulPt(QPoint(150,150)), 
m_lrPt(QPoint(300,300)) 
{ 
	// create gui elements defined in the Ui_MainWindow class 
	setupUi(this); 
	// create and set a QLabel for image loading 
	m_imageLabel = new ImageLabel(this, m_imageFrame); 
	m_imageLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); 
    m_imageLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight); 
	m_imageLabel->resize(m_imageFrame->width(), m_imageFrame->height()); 
 
	// create a null image 
	m_image = new QImage(); 
 
	m_iterationOn->setChecked(true); 
 
	// signal - slot connections 
	QObject::connect(m_actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); 
	QObject::connect(m_actionZoomNormal, SIGNAL(triggered()), this, SLOT(slotZoomNormal())); 
	QObject::connect(m_snakeButton, SIGNAL(clicked()), this, SLOT(slotSnakeButtonPressed())); 
	QObject::connect(m_demoButton, SIGNAL(clicked()), this, SLOT(slotDemoButtonPressed())); 
	QObject::connect(m_initEllipseButton, SIGNAL(clicked()), this, SLOT(slotInitCurveButtonPressed())); 
 
	QObject::connect(m_iterationOn, SIGNAL(toggled(bool)), this, SLOT(slotIterationOn())); 
	QObject::connect(m_iterationOff, SIGNAL(toggled(bool)), this, SLOT(slotIterationOff())); 
	QObject::connect(m_iterationStep, SIGNAL(toggled(bool)), this, SLOT(slotIterationStep())); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
MainWindow::~MainWindow() 
{ 
	// no need to delete child widgets, QT does it all for us 
	if (!m_image->isNull()) 
	{ 
		delete m_image; 
		m_image = NULL; 
	} 
} 
 
void MainWindow::showImage(QImage *img) 
{ 
	if(m_imageLabel) 
		m_imageLabel->setPixmap(QPixmap::fromImage(*img)); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotOpen() 
{ 
	m_fileName = new QString(QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath())); 
 
	if (!m_fileName->isEmpty()) 
	{ 
		m_image->load(*m_fileName); 
		if (m_image->isNull()) 
		{ 
			QMessageBox::information(this, tr("Snake Ballooning"), 
				tr("Cannot load %1.").arg(*m_fileName)); 
			return; 
		} 
		m_imageLabel->setPixmap(QPixmap::fromImage(*m_image)); 
		emit signalImageOpened(); 
		 
		//scaleFactor = 1.0; 
 
        //printAct->setEnabled(true); 
        //fitToWindowAct->setEnabled(true); 
        //updateActions(); 
 
        //if (!fitToWindowAct->isChecked()) 
        //    imageLabel->adjustSize(); 
    } 
} 
 
//////////////////////////////////////////////////////////////////////////// 
//void MainWindow::slotSaveAs() 
//{ 
//	QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); 
//	QImage img = m_imageLabel->pixmap()->toImage(); 
//	img-> 
//} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotSnakeButtonPressed() 
{ 
	emit signalSnakeButtonPressed(); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotDemoButtonPressed() 
{ 
	emit signalDemoButtonPressed(); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotZoomNormal() 
{ 
	qDebug("zoom to original"); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotInitCurveButtonPressed() 
{ 
	emit signalInitCurve(); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotIterationOn() 
{ 
	if (m_iterationOn->isChecked()) 
		emit signalIterationOn(); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotIterationOff() 
{ 
	if (m_iterationOff->isChecked()) 
		emit signalIterationOff(); 
} 
 
//////////////////////////////////////////////////////////////////////////// 
void MainWindow::slotIterationStep() 
{ 
	if (m_iterationStep->isChecked()) 
		emit signalIterationStep(); 
}