Source

3dmaze / mainwindow.cpp

/* Copyright (C) 2010 by Eric Waller 
  
   Build and display a maze in either 2-D or 3-D

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   ewwaller@gmail.com

   Revision History

   Date        Author      Description
   ---------   ----------  -----------
   2010.7.20   E Waller    Initial Release
*/

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sizedialog.h"
#include <QtCore/QSize>
#include <QMessageBox>
#include "ui_about.h"
#include "ui_render.h"

MainWindow::MainWindow(QWidget *parent)
  : QMainWindow(parent), ui(new Ui::MainWindow)
{
  ui->setupUi(this);
  connect (ui->actionSet_Size,SIGNAL(triggered()), this, SLOT(SetMazeSize()));
  connect (ui->actionAbout, SIGNAL(triggered()), this, SLOT(About()));
  connect (ui->actionAbout_Qt, SIGNAL(triggered()),this,SLOT(AboutQt()));
  connect (ui->actionCopy, SIGNAL(triggered()),this,SLOT(Copy()));
  connect (ui->actionNew_Maze, SIGNAL(triggered()),this,SLOT(NewMaze()));
  connect (ui->actionPrint, SIGNAL(triggered()),this,SLOT(Print()));
  connect (ui->actionShow_3d_Maze,SIGNAL(toggled(bool)),this,SLOT(Show3DMazeChanged(bool)));
  connect (ui->actionShow_Solution,SIGNAL(toggled(bool)),this,SLOT(ShowSolutionChanged(bool)));
  xSize=11; ySize=11;
  xSize=21; ySize=21;
  theRenderDialog = 0;
  NewMaze();
}

MainWindow::~MainWindow()
{
  delete ui;
}

void MainWindow::SetMazeSize()
{
  SizeDialog theDialog;
  theDialog.SetSize(xSize,ySize);
  if (theDialog.exec() == QDialog::Accepted)
    {
      theDialog.GetSize(&xSize,&ySize);
      xSize |= 1; ySize |=1;
    }
  NewMaze();
}

void MainWindow::NewMaze()
{
  ui->theMaze->CreateMaze(xSize,ySize);
  if (theRenderDialog)
    theRenderDialog->SetMazeEngine(ui->theMaze->GetMazeEngine(),ui->actionShow_Solution->isChecked());
}

void MainWindow::About()
{
  Ui_AboutDialog theAboutDialogSettings;
  QDialog theAboutDialog;
  theAboutDialogSettings.setupUi(&theAboutDialog);
  theAboutDialog.exec();
}

void MainWindow::AboutQt()
{
  QMessageBox::aboutQt(this,"About QT");
}

void MainWindow::Print()
{
  ui->theMaze->printIt();
}

void MainWindow::Copy()
{
    ui->theMaze->Copy();
}

void MainWindow::ShowSolutionChanged(bool theNewState)
{
  ui->theMaze->setShowSolution(theNewState);
  if (theRenderDialog)
    theRenderDialog->SetMazeEngine(ui->theMaze->GetMazeEngine(),theNewState);
}

void MainWindow::Show3DMazeChanged(bool theNewState)
{
  if (theNewState)
    {
      if (! theRenderDialog)
        theRenderDialog = new RenderDialog;
      theRenderDialog->show();
      connect (theRenderDialog,SIGNAL(ClosingRenderDialog()),this,SLOT(CloseRenderDialog()));
      theRenderDialog->SetMazeEngine(ui->theMaze->GetMazeEngine(),ui->actionShow_Solution->isChecked()); 
    }
  else if (theRenderDialog)
    theRenderDialog->close();
}

void MainWindow::CloseRenderDialog()
{
  ui->actionShow_3d_Maze->setChecked(false);
  delete theRenderDialog;
  theRenderDialog=0;
}