2018-03-04 08:05:20 +00:00
|
|
|
#include "newrecipedialog.h"
|
|
|
|
#include "ui_newrecipedialog.h"
|
|
|
|
|
|
|
|
NewRecipeDialog::NewRecipeDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
2018-03-10 07:51:17 +00:00
|
|
|
ui(new Ui::NewRecipeDialog){
|
2018-03-04 08:05:20 +00:00
|
|
|
ui->setupUi(this);
|
2018-03-10 09:42:22 +00:00
|
|
|
|
2018-03-10 11:36:14 +00:00
|
|
|
setModal(true);
|
|
|
|
|
2018-03-10 09:42:22 +00:00
|
|
|
ui->ingredientsListView->setModel(&this->ingredientListModel);
|
2018-03-10 11:36:14 +00:00
|
|
|
ui->tagsListView->setModel(&this->tagsListModel);
|
2018-03-04 08:05:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 07:51:17 +00:00
|
|
|
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, QWidget *parent) : NewRecipeDialog(parent){
|
|
|
|
this->recipeDB = db;
|
|
|
|
|
|
|
|
this->populateIngredientsBox();
|
|
|
|
this->populateUnitsBox();
|
2018-03-10 11:36:14 +00:00
|
|
|
this->populateTagsBox();
|
2018-03-10 07:51:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 21:25:28 +00:00
|
|
|
NewRecipeDialog::NewRecipeDialog(RecipeDatabase *db, Recipe recipe, QWidget *parent) : NewRecipeDialog(db, parent){
|
|
|
|
ui->recipeNameEdit->setText(QString::fromStdString(recipe.getName()));
|
2018-03-31 13:02:35 +00:00
|
|
|
ui->authorNameEdit->setText(QString::fromStdString(recipe.getAuthor()));
|
2018-03-30 21:25:28 +00:00
|
|
|
ui->prepTimeEdit->setTime(recipe.getPrepTime());
|
|
|
|
ui->cookTimeEdit->setTime(recipe.getCookTime());
|
|
|
|
ui->servingsSpinBox->setValue((double)recipe.getServings());
|
|
|
|
ui->instructionsTextEdit->setHtml(QString::fromStdString(recipe.getInstruction().getHTML()));
|
|
|
|
ui->imageDisplayLabel->setPixmap(QPixmap::fromImage(recipe.getImage()));
|
|
|
|
this->tagsListModel.setTags(recipe.getTags());
|
|
|
|
this->ingredientListModel.setIngredients(recipe.getIngredients());
|
|
|
|
}
|
|
|
|
|
2018-03-10 07:51:17 +00:00
|
|
|
NewRecipeDialog::~NewRecipeDialog(){
|
2018-03-04 08:05:20 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
2018-03-10 07:51:17 +00:00
|
|
|
|
2018-03-10 11:36:14 +00:00
|
|
|
Recipe NewRecipeDialog::getRecipe(){
|
|
|
|
Recipe r(ui->recipeNameEdit->text().toStdString(),
|
2018-03-31 13:02:35 +00:00
|
|
|
ui->authorNameEdit->text().toStdString(),
|
2018-03-10 11:36:14 +00:00
|
|
|
this->ingredientListModel.getIngredients(),
|
|
|
|
ui->instructionsTextEdit->toHtml().toStdString(),
|
2018-03-31 12:01:57 +00:00
|
|
|
ui->imageDisplayLabel->pixmap()->toImage(),//Image
|
2018-03-10 11:36:14 +00:00
|
|
|
this->tagsListModel.getTags(),//Tags
|
|
|
|
QDate::currentDate(),
|
|
|
|
ui->prepTimeEdit->time(),
|
|
|
|
ui->cookTimeEdit->time(),
|
|
|
|
(float)ui->servingsSpinBox->value());
|
2018-03-10 12:22:04 +00:00
|
|
|
return r;
|
2018-03-10 11:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NewRecipeDialog::isAccepted() const{
|
|
|
|
return this->accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::populateTagsBox(){
|
|
|
|
this->tags = this->recipeDB->retrieveAllTags();
|
|
|
|
ui->tagsComboBox->clear();
|
|
|
|
for (unsigned int i = 0; i < this->tags.size(); i++){
|
|
|
|
QString s = QString::fromStdString(this->tags[i].getValue());
|
|
|
|
ui->tagsComboBox->insertItem(i, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-10 09:42:22 +00:00
|
|
|
void NewRecipeDialog::on_addIngredientButton_clicked(){
|
2018-05-22 19:24:36 +00:00
|
|
|
Ingredient ing(ui->ingredientLineEdit->text().toStdString());
|
|
|
|
this->ingredientListModel.addIngredient(ing);
|
|
|
|
ui->ingredientLineEdit->clear();
|
2018-03-10 09:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::on_italicsButton_clicked(){
|
|
|
|
ui->instructionsTextEdit->setFontItalic(ui->italicsButton->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::on_boldButton_clicked(){
|
|
|
|
if (ui->boldButton->isChecked()){
|
|
|
|
ui->instructionsTextEdit->setFontWeight(QFont::Bold);
|
|
|
|
} else {
|
|
|
|
ui->instructionsTextEdit->setFontWeight(QFont::Normal);
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 11:36:14 +00:00
|
|
|
|
|
|
|
void NewRecipeDialog::on_buttonBox_accepted(){
|
|
|
|
this->accepted = true;
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::on_buttonBox_rejected(){
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::on_addTagButton_clicked(){
|
|
|
|
this->tagsListModel.addTag(this->tags[ui->tagsComboBox->currentIndex()]);
|
|
|
|
}
|
2018-03-10 11:58:31 +00:00
|
|
|
|
|
|
|
void NewRecipeDialog::on_deleteTagButton_clicked(){
|
2018-03-10 12:22:04 +00:00
|
|
|
QModelIndexList indexList = ui->tagsListView->selectionModel()->selectedIndexes();
|
2018-03-10 11:58:31 +00:00
|
|
|
for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
|
|
|
|
QModelIndex i = *it;
|
|
|
|
this->tagsListModel.deleteTag(i.row());
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 12:22:04 +00:00
|
|
|
|
|
|
|
void NewRecipeDialog::on_selectImageButton_clicked(){
|
|
|
|
QString filename = QFileDialog::getOpenFileName(this, "Open Image", QString(), "Image Files (*.png *.jpg *.bmp)");
|
|
|
|
if (!filename.isEmpty()){
|
|
|
|
ui->imageDisplayLabel->setPixmap(QPixmap(filename));
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 13:06:24 +00:00
|
|
|
|
2018-03-29 14:09:58 +00:00
|
|
|
void NewRecipeDialog::on_removeIngredientButton_clicked(){
|
2018-03-10 13:06:24 +00:00
|
|
|
QModelIndexList indexList = ui->ingredientsListView->selectionModel()->selectedIndexes();
|
|
|
|
for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
|
|
|
|
QModelIndex i = *it;
|
|
|
|
this->ingredientListModel.deleteIngredient(i.row());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewRecipeDialog::on_newTagButton_clicked(){
|
2018-03-10 13:56:43 +00:00
|
|
|
NewTagDialog d(this);
|
2018-03-10 13:06:24 +00:00
|
|
|
d.show();
|
2018-03-10 13:56:43 +00:00
|
|
|
if (d.exec() == QDialog::Accepted){
|
|
|
|
RecipeTag tag = d.getTag();
|
|
|
|
//Temporarily add this to the tags list, and it will be saved if the recipe is saved.
|
2018-03-30 10:56:42 +00:00
|
|
|
if (!tag.getValue().empty()){
|
|
|
|
this->tags.push_back(tag);
|
|
|
|
this->tagsListModel.addTag(tag);
|
|
|
|
ui->tagsComboBox->clear();
|
|
|
|
for (unsigned int i = 0; i < this->tags.size(); i++){
|
|
|
|
QString s = QString::fromStdString(this->tags[i].getValue());
|
|
|
|
ui->tagsComboBox->insertItem(i, s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QMessageBox::warning(this, "Empty Tag", "The tag you entered is blank!");
|
2018-03-10 13:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-03-10 13:06:24 +00:00
|
|
|
|
2018-03-10 13:56:43 +00:00
|
|
|
void NewRecipeDialog::on_removeTagButton_clicked(){
|
2018-03-29 14:09:58 +00:00
|
|
|
unsigned int index = ui->tagsComboBox->currentIndex();
|
|
|
|
if (index >= this->tags.size()){
|
2018-03-10 13:56:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
RecipeTag tag = this->tags[ui->tagsComboBox->currentIndex()];
|
2018-03-29 09:21:00 +00:00
|
|
|
string content = "Are you sure you wish to delete the following tag:\n"+tag.getValue()+"\nThis will delete the tag for all recipes that use it.";
|
2018-03-10 13:56:43 +00:00
|
|
|
QMessageBox::StandardButton reply = QMessageBox::question(this, QString("Delete Tag"), QString(content.c_str()));
|
|
|
|
if (reply == QMessageBox::Yes){
|
|
|
|
this->recipeDB->deleteTag(tag);
|
|
|
|
this->populateTagsBox();
|
|
|
|
}
|
2018-03-10 13:06:24 +00:00
|
|
|
}
|