From 29f38402c15b6c8a5516352a376e26fe1774711b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 13 Jul 2013 12:38:46 +0000 Subject: Adds a status bar. --- src/mainwindow.cc | 19 ++++++++++++++++++- src/mainwindow.h | 35 +++++++++++++++++------------------ src/solverwindow.cc | 24 +++++++++++++++++++++--- src/solverwindow.h | 3 +++ 4 files changed, 59 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cc b/src/mainwindow.cc index adb45e6..8ab6c70 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -40,7 +40,11 @@ MainWindow::MainWindow() initMenus(); + initStatus(); + updateTitle(); + + connect(mainwindow_solverwindow, SIGNAL(statusChanged(const QString &)), this, SLOT(updateStatus(const QString &))); } @@ -142,6 +146,13 @@ void MainWindow::initMenus() mainwindow_helpmenu->addAction(action_about); } + +void MainWindow::initStatus() +{ + setStatusBar(new QStatusBar(this)); + statusBar()->showMessage(PACKAGE_STRING); +} + void MainWindow::updateTitle() { if (mainwindow_solverwindow->filename().isEmpty()) { @@ -150,12 +161,18 @@ void MainWindow::updateTitle() action_revert->setEnabled(false); } else { - setWindowTitle(mainwindow_solverwindow->filename() + " - " + PACKAGE_NAME); + QFileInfo fileinfo(mainwindow_solverwindow->filename()); + setWindowTitle(fileinfo.baseName() + " - " + PACKAGE_NAME); action_revert->setEnabled(true); } } +void MainWindow::updateStatus(const QString & text) +{ + statusBar()->showMessage(text); +} + void MainWindow::doNew() { mainwindow_solverwindow->doNew(); diff --git a/src/mainwindow.h b/src/mainwindow.h index b928c68..def0bc8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -17,13 +17,26 @@ class MainWindow : public QMainWindow public: MainWindow(); -private: - void initActions(); +private slots: + void updateTitle(); + void updateStatus(const QString & text); - void initMenus(); + void doNew(); + void doOpen(); + void doSave(); + void doSaveAs(); + void doRevert(); + void doQuit(); - void updateTitle(); + void doValidate(); + void doAbout(); + +private: + void initActions(); + void initMenus(); + void initStatus(); + SolverWindow *mainwindow_solverwindow; QMenu *mainwindow_gamemenu; QMenu *mainwindow_movemenu; @@ -47,20 +60,6 @@ private: // Help menu actions QAction *action_about; - -private slots: - - void doNew(); - void doOpen(); - void doSave(); - void doSaveAs(); - void doRevert(); - void doQuit(); - - void doValidate(); - - void doAbout(); - }; #endif // __INCLUDED_SUDOKUSOLVER_MAINWINDOW__ diff --git a/src/solverwindow.cc b/src/solverwindow.cc index 6102c09..9e0c782 100644 --- a/src/solverwindow.cc +++ b/src/solverwindow.cc @@ -3,6 +3,8 @@ #include "sudokuwidget.h" #include "sudoku.h" +#include "config.h" + #include #include #include @@ -41,10 +43,14 @@ void SolverWindow::openFromFile(const QString & filename) QFile file(filename); if (!file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::warning(this, tr("Open"), + QMessageBox::warning(this, tr("Error opening file"), tr("Could not open file \"%1\":\n%2.") .arg(filename) .arg(file.errorString())); + + QFileInfo fileinfo(filename); + emit statusChanged(tr("Could not open file \"%1\"").arg(fileinfo.fileName())); + return; } @@ -64,6 +70,9 @@ void SolverWindow::openFromFile(const QString & filename) solverwindow_sudokuwidget->set_values(sudoku); solverwindow_filename = filename; + QFileInfo fileinfo(filename); + emit statusChanged(tr("Opened file \"%1\"").arg(fileinfo.fileName())); + QApplication::restoreOverrideCursor(); } @@ -72,10 +81,14 @@ void SolverWindow::saveToFile(const QString & filename) { QFile file(filename); if (!file.open(QFile::WriteOnly | QFile::Text)) { - QMessageBox::warning(this, tr("Save"), - tr("Could not write to file \"%1\":\n%2.") + QMessageBox::warning(this, tr("Error saving file"), + tr("Could not save file \"%1\":\n%2.") .arg(filename) .arg(file.errorString())); + + QFileInfo fileinfo(filename); + emit statusChanged(tr("Could not save file \"%1\"").arg(fileinfo.fileName())); + return; } @@ -106,6 +119,9 @@ void SolverWindow::saveToFile(const QString & filename) solverwindow_filename = filename; + QFileInfo fileinfo(filename); + emit statusChanged(tr("Saved file \"%1\"").arg(fileinfo.fileName())); + QApplication::restoreOverrideCursor(); } @@ -164,6 +180,8 @@ void SolverWindow::doNew() Sudoku sudoku; solverwindow_sudokuwidget->set_values(sudoku); solverwindow_filename.clear(); + + emit statusChanged(PACKAGE_STRING); } } diff --git a/src/solverwindow.h b/src/solverwindow.h index 053e14a..d279a1a 100644 --- a/src/solverwindow.h +++ b/src/solverwindow.h @@ -47,6 +47,9 @@ public slots: void doValidate(); +signals: + void statusChanged(const QString &text); + private: void step_constraints(); void step_coverage(); -- cgit v1.2.3