From 1346537ab4fbd6c9853161c4accc8073a9975372 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 12 Jul 2013 21:08:47 +0000 Subject: Cleans up user interface actions and message boxes. --- src/mainwindow.cc | 62 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'src/mainwindow.cc') diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 873502e..7cfdf4b 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -37,6 +37,8 @@ MainWindow::MainWindow() initActions(); initMenus(); + + updateTitle(); } @@ -49,56 +51,57 @@ void MainWindow::initActions() connect(action_new, SIGNAL(triggered()), this, SLOT(doNew())); // Game -> Load - action_load = new QAction(tr("&Load..."), this); - action_load->setShortcuts(QKeySequence::Open); - action_load->setStatusTip(tr("Load a previously saved game")); - connect(action_load, SIGNAL(triggered()), this, SLOT(doLoad())); + action_open = new QAction(tr("&Open..."), this); + action_open->setShortcuts(QKeySequence::Open); + action_open->setStatusTip(tr("Open a previously saved game")); + connect(action_open, SIGNAL(triggered()), this, SLOT(doOpen())); // Game -> Save action_save = new QAction(tr("&Save"), this); - action_load->setStatusTip(tr("Save the current game")); + action_save->setShortcuts(QKeySequence::Save); + action_save->setStatusTip(tr("Save the current game")); connect(action_save, SIGNAL(triggered()), this, SLOT(doSave())); // Game -> Save As action_saveas = new QAction(tr("Save &As..."), this); - action_load->setStatusTip(tr("Save the current game to a new file")); + action_saveas->setStatusTip(tr("Save the current game to a new file")); connect(action_saveas, SIGNAL(triggered()), this, SLOT(doSaveAs())); // Game -> Revert action_revert = new QAction(tr("&Revert"), this); action_revert->setStatusTip(tr("Reload the current game from file")); - connect(action_revert, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(revert())); + connect(action_revert, SIGNAL(triggered()), this, SLOT(doRevert())); // Game -> Quit action_quit = new QAction(tr("&Quit"), this); action_quit->setShortcuts(QKeySequence::Quit); action_quit->setStatusTip(tr("Exit the application")); - connect(action_quit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + connect(action_quit, SIGNAL(triggered()), this, SLOT(doQuit())); // Move -> Hint action_hint = new QAction(tr("Hint"), this); action_hint->setStatusTip(tr("Give a hint")); - // TODO + // TODO connect() // Move -> Step action_step = new QAction(tr("Step"), this); action_step->setStatusTip(tr("Solve a single cell")); - connect(action_step, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(step())); + connect(action_step, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(doStep())); // Move -> Step action_guess = new QAction(tr("Guess"), this); action_guess->setStatusTip(tr("Solve a single cell with guessing")); - connect(action_guess, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(guess())); + connect(action_guess, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(doGuess())); // Move -> Solve action_solve = new QAction(tr("Solve rules"), this); action_solve->setStatusTip(tr("Solve sudoku rules")); - connect(action_solve, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(solve())); + connect(action_solve, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(doSolve())); // Move -> Search action_search = new QAction(tr("Find solution"), this); action_search->setStatusTip(tr("Find a solution")); - connect(action_search, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(search())); + connect(action_search, SIGNAL(triggered()), mainwindow_solverwindow, SLOT(doSearch())); // Move -> Validate action_validate = new QAction(tr("Validate"), this); @@ -110,7 +113,7 @@ void MainWindow::initMenus() { mainwindow_gamemenu = menuBar()->addMenu(tr("&Game")); mainwindow_gamemenu->addAction(action_new); - mainwindow_gamemenu->addAction(action_load); + mainwindow_gamemenu->addAction(action_open); mainwindow_gamemenu->addSeparator(); mainwindow_gamemenu->addAction(action_save); mainwindow_gamemenu->addAction(action_saveas); @@ -133,37 +136,54 @@ void MainWindow::updateTitle() { if (mainwindow_solverwindow->filename().isEmpty()) { setWindowTitle("Sudoku"); + + action_revert->setEnabled(false); + } else { setWindowTitle(mainwindow_solverwindow->filename() + " - Sudoku"); + + action_revert->setEnabled(true); } } void MainWindow::doNew() { - mainwindow_solverwindow->clear(); + mainwindow_solverwindow->doNew(); updateTitle(); } void MainWindow::doSave() { - mainwindow_solverwindow->save(); + mainwindow_solverwindow->doSave(); updateTitle(); } void MainWindow::doSaveAs() { - mainwindow_solverwindow->saveas(); + mainwindow_solverwindow->doSaveAs(); + updateTitle(); +} + +void MainWindow::doOpen() +{ + mainwindow_solverwindow->doOpen(); updateTitle(); } -void MainWindow::doLoad() +void MainWindow::doRevert() { - mainwindow_solverwindow->load(); + mainwindow_solverwindow->doRevert(); updateTitle(); } void MainWindow::doValidate() { - mainwindow_solverwindow->validate(); + mainwindow_solverwindow->doValidate(); +} + +void MainWindow::doQuit() +{ + if (QMessageBox::question(this, tr("Quit"), tr("Exit the application?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + qApp->closeAllWindows(); + } } - \ No newline at end of file -- cgit v1.2.3