00001 #include "MainWindow.h"
00002 #include "ImageLabel.h"
00003
00004 #include <QtGui/QFileDialog>
00005 #include <QtGui/QMessageBox>
00006 #include <QtGui/QRadioButton>
00007
00009 MainWindow::MainWindow(QWidget* parent , Qt::WindowFlags flags )
00010 : QMainWindow(parent, flags),
00011 m_scaleFactor(1),
00012 m_ulPt(QPoint(150,150)),
00013 m_lrPt(QPoint(300,300))
00014 {
00015
00016 setupUi(this);
00017
00018 m_imageLabel = new ImageLabel(this, m_imageFrame);
00019 m_imageLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00020 m_imageLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight);
00021 m_imageLabel->resize(m_imageFrame->width(), m_imageFrame->height());
00022
00023
00024 m_image = new QImage();
00025
00026 m_iterationOn->setChecked(true);
00027
00028
00029 QObject::connect(m_actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
00030 QObject::connect(m_actionZoomNormal, SIGNAL(triggered()), this, SLOT(slotZoomNormal()));
00031 QObject::connect(m_snakeButton, SIGNAL(clicked()), this, SLOT(slotSnakeButtonPressed()));
00032 QObject::connect(m_demoButton, SIGNAL(clicked()), this, SLOT(slotDemoButtonPressed()));
00033 QObject::connect(m_initEllipseButton, SIGNAL(clicked()), this, SLOT(slotInitCurveButtonPressed()));
00034
00035 QObject::connect(m_iterationOn, SIGNAL(toggled(bool)), this, SLOT(slotIterationOn()));
00036 QObject::connect(m_iterationOff, SIGNAL(toggled(bool)), this, SLOT(slotIterationOff()));
00037 QObject::connect(m_iterationStep, SIGNAL(toggled(bool)), this, SLOT(slotIterationStep()));
00038 }
00039
00041 MainWindow::~MainWindow()
00042 {
00043
00044 if (!m_image->isNull())
00045 {
00046 delete m_image;
00047 m_image = NULL;
00048 }
00049 }
00050
00051 void MainWindow::showImage(QImage *img)
00052 {
00053 if(m_imageLabel)
00054 m_imageLabel->setPixmap(QPixmap::fromImage(*img));
00055 }
00056
00058 void MainWindow::slotOpen()
00059 {
00060 m_fileName = new QString(QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()));
00061
00062 if (!m_fileName->isEmpty())
00063 {
00064 m_image->load(*m_fileName);
00065 if (m_image->isNull())
00066 {
00067 QMessageBox::information(this, tr("Snake Ballooning"),
00068 tr("Cannot load %1.").arg(*m_fileName));
00069 return;
00070 }
00071 m_imageLabel->setPixmap(QPixmap::fromImage(*m_image));
00072 emit signalImageOpened();
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 }
00083 }
00084
00086
00087
00088
00089
00090
00091
00092
00094 void MainWindow::slotSnakeButtonPressed()
00095 {
00096 emit signalSnakeButtonPressed();
00097 }
00098
00100 void MainWindow::slotDemoButtonPressed()
00101 {
00102 emit signalDemoButtonPressed();
00103 }
00104
00106 void MainWindow::slotZoomNormal()
00107 {
00108 qDebug("zoom to original");
00109 }
00110
00112 void MainWindow::slotInitCurveButtonPressed()
00113 {
00114 emit signalInitCurve();
00115 }
00116
00118 void MainWindow::slotIterationOn()
00119 {
00120 if (m_iterationOn->isChecked())
00121 emit signalIterationOn();
00122 }
00123
00125 void MainWindow::slotIterationOff()
00126 {
00127 if (m_iterationOff->isChecked())
00128 emit signalIterationOff();
00129 }
00130
00132 void MainWindow::slotIterationStep()
00133 {
00134 if (m_iterationStep->isChecked())
00135 emit signalIterationStep();
00136 }
00137