diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-04-24 15:44:35 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-26 18:41:20 +0200 |
commit | 60cacb4babb46ae2ab22ae0b7b7357012887460d (patch) | |
tree | e68cea1bd5a3cd84a5514740a515ce12772170da /src/viewer.cc | |
parent | e5d35d6b643dbb8ecbd3ece2a0d84ec93cadbfc1 (diff) |
Better viewer. Set license to GPL 3.
Diffstat (limited to 'src/viewer.cc')
-rw-r--r-- | src/viewer.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/viewer.cc b/src/viewer.cc new file mode 100644 index 0000000..9ed0dba --- /dev/null +++ b/src/viewer.cc @@ -0,0 +1,96 @@ +/* -*- c++ -*- */ +/*************************************************************************** + * viewer.cc + * + * Sun Apr 24 09:04:57 CEST 2022 + * Copyright 2022 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Qookie. + * + * Qookie is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Qookie is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Qookie; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "viewer.h" + +#include <iostream> + +#include <QTextEdit> +#include <QHBoxLayout> + +#include "recipe.h" + +Viewer::Viewer() +{ + setLayout(new QHBoxLayout()); + textEdit = new QTextEdit(); + layout()->addWidget(textEdit); + textEdit->setReadOnly(true); +} + +void Viewer::show(const Recipe& recipe) +{ + auto instructions = QString::fromUtf8(recipe.instructions.data()); + instructions.replace("\n", "<br/>"); + + QString ingredients; + for(const auto& ingredient : recipe.ingredients) + { + if(ingredient.amount > 0) + { + ingredients += + "<li>" + + QString::number(ingredient.amount) + " " + + QString::fromUtf8(ingredient.unit.data()) + " " + + QString::fromUtf8(ingredient.item.data()) + + "</li>"; + } + else + { + ingredients += + "<li>" + + QString::fromUtf8(ingredient.item.data()) + + "</li>"; + } + } + + QByteArray image(recipe.image.data(), recipe.image.size()); + if(recipe.image.substr(0, 4) == "/9j/") // Image is base64 encoded + { + image = QByteArray::fromBase64(image); + } + + QString html = + "<center><strong style=\"font-size:28px;\">" + QString::fromUtf8(recipe.title.data()) + "</strong></center><br/>" + "<p>" + "<img height=\"300\" src=\"data:image/png;base64," + image.toBase64() + "\"/>" + "</p>" + "<p>" + QString::fromUtf8(recipe.description.data()) + "</p>" + "<p>" + "Source: " + QString::fromUtf8(recipe.source.data()) + "<br/>" + "Cuisine: " + QString::fromUtf8(recipe.cuisine.data()) + "<br/>" + "Cooktime: " + QString::number(recipe.cooktime / 60) + "min<br/>" + "Preptime: " + QString::number(recipe.preptime / 60) + "min<br/>" + "Yields: " + QString::number(recipe.yields) + " " + QString::fromUtf8(recipe.yield_unit.data()) + "<br/>" + "Tags: " + QString::fromUtf8(recipe.tags[0].data()) + "" + "</p>" + "<h2>Ingredients</h2>" + "<ul>" + ingredients + "</ul>" + "<h2>Instructions</h2>" + "<p>" + instructions + "</p>" + ; + textEdit->setHtml(html); +} |