/* -*- 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 #include #include #include #include "recipe.h" #include "client.h" Viewer::Viewer() { setLayout(new QVBoxLayout()); lineEdit = new QLineEdit(); lineEdit->setVisible(false); layout()->addWidget(lineEdit); textEdit = new QTextEdit(); textEdit->setReadOnly(true); textEdit->setVisible(false); layout()->addWidget(textEdit); } void Viewer::show(const Recipe& recipe) { textEdit->setReadOnly(true); textEdit->setVisible(true); lineEdit->setVisible(false); title = QString::fromUtf8(recipe.title.data()); auto instructions = QString::fromUtf8(recipe.instructions.data()); instructions.replace("\n", "
"); QString ingredients; for(const auto& ingredient_group : recipe.ingredient_groups) { if(ingredient_group.title != "") { ingredients += "

" + QString::fromUtf8(ingredient_group.title.data()) + "

"; } ingredients += "
    "; for(const auto& ingredient : ingredient_group.ingredients) { if(ingredient.amount > 0) { ingredients += "
  • " + QString::number(ingredient.amount) + " " + QString::fromUtf8(ingredient.unit.data()) + " " + QString::fromUtf8(ingredient.item.data()) + "
  • "; } else { ingredients += "
  • " + QString::fromUtf8(ingredient.item.data()) + "
  • "; } } ingredients += "
"; } QByteArray image(recipe.image.data(), recipe.image.size()); if(recipe.image.substr(0, 4) == "/9j/") // Image is base64 encoded { image = QByteArray::fromBase64(image); } QString db; switch(recipe.db) { case DatabaseSource::KRecipes: db = "KRecipes"; break; case DatabaseSource::Gourmet: db = "Gourmet"; break; case DatabaseSource::Qookie: db = "Qookie"; break; } html = "
" + QString::fromUtf8(recipe.title.data()) + "

" "" "" "" "" "" "
" "

" + QString::fromUtf8(recipe.description.data()) + "

" "

" "Database: " + db + " (id:" + QString::number(recipe.id) + ")
" "Source: " + QString::fromUtf8(recipe.source.data()) + "
" "Cuisine: " + QString::fromUtf8(recipe.cuisine.data()) + "
" "Cooktime: " + QString::number(recipe.cooktime / 60) + "min
" "Preptime: " + QString::number(recipe.preptime / 60) + "min
" "Yields: " + QString::number(recipe.yields) + " " + QString::fromUtf8(recipe.yield_unit.data()) + "
" "Tags: " + QString::fromUtf8(recipe.tags[0].data()) + "" "

" "

Ingredienser

" + ingredients + "
" "" "
" "

Instruktioner

" "

" + instructions + "

" ; textEdit->setHtml(html); } void Viewer::scratchPad() { textEdit->setReadOnly(false); textEdit->setVisible(true); textEdit->setHtml(""); lineEdit->setVisible(true); lineEdit->setText(""); } const QString& Viewer::getTitle() { if(lineEdit->isVisible()) { title = lineEdit->text(); } return title; } const QString& Viewer::getHtml() { html = textEdit->toHtml(); return html; }