RecipeDB/userInterface/mainwindow.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

#include "userInterface/mainwindow.h"
2018-02-02 09:00:46 +00:00
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
2018-02-12 13:24:11 +00:00
ui(new Ui::MainWindow){
2018-02-02 09:00:46 +00:00
ui->setupUi(this);
ui->ingredientsListView->setModel(&this->ingredientModel);
ui->tagsListView->setModel(&this->tagsListModel);
2018-02-02 09:00:46 +00:00
}
MainWindow::MainWindow(RecipeDatabase *db, QWidget *parent) : MainWindow(parent){
this->recipeDB = db;
}
2018-02-12 13:24:11 +00:00
MainWindow::~MainWindow(){
2018-02-02 09:00:46 +00:00
delete ui;
}
2018-02-12 13:24:11 +00:00
void MainWindow::loadFromRecipe(Recipe recipe){
setRecipeName(recipe.getName());
setInstruction(recipe.getInstruction());
2018-02-12 13:24:11 +00:00
setIngredients(recipe.getIngredients());
if (recipe.getImage().isNull()){
setImage(QImage(QString(":/images/images/no_image.png")));
} else {
setImage(recipe.getImage());
}
2018-03-10 15:02:01 +00:00
setPrepTime(recipe.getPrepTime());
setCookTime(recipe.getCookTime());
setServings(recipe.getServings());
setTags(recipe.getTags());
2018-02-12 13:24:11 +00:00
}
void MainWindow::setRecipeName(string name){
ui->recipeNameLabel->setText(QString::fromStdString(name));
}
void MainWindow::setInstruction(Instruction instruction){
ui->instructionsTextEdit->setHtml(QString::fromStdString(instruction.getHTML()));
2018-02-12 13:24:11 +00:00
}
void MainWindow::setIngredients(vector<RecipeIngredient> ingredients){
this->ingredientModel.setIngredients(ingredients);
}
void MainWindow::setImage(QImage img){
ui->imageLabel->setPixmap(QPixmap::fromImage(img));
}
2018-03-10 15:02:01 +00:00
void MainWindow::setPrepTime(QTime prepTime){
ui->prepTimeLabel->setText(QString("Prep Time: ")+prepTime.toString("hh:mm:ss"));
}
void MainWindow::setCookTime(QTime cookTime){
ui->cookTimeLabel->setText(QString("Cook Time: ")+cookTime.toString("hh:mm:ss"));
}
void MainWindow::setServings(float servings){
ui->servingsLabel->setText(QString("Servings: ")+QString::fromStdString(StringUtils::toString(servings)));
}
void MainWindow::setTags(vector<RecipeTag> tags){
this->tagsListModel.setTags(tags);
2018-03-10 15:02:01 +00:00
}
void MainWindow::on_newButton_clicked(){
NewRecipeDialog d(this->recipeDB, this);
d.show();
d.exec();
if (d.isAccepted()){
Recipe r = d.getRecipe();
if (!this->recipeDB->storeRecipe(r)){
QMessageBox::critical(this, QString("Unable to Save Recipe"), QString("The program was not able to successfully save the recipe."));
}
this->loadFromRecipe(r);
}
2018-02-12 13:24:11 +00:00
}
void MainWindow::on_openButton_clicked(){
OpenRecipeDialog d(this->recipeDB, this);
d.show();
d.exec();
}