# HG changeset patch # User Michiel Broek # Date 1650831742 -7200 # Node ID 231f5c8002e3f8678ae262a70b704d91c632d342 # Parent 24bc2de721d9b08923892f6b214b91bfa96cb7cf Added the largest part of print recipe. diff -r 24bc2de721d9 -r 231f5c8002e3 src/PrinterDialog.cpp --- a/src/PrinterDialog.cpp Sun Apr 24 14:15:20 2022 +0200 +++ b/src/PrinterDialog.cpp Sun Apr 24 22:22:22 2022 +0200 @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include "PrinterDialog.h" +#include "Utils.h" #include "EditRecipe.h" #include "config.h" #include "global.h" @@ -52,9 +53,21 @@ QSqlQuery query; const QColor c_header(255, 150, 100, 255); - const QColor c_line1(210, 245, 255, 255); - const QColor c_line2(255, 255, 210, 255); + const QColor c_line1( 210, 245, 255, 255); + const QColor c_line2( 255, 255, 210, 255); + const QColor f_line( 250, 195, 65, 255); + const QColor h_line( 100, 250, 65, 255); + const QColor y_line( 175, 175, 255, 255); + const QColor mw_line( 240, 140, 130, 255); + const QColor mf_line( 95, 180, 25, 255); + const QColor ms_line( 240, 250, 65, 255); + const QColor mo_line( 210, 245, 255, 255); + const QColor m_line( 175, 175, 255, 255); // also y_line + const QColor w_line( 120, 255, 250, 255); + const QStringList y_unit({tr("pkg"), tr("gr"), tr("ml"), tr("ml"), tr("ml"), tr("ml"), tr("gr")}); + const QStringList ibu_method({ "Tinseth", "Rager", "Daniels", "Garetz", "Mosher", "Noonan" }); + const QStringList color_method({ "Morey", "Mosher", "Daniels", "Halberstadt", "Naudts" }); painter.begin(printer); qreal y = 0; @@ -298,7 +311,261 @@ printHeader(&painter); y = 120; + /* Fermentables supplies header */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.setPen(Qt::black); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 735, 20, Qt::AlignCenter, tr("Recipe overview")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + painter.fillRect( 0, y, 300, 20, c_line1); + painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Brew type")); + painter.drawText(120, y+4, 180, 20, Qt::AlignLeft, recipe_types[recipe->type]); + painter.fillRect(435, y, 300, 20, c_line1); + painter.drawText(435, y+4, 120, 20, Qt::AlignLeft, tr("Efficiency")); + painter.drawText(555, y+4, 180, 20, Qt::AlignLeft, QString("%1 %").arg(recipe->efficiency, 1, 'f', 1)); + y += 20; + painter.fillRect( 0, y, 300, 20, c_line1); + painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Boil time")); + painter.drawText(120, y+4, 180, 20, Qt::AlignLeft, QString("%1 minutes.").arg(recipe->boil_time, 1, 'f', 0)); + painter.fillRect(435, y, 300, 20, c_line1); + painter.drawText(435, y+4, 120, 20, Qt::AlignLeft, tr("Batch size")); + painter.drawText(555, y+4, 180, 20, Qt::AlignLeft, QString("%1 L.").arg(recipe->batch_size, 1, 'f', 1)); + y += 20; + painter.fillRect( 0, y, 300, 20, c_line1); + painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Start SG")); + painter.drawText(120, y+4, 90, 20, Qt::AlignLeft, QString("%1").arg(recipe->est_og, 1, 'f', 3)); + painter.drawText(210, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_og_min, 1, 'f', 3).arg(recipe->st_og_max, 1, 'f', 3)); + painter.fillRect(435, y, 300, 20, c_line1); + painter.drawText(435, y+4, 120, 20, Qt::AlignLeft, tr("End SG")); + painter.drawText(555, y+4, 90, 20, Qt::AlignLeft, QString("%1").arg(recipe->est_fg, 1, 'f', 3)); + painter.drawText(645, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_fg_min, 1, 'f', 3).arg(recipe->st_fg_max, 1, 'f', 3)); + y += 20; + painter.fillRect( 0, y, 300, 20, c_line1); + painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Estimated Alcohol")); + painter.drawText(120, y+4, 90, 20, Qt::AlignLeft, QString("%1%").arg(recipe->est_abv, 1, 'f', 1)); + painter.drawText(210, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_abv_min, 1, 'f', 1).arg(recipe->st_abv_max, 1, 'f', 1)); + painter.fillRect(435, y, 300, 20, c_line1); + painter.drawText(435, y+4, 120, 20, Qt::AlignLeft, tr("Estimated CO2 vol")); + painter.drawText(555, y+4, 90, 20, Qt::AlignLeft, QString("%1").arg(recipe->est_carb, 1, 'f', 1)); + painter.drawText(645, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_carb_min, 1, 'f', 1).arg(recipe->st_carb_max, 1, 'f', 1)); + y += 20; + painter.fillRect( 0, y, 120, 20, c_line1); + painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Color (") + color_method[recipe->color_method] + ")"); + painter.fillRect(120, y, 180, 20, Utils::ebc_to_color(recipe->est_color)); + if (recipe->est_color > 30) + painter.setPen(Qt::white); + painter.drawText(120, y+4, 90, 20, Qt::AlignLeft, QString("%1 EBC").arg(recipe->est_color, 1, 'f', 0)); + painter.drawText(210, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_color_min, 1, 'f', 0).arg(recipe->st_color_max, 1, 'f', 0)); + painter.setPen(Qt::black); + painter.fillRect(435, y, 300, 20, c_line1); + painter.drawText(435, y+4, 120, 20, Qt::AlignLeft, tr("IBU (") + ibu_method[recipe->ibu_method] + ")"); + painter.drawText(555, y+4, 90, 20, Qt::AlignLeft, QString("%1").arg(recipe->est_ibu, 1, 'f', 1)); + painter.drawText(645, y+4, 90, 20, Qt::AlignLeft, QString("(%1 - %2)").arg(recipe->st_ibu_min, 1, 'f', 0).arg(recipe->st_ibu_max, 1, 'f', 0)); + y += 40; + /* Fermentables */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.setPen(Qt::black); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 260, 20, Qt::AlignLeft, tr("Fermentable")); + painter.drawText(265, y+4, 70, 20, Qt::AlignRight, tr("Percent")); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, tr("Yield")); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, tr("Type")); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, tr("Use at")); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, tr("Amount")); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, tr("Cost")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + double cost_fermentables = 0; + QString soort, amount, use; + for (int i = 0; i < recipe->fermentables.size(); i++) { + double cost = recipe->fermentables.at(i).f_amount * recipe->fermentables.at(i).f_cost; + cost_fermentables += cost; + + if (recipe->fermentables.at(i).f_type == 0) + soort = fermentable_graintypes[recipe->fermentables.at(i).f_graintype]; + else + soort = fermentable_types[recipe->fermentables.at(i).f_type]; + + if (recipe->fermentables.at(i).f_amount > 100) + amount = QString("%1 kg").arg(recipe->fermentables.at(i).f_amount, 1, 'f', 1); + else if (recipe->fermentables.at(i).f_amount > 10) + amount = QString("%1 kg").arg(recipe->fermentables.at(i).f_amount, 1, 'f', 2); + else + amount = QString("%1 gr").arg(recipe->fermentables.at(i).f_amount * 1000, 1, 'f', 0); + + painter.fillRect( 0, y, 735, 20, f_line); + + painter.drawText( 0, y+4, 260, 20, Qt::AlignLeft, recipe->fermentables.at(i).f_name + + QString(", %1 EBC (").arg(recipe->fermentables.at(i).f_color, 1, 'f', 0) + + recipe->fermentables.at(i).f_supplier + ")"); + painter.drawText(265, y+4, 70, 20, Qt::AlignRight, QString("%1%").arg(recipe->fermentables.at(i).f_percentage, 1, 'f', 1)); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, QString("%1%").arg(recipe->fermentables.at(i).f_yield, 1, 'f', 1)); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, soort); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, fermentable_added[recipe->fermentables.at(i).f_added]); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, amount); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost, 1, 'f', 3)); + y += 20; + } + painter.fillRect(670, y, 60, 20, c_line1); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost_fermentables, 1, 'f', 3)); + y += 40; + + /* Hops */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 260, 20, Qt::AlignLeft, tr("Hop")); + painter.drawText(265, y+4, 70, 20, Qt::AlignRight, tr("Alpha")); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, tr("IBU")); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, tr("Type")); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, tr("Use at")); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, tr("Amount")); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, tr("Cost")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + double cost_hops = 0; + for (int i = 0; i < recipe->hops.size(); i++) { + + double cost = recipe->hops.at(i).h_amount * recipe->hops.at(i).h_cost; + cost_hops += cost; + double ibu = Utils::toIBU(recipe->hops.at(i).h_useat, recipe->hops.at(i).h_form, recipe->preboil_sg, recipe->batch_size, + recipe->hops.at(i).h_amount, recipe->hops.at(i).h_time, recipe->hops.at(i).h_alpha, + recipe->ibu_method, 0, recipe->hops.at(i).h_time, 0); + + if (recipe->hops.at(i).h_useat == 2 || recipe->hops.at(i).h_useat == 4) // Boil or Whirlpool + use = hop_useat[recipe->hops.at(i).h_useat] + QString(" %1 min").arg(recipe->hops.at(i).h_time); + else if (recipe->hops.at(i).h_useat == 5) // Dryhop + use = hop_useat[recipe->hops.at(i).h_useat] + QString(" %1 days").arg(recipe->hops.at(i).h_time / 1440); + else + use = hop_useat[recipe->hops.at(i).h_useat]; + + if (recipe->hops.at(i).h_amount > 1) + amount = QString("%1 kg").arg(recipe->hops.at(i).h_amount, 1, 'f', 3); + else + amount = QString("%1 gr").arg(recipe->hops.at(i).h_amount * 1000, 1, 'f', 1); + + painter.fillRect( 0, y, 735, 20, h_line); + painter.drawText( 0, y+4, 260, 20, Qt::AlignLeft, recipe->hops.at(i).h_name + " (" + recipe->hops.at(i).h_origin + ")"); + painter.drawText(265, y+4, 70, 20, Qt::AlignRight, QString("%1%").arg(recipe->hops.at(i).h_alpha, 1, 'f', 1)); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, QString("%1").arg(ibu, 1, 'f', 1)); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, hop_forms[recipe->hops.at(i).h_form]); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, use); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, amount); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost, 1, 'f', 3)); + y += 20; + } + painter.fillRect(670, y, 60, 20, c_line1); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost_hops, 1, 'f', 3)); + y += 40; + + /* Yeasts */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 335, 20, Qt::AlignLeft, tr("Yeast")); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, tr("Attn")); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, tr("Type")); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, tr("Use at")); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, tr("Amount")); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, tr("Cost")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + double cost_yeasts = 0; + for (int i = 0; i < recipe->yeasts.size(); i++) { + double cost = recipe->yeasts.at(i).y_amount * recipe->yeasts.at(i).y_cost; + cost_yeasts += cost; + + if (recipe->yeasts.at(i).y_form == 0) + amount = QString("%1 pack").arg(recipe->yeasts.at(i).y_amount, 1, 'f', 0); + else if (recipe->yeasts.at(i).y_form == 1 || recipe->yeasts.at(i).y_form == 6) + amount = QString("%1 gr").arg(recipe->yeasts.at(i).y_amount * 1000.0, 1, 'f', 1); + else + amount = QString("%1 ml").arg(recipe->yeasts.at(i).y_amount * 1000.0, 1, 'f', 1); + + painter.fillRect( 0, y, 735, 20, y_line); + painter.drawText( 0, y+4, 260, 20, Qt::AlignLeft, recipe->yeasts.at(i).y_laboratory + " " + + recipe->yeasts.at(i).y_product_id + " (" + + recipe->yeasts.at(i).y_name + ")"); + painter.drawText(340, y+4, 70, 20, Qt::AlignRight, QString("%1%").arg(recipe->yeasts.at(i).y_attenuation, 1, 'f', 1)); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, yeast_forms[recipe->yeasts.at(i).y_form]); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, yeast_use[recipe->yeasts.at(i).y_use]); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, amount); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost, 1, 'f', 3)); + y += 20; + } + painter.fillRect(670, y, 60, 20, c_line1); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost_yeasts, 1, 'f', 3)); + y += 40; + + /* Miscs */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 410, 20, Qt::AlignLeft, tr("Misc ingredient")); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, tr("Type")); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, tr("Use at")); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, tr("Amount")); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, tr("Cost")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + double cost_miscs = 0; + for (int i = 0; i < recipe->miscs.size(); i++) { + double cost = recipe->miscs.at(i).m_amount * recipe->miscs.at(i).m_cost; + cost_miscs += cost; + + if (recipe->miscs.at(i).m_use_use == 2) + use = misc_uses[recipe->miscs.at(i).m_use_use] + QString(" %1 min").arg(recipe->miscs.at(i).m_time); + else + use = misc_uses[recipe->miscs.at(i).m_use_use]; + + if (recipe->miscs.at(i).m_type == 4) // Water agent + painter.fillRect( 0, y, 735, 20, mw_line); + else if (recipe->miscs.at(i).m_type == 3) // Fining + painter.fillRect( 0, y, 735, 20, mf_line); + else if (recipe->miscs.at(i).m_type < 3 || recipe->miscs.at(i).m_type == 5) // Spice, Herb, Flavour, Yeast nutrient + painter.fillRect( 0, y, 735, 20, ms_line); + else + painter.fillRect( 0, y, 735, 20, mo_line); + painter.drawText( 0, y+4, 410, 20, Qt::AlignLeft, recipe->miscs.at(i).m_name); + painter.drawText(415, y+4, 90, 20, Qt::AlignLeft, misc_types[recipe->miscs.at(i).m_type]); + painter.drawText(510, y+4, 90, 20, Qt::AlignLeft, use); + painter.drawText(605, y+4, 60, 20, Qt::AlignRight, + QString("%1 %2").arg(recipe->miscs.at(i).m_amount * 1000.0, 1, 'f', 1).arg(recipe->miscs.at(i).m_amount_is_weight ? "gr":"ml")); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost, 1, 'f', 3)); + y += 20; + } + painter.fillRect(670, y, 60, 20, c_line1); + painter.drawText(670, y+4, 60, 20, Qt::AlignRight, QString("%1 €").arg(cost_miscs, 1, 'f', 3)); + y += 40; + + /* Mash */ + painter.setFont(QFont("Helvetica", 9, QFont::Bold)); + painter.fillRect( 0, y, 735, 20, c_header); + painter.drawText( 0, y+4, 160, 20, Qt::AlignLeft, tr("Mash step")); + painter.drawText(165, y+4, 90, 20, Qt::AlignLeft, tr("Step type")); + painter.drawText(260, y+4, 60, 20, Qt::AlignRight, tr("Start °C")); + painter.drawText(325, y+4, 60, 20, Qt::AlignRight, tr("End °C")); + painter.drawText(390, y+4, 60, 20, Qt::AlignRight, tr("Time")); + painter.drawText(455, y+4, 60, 20, Qt::AlignRight, tr("Ramp")); + painter.drawText(520, y+4, 60, 20, Qt::AlignRight, tr("L/kg")); + painter.drawText(585, y+4, 70, 20, Qt::AlignRight, tr("Inf/dec L.")); + painter.drawText(660, y+4, 70, 20, Qt::AlignRight, tr("Inf/dec °C")); + y += 20; + painter.setFont(QFont("Helvetica", 9, QFont::Normal)); + for (int i = 0; i < recipe->mashs.size(); i++) { + painter.fillRect( 0, y, 735, 20, m_line); + painter.drawText( 0, y+4, 160, 20, Qt::AlignLeft, recipe->mashs.at(i).step_name); + painter.drawText(165, y+4, 90, 20, Qt::AlignLeft, step_types[recipe->mashs.at(i).step_type]); + painter.drawText(260, y+4, 60, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).step_temp, 1, 'f', 1)); + painter.drawText(325, y+4, 60, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).end_temp, 1, 'f', 1)); + painter.drawText(390, y+4, 60, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).step_time, 1, 'f', 0)); + painter.drawText(455, y+4, 60, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).ramp_time, 1, 'f', 0)); + painter.drawText(520, y+4, 60, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).step_wg_ratio, 1, 'f', 2)); + if (recipe->mashs.at(i).step_type != 1) { + painter.drawText(585, y+4, 70, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).step_infuse_amount, 1, 'f', 1)); + painter.drawText(660, y+4, 70, 20, Qt::AlignRight, QString("%1").arg(recipe->mashs.at(i).step_infuse_temp, 1, 'f', 1)); + } + y += 20; + } } @@ -337,6 +604,10 @@ painter->setFont(QFont("Helvetica",10, QFont::Normal)); painter->drawText(120,35, 80, 20, Qt::AlignLeft, tr("Date and time")); painter->drawText(200,35, 400, 20, Qt::AlignLeft, ": " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm")); + if (p_job == PR_RECIPE) { + painter->drawText(120,55, 80, 20, Qt::AlignLeft, tr("Beer style")); + painter->drawText(200,55, 400, 20, Qt::AlignLeft, ": " + recipe->st_name); + } /* The report itself may print more lines from y = 55. */ } diff -r 24bc2de721d9 -r 231f5c8002e3 src/global.cpp --- a/src/global.cpp Sun Apr 24 14:15:20 2022 +0200 +++ b/src/global.cpp Sun Apr 24 22:22:22 2022 +0200 @@ -22,6 +22,12 @@ Recipe *recipe; +const QStringList recipe_types({ + QObject::tr("Extract"), + QObject::tr("Partial Mash"), + QObject::tr("All Grain") +}); + const QStringList style_types({ QObject::tr("Lager"), QObject::tr("Ale"), diff -r 24bc2de721d9 -r 231f5c8002e3 src/global.h --- a/src/global.h Sun Apr 24 14:15:20 2022 +0200 +++ b/src/global.h Sun Apr 24 22:22:22 2022 +0200 @@ -551,6 +551,7 @@ extern int my_default_water; extern QString my_yeastlab; +extern const QStringList recipe_types; extern const QStringList style_types; extern const QStringList fermentable_types; extern const QStringList fermentable_graintypes;