void MainWindow::setCompleted() { QMessageBox::information(this, tr("Puzzle Completed"), tr("Congratulations! You have completed the puzzle!\n" "Click OK to start again."), QMessageBox::Ok); setupPuzzle(); }
void MainWindow::loadImage(const QString &fileName) { QPixmap newImage; if (!newImage.load(fileName)) { QMessageBox::warning(this, tr("Open Image"), tr("The image file could not be loaded."), QMessageBox::Close); return; } puzzleImage = newImage; setupPuzzle(); }
void MainWindow::setupMenus() { QMenu *fileMenu = menuBar()->addMenu(tr("&File")); QAction *openAction = fileMenu->addAction(tr("&Open...")); openAction->setShortcuts(QKeySequence::Open); QAction *exitAction = fileMenu->addAction(tr("E&xit")); exitAction->setShortcuts(QKeySequence::Quit); QMenu *gameMenu = menuBar()->addMenu(tr("&Game")); QAction *restartAction = gameMenu->addAction(tr("&Restart")); connect(openAction, SIGNAL(triggered()), this, SLOT(openImage())); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(restartAction, SIGNAL(triggered()), this, SLOT(setupPuzzle())); }
void MainWindow::openImage(const QString &path) { QString fileName = path; if (fileName.isNull()) fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", "Image Files (*.png *.jpg *.bmp)"); if (!fileName.isEmpty()) { QPixmap newImage; if (!newImage.load(fileName)) { QMessageBox::warning(this, tr("Open Image"), tr("The image file could not be loaded."), QMessageBox::Cancel); return; } puzzleImage = newImage; setupPuzzle(); } }
void MainWindow::openImage(const QString &path) { QString fileName = path; if (fileName.isNull()) { fileName = QFileDialog::getOpenFileName(this, "Open image", "", "Image files(*.png *jpg *bmp)"); } if (fileName.isEmpty() == false) { QPixmap newImage; if (newImage.load(fileName) == false) { QMessageBox::warning(this, "Open image", "This image file couldn't be loaded", QMessageBox::Cancel); return; } puzzleImage = newImage; setupPuzzle(); } }
void MainWindow::setCompleted() { QMessageBox::information(this, "Puzzle Completed", "Congratulations! Clicked Ok to restart", QMessageBox::Ok); setupPuzzle(); }