Added support for custom images.
This commit is contained in:
parent
041d56e1a9
commit
cbb2079a7f
|
@ -29,12 +29,13 @@ Recipe NewRecipeDialog::getRecipe(){
|
|||
Recipe r(ui->recipeNameEdit->text().toStdString(),
|
||||
this->ingredientListModel.getIngredients(),
|
||||
ui->instructionsTextEdit->toHtml().toStdString(),
|
||||
QImage(),//Image
|
||||
this->img,//Image
|
||||
this->tagsListModel.getTags(),//Tags
|
||||
QDate::currentDate(),
|
||||
ui->prepTimeEdit->time(),
|
||||
ui->cookTimeEdit->time(),
|
||||
(float)ui->servingsSpinBox->value());
|
||||
return r;
|
||||
}
|
||||
|
||||
bool NewRecipeDialog::isAccepted() const{
|
||||
|
@ -103,9 +104,17 @@ void NewRecipeDialog::on_addTagButton_clicked(){
|
|||
}
|
||||
|
||||
void NewRecipeDialog::on_deleteTagButton_clicked(){
|
||||
QModelIndexList indexList = ui->tagsListView->selectedIndexes();
|
||||
QModelIndexList indexList = ui->tagsListView->selectionModel()->selectedIndexes();
|
||||
for (QModelIndexList::iterator it = indexList.begin(); it != indexList.end(); ++it){
|
||||
QModelIndex i = *it;
|
||||
this->tagsListModel.deleteTag(i.row());
|
||||
}
|
||||
}
|
||||
|
||||
void NewRecipeDialog::on_selectImageButton_clicked(){
|
||||
QString filename = QFileDialog::getOpenFileName(this, "Open Image", QString(), "Image Files (*.png *.jpg *.bmp)");
|
||||
if (!filename.isEmpty()){
|
||||
this->img = QImage(filename);
|
||||
ui->imageDisplayLabel->setPixmap(QPixmap(filename));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include <QTextCharFormat>
|
||||
#include <QFileDialog>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "model/database/recipedatabase.h"
|
||||
#include "model/recipe/ingredients/ingredientlistmodel.h"
|
||||
|
@ -36,6 +38,10 @@ class NewRecipeDialog : public QDialog
|
|||
|
||||
void on_addTagButton_clicked();
|
||||
|
||||
void on_deleteTagButton_clicked();
|
||||
|
||||
void on_selectImageButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::NewRecipeDialog *ui;
|
||||
RecipeDatabase *recipeDB;
|
||||
|
@ -44,6 +50,7 @@ class NewRecipeDialog : public QDialog
|
|||
vector<RecipeTag> tags;
|
||||
IngredientListModel ingredientListModel;
|
||||
TagListModel tagsListModel;
|
||||
QImage img;
|
||||
bool accepted = false;
|
||||
|
||||
//Helper functions to fill fields.
|
||||
|
|
|
@ -630,9 +630,18 @@
|
|||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="imageDisplayLabel">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>500</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../images.qrc">:/images/images/no_image.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -641,6 +650,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="selectImageButton">
|
||||
<property name="text">
|
||||
<string>Select Image...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -735,6 +751,8 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
//Custom methods to handle ingredient data.
|
||||
void setIngredients(vector<RecipeIngredient> ingredients);
|
||||
bool addIngredient(RecipeIngredient ri);
|
||||
void deleteIngredient(int index);
|
||||
vector<RecipeIngredient> getIngredients();
|
||||
|
||||
private:
|
||||
|
|
|
@ -16,6 +16,7 @@ class TagListModel : public QAbstractListModel
|
|||
|
||||
void setTags(vector<RecipeTag> tags);
|
||||
bool addTag(RecipeTag tag);
|
||||
void deleteTag(int index);
|
||||
vector<RecipeTag> getTags();
|
||||
private:
|
||||
vector<RecipeTag> tags;
|
||||
|
|
Loading…
Reference in New Issue