diff --git a/RecipeDB.pro b/RecipeDB.pro
index e573956..791ba66 100644
--- a/RecipeDB.pro
+++ b/RecipeDB.pro
@@ -29,7 +29,11 @@ SOURCES += model/recipe/instruction.cpp \
gui/newrecipedialog.cpp \
model/recipe/tags/taglistmodel.cpp \
gui/newDialogs/newingredientdialog.cpp \
- gui/newDialogs/newtagdialog.cpp
+ gui/newDialogs/newtagdialog.cpp \
+ gui/newDialogs/newunitdialog.cpp \
+ utils/aspectratiopixmaplabel.cpp \
+ utils/stringutils.cpp \
+ openrecipedialog.cpp
HEADERS += model/recipe/instruction.h \
model/recipe/recipe.h \
@@ -48,14 +52,20 @@ HEADERS += model/recipe/instruction.h \
gui/newrecipedialog.h \
model/recipe/tags/taglistmodel.h \
gui/newDialogs/newingredientdialog.h \
- gui/newDialogs/newtagdialog.h
+ gui/newDialogs/newtagdialog.h \
+ gui/newDialogs/newunitdialog.h \
+ utils/aspectratiopixmaplabel.h \
+ utils/stringutils.h \
+ openrecipedialog.h
LIBS += -ldl \
FORMS += gui/mainwindow.ui \
gui/newrecipedialog.ui \
gui/newDialogs/newingredientdialog.ui \
- gui/newDialogs/newtagdialog.ui
+ gui/newDialogs/newtagdialog.ui \
+ gui/newDialogs/newunitdialog.ui \
+ openrecipedialog.ui
DISTFILES += \
.gitignore
diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui
index 58638ed..430cb1e 100644
--- a/gui/mainwindow.ui
+++ b/gui/mainwindow.ui
@@ -242,7 +242,7 @@ QPushButton#browseButton:pressed{
0
-
-
+
50
@@ -270,119 +270,6 @@ font: "Noto Sans CJK KR";
0
-
-
-
-
-
- Noto Sans CJK KR Light
-
-
-
-
-
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- Noto Sans CJK KR Light
- 12
-
-
-
- Prep Time:
-
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- Noto Sans CJK KR Light
- 12
-
-
-
- Cook Time:
-
-
-
-
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- Noto Sans CJK KR Light
- 12
-
-
-
- Servings:
-
-
-
-
-
-
-
@@ -419,14 +306,8 @@ font: "Noto Sans CJK KR";
-
-
-
-
- 0
- 0
-
-
-
+
+
0
@@ -442,219 +323,78 @@ font: "Noto Sans CJK KR";
0
-
-
-
-
-
- 0
- 0
-
-
-
-
- 250
- 16777215
-
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 0
- 40
-
-
-
-
- Noto Sans CJK KR Thin
- 18
-
-
-
- background-color: rgb(194, 196, 233);
-
-
- Ingredients
-
-
- Qt::AlignCenter
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- Noto Sans CJK KR Light
- 12
- PreferAntialias
-
-
-
- background-color: rgb(232, 232, 232);
-
-
- QFrame::NoFrame
-
-
- QFrame::Plain
-
-
- 0
-
-
- Qt::ScrollBarAlwaysOff
-
-
- QAbstractItemView::NoSelection
-
-
- true
-
-
- QListView::SinglePass
-
-
- true
-
-
-
-
-
-
-
-
+
-
+
0
0
- 400
- 0
+ 0
+ 40
-
+
+ background-color: rgb(208, 204, 255);
+
+
- 0
+ 2
- 0
+ 2
- 0
+ 2
- 0
+ 2
- 0
+ 2
-
-
-
-
-
- 0
- 0
-
-
-
-
- 0
- 40
-
-
+
-
+
- Noto Sans CJK KR Thin
- 18
+ Noto Sans CJK KR Light
+ 12
-
- background-color: rgb(218, 219, 234);
-
- Instructions
-
-
- Qt::AlignCenter
+ Prep Time:
-
-
-
-
- Noto Sans CJK KR Medium
- PreferAntialias
-
-
-
- background-color: rgb(244, 244, 244);
-
-
- QFrame::NoFrame
-
-
- QFrame::Plain
-
-
- 0
-
-
- Qt::ScrollBarAlwaysOff
-
-
- QAbstractScrollArea::AdjustToContents
-
-
- QTextEdit::AutoNone
-
-
- QTextEdit::WidgetWidth
-
-
+
+
true
-
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
-<html><head><meta name="qrichtext" content="1" /><style type="text/css">
-p, li { white-space: pre-wrap; }
-</style></head><body style=" font-family:'Noto Sans CJK KR Medium'; font-size:11pt; font-weight:400; font-style:normal;">
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; color:#00ff40;">This is some </span><span style=" font-family:'MS Shell Dlg 2'; font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html>
+
+
+ Noto Sans CJK KR Light
+ 12
+
-
- Qt::TextSelectableByMouse
+
+ Cook Time:
+
+
+
+ -
+
+
+
+ Noto Sans CJK KR Light
+ 12
+
+
+
+ Servings:
@@ -662,23 +402,14 @@ p, li { white-space: pre-wrap; }
-
-
+
0
0
-
-
- 200
- 0
-
-
-
- background-color: rgb(255, 255, 255);
-
-
+
0
@@ -694,17 +425,372 @@ p, li { white-space: pre-wrap; }
0
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 250
+ 16777215
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 40
+
+
+
+
+ Noto Sans CJK KR Thin
+ 18
+
+
+
+ background-color: rgb(194, 196, 233);
+
+
+ Ingredients
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ Noto Sans CJK KR Light
+ 12
+ PreferAntialias
+
+
+
+ background-color: rgb(232, 232, 232);
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Plain
+
+
+ 0
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ QAbstractItemView::ExtendedSelection
+
+
+ true
+
+
+ QListView::SinglePass
+
+
+ true
+
+
+
+
+
+
-
-
-
- :/images/images/no_image.png
+
+
+
+ 0
+ 0
+
-
- false
+
+
+ 400
+ 0
+
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 40
+
+
+
+
+ Noto Sans CJK KR Thin
+ 18
+
+
+
+ background-color: rgb(218, 219, 234);
+
+
+ Instructions
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ Noto Sans CJK KR Medium
+ PreferAntialias
+
+
+
+ background-color: rgb(244, 244, 244);
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Plain
+
+
+ 0
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ QAbstractScrollArea::AdjustToContents
+
+
+ QTextEdit::AutoNone
+
+
+ QTextEdit::WidgetWidth
+
+
+ true
+
+
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'Noto Sans CJK KR Medium'; font-size:11pt; font-weight:400; font-style:normal;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; color:#00ff40;">This is some </span><span style=" font-family:'MS Shell Dlg 2'; font-size:16pt; color:#a33c3e;">colored text and </span><a href="https://www.google.com"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt; text-decoration: underline; color:#0000ff;">link</span></a></p></body></html>
+
+
+ Qt::TextSelectableByMouse
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ 200
+ 0
+
+
+
+ background-color: rgb(255, 255, 255);
+
+
+
+ 6
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 200
+ 200
+
+
+
+
+ 500
+ 16777215
+
+
+
+ :/images/images/no_image.png
+
+
+ false
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ background-color: rgb(243, 243, 243);
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ Noto Sans CJK KR Light
+ 16
+ PreferAntialias
+
+
+
+ Tags
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ Noto Sans CJK KR Light
+ 12
+ PreferAntialias
+
+
+
+ background-color: rgb(255, 255, 255);
+
+
+ QFrame::NoFrame
+
+
+
+
+
+
+
@@ -720,6 +806,13 @@ p, li { white-space: pre-wrap; }
+
+
+ AspectRatioPixmapLabel
+ QLabel
+ utils/aspectratiopixmaplabel.h
+
+
diff --git a/gui/newDialogs/newunitdialog.cpp b/gui/newDialogs/newunitdialog.cpp
new file mode 100644
index 0000000..d89acaf
--- /dev/null
+++ b/gui/newDialogs/newunitdialog.cpp
@@ -0,0 +1,33 @@
+#include "newunitdialog.h"
+#include "ui_newunitdialog.h"
+
+NewUnitDialog::NewUnitDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::NewUnitDialog)
+{
+ ui->setupUi(this);
+
+ ui->typeComboBox->clear();
+ ui->typeComboBox->setItemData(0, "Mass");
+ ui->typeComboBox->setItemData(1, "Volume");
+ ui->typeComboBox->setItemData(2, "Length");
+ ui->typeComboBox->setItemData(3, "Misc");
+
+}
+
+NewUnitDialog::~NewUnitDialog()
+{
+ delete ui;
+}
+
+UnitOfMeasure NewUnitDialog::getUnit(){
+ return UnitOfMeasure(ui->unitNameEdit->text().toLower().toStdString(),
+ ui->pluralNameEdit->text().toLower().toStdString(),
+ ui->abbreviationEdit->text().toLower().toStdString(),
+ this->getSelectedType(),
+ ui->coefficientSpinBox->value());
+}
+
+int NewUnitDialog::getSelectedType(){
+ return ui->typeComboBox->currentIndex();
+}
diff --git a/gui/newDialogs/newunitdialog.h b/gui/newDialogs/newunitdialog.h
new file mode 100644
index 0000000..7221134
--- /dev/null
+++ b/gui/newDialogs/newunitdialog.h
@@ -0,0 +1,27 @@
+#ifndef NEWUNITDIALOG_H
+#define NEWUNITDIALOG_H
+
+#include
+
+#include "model/recipe/ingredients/unitofmeasure.h"
+
+namespace Ui {
+class NewUnitDialog;
+}
+
+class NewUnitDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ explicit NewUnitDialog(QWidget *parent = 0);
+ ~NewUnitDialog();
+
+ UnitOfMeasure getUnit();
+ private:
+ Ui::NewUnitDialog *ui;
+
+ int getSelectedType();
+};
+
+#endif // NEWUNITDIALOG_H
diff --git a/gui/newDialogs/newunitdialog.ui b/gui/newDialogs/newunitdialog.ui
new file mode 100644
index 0000000..953be58
--- /dev/null
+++ b/gui/newDialogs/newunitdialog.ui
@@ -0,0 +1,185 @@
+
+
+ NewUnitDialog
+
+
+
+ 0
+ 0
+ 240
+ 350
+
+
+
+ New Unit
+
+
+
+ :/images/images/icon.png:/images/images/icon.png
+
+
+ true
+
+
+ -
+
+
+
-
+
+
+ Unit Name
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ -
+
+
+ Plural Name
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ -
+
+
+ Abbreviation
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ Type:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+
-
+
+
+ Metric Coefficient
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ 1000.000000000000000
+
+
+ 1.000000000000000
+
+
+
+
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ NewUnitDialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ NewUnitDialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/gui/newrecipedialog.cpp b/gui/newrecipedialog.cpp
index 0517fd9..93e3ffa 100644
--- a/gui/newrecipedialog.cpp
+++ b/gui/newrecipedialog.cpp
@@ -144,6 +144,7 @@ void NewRecipeDialog::on_newTagButton_clicked(){
RecipeTag tag = d.getTag();
//Temporarily add this to the tags list, and it will be saved if the recipe is saved.
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());
@@ -166,3 +167,16 @@ void NewRecipeDialog::on_removeTagButton_clicked(){
this->populateTagsBox();
}
}
+
+void NewRecipeDialog::on_newUnitButton_clicked(){
+ NewUnitDialog d(this);
+ d.show();
+ if (d.exec() == QDialog::Accepted){
+ UnitOfMeasure u = d.getUnit();
+ if (!this->recipeDB->storeUnitOfMeasure(u)){
+ QMessageBox::critical(this, "Error", "Unable to store new unit.");
+ } else {
+ this->populateUnitsBox();
+ }
+ }
+}
diff --git a/gui/newrecipedialog.h b/gui/newrecipedialog.h
index f1c87cb..d272f3e 100644
--- a/gui/newrecipedialog.h
+++ b/gui/newrecipedialog.h
@@ -13,6 +13,7 @@
#include "gui/newDialogs/newingredientdialog.h"
#include "gui/newDialogs/newtagdialog.h"
+#include "gui/newDialogs/newunitdialog.h"
namespace Ui {
class NewRecipeDialog;
@@ -54,6 +55,8 @@ class NewRecipeDialog : public QDialog
void on_removeTagButton_clicked();
+ void on_newUnitButton_clicked();
+
private:
Ui::NewRecipeDialog *ui;
RecipeDatabase *recipeDB;
diff --git a/gui/newrecipedialog.ui b/gui/newrecipedialog.ui
index 82afc1d..e7ef5e9 100644
--- a/gui/newrecipedialog.ui
+++ b/gui/newrecipedialog.ui
@@ -155,7 +155,7 @@
0
1999
12
- 27
+ 26
@@ -662,6 +662,9 @@
-
+
+ background-color: rgb(255, 255, 255);
+
0
@@ -679,7 +682,13 @@
0
-
-
+
+
+
+ 0
+ 0
+
+
500
@@ -693,7 +702,7 @@
:/images/images/no_image.png
- true
+ false
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
@@ -816,6 +825,13 @@
+
+
+ AspectRatioPixmapLabel
+ QLabel
+ utils/aspectratiopixmaplabel.h
+
+
diff --git a/model/recipe/ingredients/ingredientlistmodel.cpp b/model/recipe/ingredients/ingredientlistmodel.cpp
index 7763671..916bbb0 100644
--- a/model/recipe/ingredients/ingredientlistmodel.cpp
+++ b/model/recipe/ingredients/ingredientlistmodel.cpp
@@ -12,17 +12,7 @@ QVariant IngredientListModel::data(const QModelIndex &index, int role) const{
int row = index.row();
RecipeIngredient i = this->ingredients[row];
- string displayStr;
-
- if (std::ceil(i.getQuantity()) == i.getQuantity()){
- //The quantity is an integer and should be casted.
- displayStr += std::to_string((int)i.getQuantity());
- } else {
- float q = i.getQuantity();
- displayStr += toString(q);
- }
-
- displayStr += " " + i.getUnit().getAbbreviation() + " " + i.getName();
+ string displayStr = i.toString();
switch(role){
case Qt::DisplayRole:
@@ -61,17 +51,3 @@ void IngredientListModel::deleteIngredient(int index){
vector IngredientListModel::getIngredients(){
return this->ingredients;
}
-
-string toString(float val){
- float decimal = std::fmod(val, 1.0f);
- int places = 1;
- while (std::fmod(decimal * 10, 1.0f) > 0){
- decimal *= 10;
- places++;
- }
- char buffer[50];
- string arg = "%."+std::to_string(places)+"f";
- sprintf(buffer, arg.c_str(), val);
- string s = buffer;
- return s;
-}
diff --git a/model/recipe/ingredients/ingredientlistmodel.h b/model/recipe/ingredients/ingredientlistmodel.h
index 3c3028d..738e570 100644
--- a/model/recipe/ingredients/ingredientlistmodel.h
+++ b/model/recipe/ingredients/ingredientlistmodel.h
@@ -28,6 +28,4 @@ private:
};
-string toString(float val);
-
#endif // INGREDIENTLISTMODEL_H
diff --git a/model/recipe/ingredients/recipeingredient.cpp b/model/recipe/ingredients/recipeingredient.cpp
index 7a3b75a..d8f115b 100644
--- a/model/recipe/ingredients/recipeingredient.cpp
+++ b/model/recipe/ingredients/recipeingredient.cpp
@@ -39,5 +39,18 @@ void RecipeIngredient::setUnit(UnitOfMeasure newUnit){
}
void RecipeIngredient::setComment(string newComment){
- this->comment = newComment;
+ this->comment = newComment;
+}
+
+string RecipeIngredient::toString(){
+ string result;
+ if (std::ceil(this->getQuantity()) == this->getQuantity()){
+ result += std::to_string((int)this->getQuantity());
+ } else {
+ result += StringUtils::toString(this->getQuantity());
+ }
+ result += " " + this->getUnit().getAbbreviation() + " " + this->getName();
+ if (!this->getComment().empty()) result += " ~" + this->getComment();
+
+ return result;
}
diff --git a/model/recipe/ingredients/recipeingredient.h b/model/recipe/ingredients/recipeingredient.h
index ae5fef9..cd044a5 100644
--- a/model/recipe/ingredients/recipeingredient.h
+++ b/model/recipe/ingredients/recipeingredient.h
@@ -2,9 +2,11 @@
#define RECIPEINGREDIENT_H
#include
+#include
#include "model/recipe/ingredients/ingredient.h"
#include "model/recipe/ingredients/unitofmeasure.h"
+#include "utils/stringutils.h"
using namespace std;
@@ -30,6 +32,7 @@ public:
void setQuantity(float newQuantity);
void setUnit(UnitOfMeasure newUnit);
void setComment(string newComment);
+ string toString();
private:
float quantity;
UnitOfMeasure unit;
diff --git a/model/recipe/ingredients/unitofmeasure.h b/model/recipe/ingredients/unitofmeasure.h
index b446e2e..96022fc 100644
--- a/model/recipe/ingredients/unitofmeasure.h
+++ b/model/recipe/ingredients/unitofmeasure.h
@@ -13,10 +13,10 @@ class UnitOfMeasure
{
public:
//Constants Declarations.
- static const int MASS = 1;
- static const int VOLUME = 2;
- static const int LENGTH = 3;
- static const int MISC = 4;
+ static const int MASS = 0;
+ static const int VOLUME = 1;
+ static const int LENGTH = 2;
+ static const int MISC = 3;
//Full constructor.
UnitOfMeasure(string name, string plural, string abbreviation, int type, double coef);
diff --git a/openrecipedialog.cpp b/openrecipedialog.cpp
new file mode 100644
index 0000000..950a06c
--- /dev/null
+++ b/openrecipedialog.cpp
@@ -0,0 +1,14 @@
+#include "openrecipedialog.h"
+#include "ui_openrecipedialog.h"
+
+OpenRecipeDialog::OpenRecipeDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::OpenRecipeDialog)
+{
+ ui->setupUi(this);
+}
+
+OpenRecipeDialog::~OpenRecipeDialog()
+{
+ delete ui;
+}
diff --git a/openrecipedialog.h b/openrecipedialog.h
new file mode 100644
index 0000000..ad95ad6
--- /dev/null
+++ b/openrecipedialog.h
@@ -0,0 +1,22 @@
+#ifndef OPENRECIPEDIALOG_H
+#define OPENRECIPEDIALOG_H
+
+#include
+
+namespace Ui {
+class OpenRecipeDialog;
+}
+
+class OpenRecipeDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ explicit OpenRecipeDialog(QWidget *parent = 0);
+ ~OpenRecipeDialog();
+
+ private:
+ Ui::OpenRecipeDialog *ui;
+};
+
+#endif // OPENRECIPEDIALOG_H
diff --git a/openrecipedialog.ui b/openrecipedialog.ui
new file mode 100644
index 0000000..31f318f
--- /dev/null
+++ b/openrecipedialog.ui
@@ -0,0 +1,19 @@
+
+
+ OpenRecipeDialog
+
+
+
+ 0
+ 0
+ 640
+ 480
+
+
+
+ Dialog
+
+
+
+
+
diff --git a/userInterface/mainwindow.cpp b/userInterface/mainwindow.cpp
index b39eec6..d2825d3 100644
--- a/userInterface/mainwindow.cpp
+++ b/userInterface/mainwindow.cpp
@@ -7,6 +7,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
ui->ingredientsListView->setModel(&this->ingredientModel);
+ ui->tagsListView->setModel(&this->tagsListModel);
}
MainWindow::MainWindow(RecipeDatabase *db, QWidget *parent) : MainWindow(parent){
@@ -21,10 +22,15 @@ void MainWindow::loadFromRecipe(Recipe recipe){
setRecipeName(recipe.getName());
setInstruction(recipe.getInstruction());
setIngredients(recipe.getIngredients());
- setImage(recipe.getImage());
+ if (recipe.getImage().isNull()){
+ setImage(QImage(QString(":/images/images/no_image.png")));
+ } else {
+ setImage(recipe.getImage());
+ }
setPrepTime(recipe.getPrepTime());
setCookTime(recipe.getCookTime());
setServings(recipe.getServings());
+ setTags(recipe.getTags());
}
void MainWindow::setRecipeName(string name){
@@ -52,7 +58,11 @@ void MainWindow::setCookTime(QTime cookTime){
}
void MainWindow::setServings(float servings){
- ui->servingsLabel->setText(QString("Servings: ")+QString::fromStdString(toString(servings)));
+ ui->servingsLabel->setText(QString("Servings: ")+QString::fromStdString(StringUtils::toString(servings)));
+}
+
+void MainWindow::setTags(vector tags){
+ this->tagsListModel.setTags(tags);
}
void MainWindow::on_newButton_clicked(){
diff --git a/userInterface/mainwindow.h b/userInterface/mainwindow.h
index 1605311..b5bcdb5 100644
--- a/userInterface/mainwindow.h
+++ b/userInterface/mainwindow.h
@@ -8,6 +8,7 @@
#include "model/recipe/recipe.h"
#include "model/recipe/ingredients/ingredientlistmodel.h"
#include "gui/newrecipedialog.h"
+#include "utils/stringutils.h"
using namespace std;
@@ -33,6 +34,7 @@ public:
Ui::MainWindow *ui;
RecipeDatabase *recipeDB;
IngredientListModel ingredientModel;
+ TagListModel tagsListModel;
//Hidden manipulation methods.
void setRecipeName(string name);
@@ -42,6 +44,7 @@ public:
void setPrepTime(QTime prepTime);
void setCookTime(QTime cookTime);
void setServings(float servings);
+ void setTags(vector tags);
};
#endif // MAINWINDOW_H
diff --git a/utils/aspectratiopixmaplabel.cpp b/utils/aspectratiopixmaplabel.cpp
new file mode 100644
index 0000000..9347b8e
--- /dev/null
+++ b/utils/aspectratiopixmaplabel.cpp
@@ -0,0 +1,36 @@
+#include "aspectratiopixmaplabel.h"
+
+AspectRatioPixmapLabel::AspectRatioPixmapLabel(QWidget *parent) :
+ QLabel(parent)
+{
+ this->setMinimumSize(1,1);
+ setScaledContents(false);
+}
+
+void AspectRatioPixmapLabel::setPixmap ( const QPixmap & p)
+{
+ pix = p;
+ QLabel::setPixmap(scaledPixmap());
+}
+
+int AspectRatioPixmapLabel::heightForWidth( int width ) const
+{
+ return pix.isNull() ? this->height() : ((qreal)pix.height()*width)/pix.width();
+}
+
+QSize AspectRatioPixmapLabel::sizeHint() const
+{
+ int w = this->width();
+ return QSize( w, heightForWidth(w) );
+}
+
+QPixmap AspectRatioPixmapLabel::scaledPixmap() const
+{
+ return pix.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+}
+
+void AspectRatioPixmapLabel::resizeEvent(QResizeEvent * e)
+{
+ if(!pix.isNull())
+ QLabel::setPixmap(scaledPixmap());
+}
diff --git a/utils/aspectratiopixmaplabel.h b/utils/aspectratiopixmaplabel.h
new file mode 100644
index 0000000..b9fee0b
--- /dev/null
+++ b/utils/aspectratiopixmaplabel.h
@@ -0,0 +1,23 @@
+#ifndef ASPECTRATIOPIXMAPLABEL_H
+#define ASPECTRATIOPIXMAPLABEL_H
+
+#include
+#include
+#include
+
+class AspectRatioPixmapLabel : public QLabel
+{
+ Q_OBJECT
+public:
+ explicit AspectRatioPixmapLabel(QWidget *parent = 0);
+ virtual int heightForWidth( int width ) const;
+ virtual QSize sizeHint() const;
+ QPixmap scaledPixmap() const;
+public slots:
+ void setPixmap ( const QPixmap & );
+ void resizeEvent(QResizeEvent *);
+private:
+ QPixmap pix;
+};
+
+#endif // ASPECTRATIOPIXMAPLABEL_H
diff --git a/utils/stringutils.cpp b/utils/stringutils.cpp
new file mode 100644
index 0000000..3ed578b
--- /dev/null
+++ b/utils/stringutils.cpp
@@ -0,0 +1,19 @@
+#include "stringutils.h"
+
+namespace StringUtils{
+
+std::string toString(float val){
+ float decimal = std::fmod(val, 1.0f);
+ int places = 1;
+ while (std::fmod(decimal * 10, 1.0f) > 0){
+ decimal *= 10;
+ places++;
+ }
+ char buffer[50];
+ std::string arg = "%."+std::to_string(places)+"f";
+ sprintf(buffer, arg.c_str(), val);
+ std::string s = buffer;
+ return s;
+}
+
+}
diff --git a/utils/stringutils.h b/utils/stringutils.h
new file mode 100644
index 0000000..c678e46
--- /dev/null
+++ b/utils/stringutils.h
@@ -0,0 +1,13 @@
+#ifndef STRINGUTILS_H
+#define STRINGUTILS_H
+
+#include
+#include
+
+namespace StringUtils{
+
+ std::string toString(float val);
+
+}
+
+#endif // STRINGUTILS_H