From 60cacb4babb46ae2ab22ae0b7b7357012887460d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 24 Apr 2022 15:44:35 +0200 Subject: Better viewer. Set license to GPL 3. --- src/viewer.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/viewer.cc (limited to 'src/viewer.cc') 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 + +#include +#include + +#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", "
"); + + QString ingredients; + for(const auto& ingredient : recipe.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()) + + "
  • "; + } + } + + 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 = + "
    " + QString::fromUtf8(recipe.title.data()) + "

    " + "

    " + "" + "

    " + "

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

    " + "

    " + "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()) + "" + "

    " + "

    Ingredients

    " + "
      " + ingredients + "
    " + "

    Instructions

    " + "

    " + instructions + "

    " + ; + textEdit->setHtml(html); +} -- cgit v1.2.3