src/PrinterDialog.cpp

changeset 240
52efe638e79a
parent 238
047e99c90848
child 255
f237db73d4c8
equal deleted inserted replaced
239:bfd4e07c20cb 240:52efe638e79a
1520 painter.fillRect( 0, y, 735, 20, c_line1); 1520 painter.fillRect( 0, y, 735, 20, c_line1);
1521 painter.drawText( 0, y+4, 735, 20, Qt::AlignLeft, lines[i]); 1521 painter.drawText( 0, y+4, 735, 20, Qt::AlignLeft, lines[i]);
1522 y += 20; 1522 y += 20;
1523 } 1523 }
1524 } 1524 }
1525
1526 } else if (p_job == PR_CHECKLIST) {
1527
1528 double factor = 1.0 / product->divide_factor;
1529 double mashwater = 0;
1530 int numsalts = 0;
1531 qDebug() << "print checklist";
1532 printHeader(&painter);
1533 y = 120;
1534
1535 /* First item, a yeast starter if needed, days before brewday. */
1536 if (product->starter_enable && product->prop_volume[0]) {
1537 checkHeader(&painter, &y, tr("Make a yeast starter"));
1538 int days = 0;
1539 int last = 0;
1540 QString s = "";
1541 for (int i = 0; i < 4; i++) {
1542 if (product->prop_volume[i]) {
1543 last = i;
1544 if (product->prop_type[i] == STARTERS_STIRRED)
1545 days += 2;
1546 else if (product->prop_type[i] == STARTERS_SHAKEN)
1547 days += 4;
1548 else
1549 days += 6; // Simple starter
1550 }
1551 }
1552 checkLine(&painter, &y, QString(tr("Start about %1 days before brewday with the starter.")).arg(days));
1553 for (int i = 0; i < 4; i++) {
1554 if (product->prop_volume[i]) {
1555 checkLine(&painter, &y, QString(tr("Starter step %1 of %2 liter with SG %3")).arg(i+1).arg(product->prop_volume[i], 1, 'f', 3).
1556 arg(product->starter_sg, 1, 'f', 3));
1557 QString w = tr(" until there is enough yeast");
1558 if (product->prop_type[i] == STARTERS_STIRRED)
1559 checkLine(&painter, &y, QString(tr("about 24 hours on a stirplate"))+w);
1560 else if (product->prop_type[i] == STARTERS_SHAKEN)
1561 checkLine(&painter, &y, QString(tr("shake often for a few days"))+w);
1562 else
1563 checkLine(&painter, &y, QString(tr("let it rest for almost a week"))+w);
1564 if (i < last) {
1565 checkLine(&painter, &y, QString(tr("place starter in the fridge for 24 hours")));
1566 checkLine(&painter, &y, QString(tr("remove starter from the fridge and decant")));
1567 } else {
1568 checkLine(&painter, &y, QString(tr("place starter in the fridge until brewday")));
1569 checkLine(&painter, &y, QString(tr("remove starter from the fridge and decant")));
1570 }
1571 }
1572 }
1573 y += 20;
1574 }
1575
1576 checkHeader(&painter, &y, tr("Mash water and treatment"));
1577 checkLine(&painter, &y, QString("%1 liter water %2").arg(product->w1_amount * factor, 1, 'f', 1).arg(product->w1_name));
1578 mashwater += product->w1_amount * factor;
1579 if (product->w2_name != "" && product->w2_amount > 0) {
1580 checkLine(&painter, &y, QString("%1 liter water %2").arg(product->w2_amount * factor, 1, 'f', 1).arg(product->w2_name));
1581 mashwater += product->w2_amount * factor;
1582 }
1583 for (int i = 0; i < product->miscs.size(); i++) {
1584 if (product->miscs.at(i).m_type == MISC_TYPES_WATER_AGENT) {
1585 QString unit = (product->miscs.at(i).m_amount_is_weight) ? "gr":"ml";
1586 checkLine(&painter, &y, QString("%1 %2 %3").arg(product->miscs.at(i).m_amount * 1000 * factor, 1, 'f', 2).arg(unit).arg(product->miscs.at(i).m_name));
1587 numsalts++;
1588 }
1589 }
1590 y += 20;
1591
1592 checkHeader(&painter, &y, tr("Weight and mill the malts"));
1593 for (int i = 0; i < product->fermentables.size(); i++) {
1594 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
1595 checkLine(&painter, &y, QString("%1 kg `%2` (%3)").arg(product->fermentables.at(i).f_amount * factor, 1, 'f', 3).
1596 arg(product->fermentables.at(i).f_name).arg(product->fermentables.at(i).f_supplier));
1597 }
1598 }
1599 checkLine(&painter, &y, QString(tr("Mill the malts")));
1600 y += 20;
1601
1602 checkHeader(&painter, &y, tr("Mash"));
1603 int loop = 0;
1604 double l, mvol = 0, msugars = 0;
1605 for (int i = 0; i < product->mashs.size(); i++) {
1606 if (product->mashs.at(i).step_type == 0)
1607 mvol += product->mashs.at(i).step_infuse_amount * factor; // We need this later
1608 if (loop == 0) {
1609 if (product->mashs.at(i).step_type == 0)
1610 l = product->mashs.at(i).step_infuse_amount * factor;
1611 else
1612 l = mashwater;
1613 checkLine(&painter, &y, QString(tr("Heat %1 liter water to %2°C (%3 cm below kettle top)"))
1614 .arg(mashwater, 1, 'f', 1).arg(product->mashs.at(i).step_infuse_temp, 1, 'f', 1)
1615 .arg(Utils::kettle_cm(l, product->eq_tun_volume, product->eq_tun_height), 1, 'f', 1));
1616 if (numsalts > 0)
1617 checkLine(&painter, &y, QString(tr("Add brouwzouten")));
1618 checkLine(&painter, &y, QString(tr("Add malts and dough-in")));
1619 for (int j = 0; j < product->hops.size(); j++) {
1620 if (product->hops.at(j).h_useat == HOP_USEAT_MASH) {
1621 checkLine(&painter, &y, QString(tr("Add %1 gram `%2` hop")).arg(product->hops.at(j).h_amount * 1000 * factor, 1, 'f', 1)
1622 .arg(product->hops.at(j).h_name));
1623 }
1624 }
1625 for (int j = 0; j < product->miscs.size(); j++) {
1626 if ((product->miscs.at(j).m_use_use == MISC_USES_MASH) && (product->miscs.at(j).m_type != MISC_TYPES_WATER_AGENT)) {
1627 QString unit = (product->miscs.at(j).m_amount_is_weight) ? "gr":"ml";
1628 checkLine(&painter, &y, QString(tr("Add %1 %2 `%3`")).arg(product->miscs.at(j).m_amount * 1000 * factor, 1, 'f', 2)
1629 .arg(unit).arg(product->miscs.at(j).m_name));
1630 }
1631 }
1632 } else { // loop > 0
1633 if (product->mashs.at(i).step_type == 0) { // Infusion
1634 checkLine(&painter, &y, QString(tr("Add %1 liter water of %2°C")).arg(product->mashs.at(i).step_infuse_amount * factor, 1, 'f', 1)
1635 .arg(product->mashs.at(i).step_infuse_temp, 1, 'f', 1));
1636 } else if (product->mashs.at(i).step_type == 1) { // Direct heat
1637 checkLine(&painter, &y, QString(tr("Heat upto %1°C")).arg(product->mashs.at(i).step_temp, 1, 'f', 1));
1638 } else { // Decoction
1639 checkLine(&painter, &y, QString(tr("Take, heat, boil and return %1 part of the mash"))
1640 .arg(product->mashs.at(i).step_infuse_amount * factor, 1, 'f', 1));
1641 }
1642 }
1643 if (product->mashs.at(i).step_temp != product->mashs.at(i).end_temp) {
1644 checkInput(&painter, &y, QString(tr("%1 minutes from %2°C to %3°C")).arg(product->mashs.at(i).step_time)
1645 .arg(product->mashs.at(i).step_temp, 1, 'f', 1).arg(product->mashs.at(i).end_temp, 1, 'f', 1), QString(tr("Brix")));
1646 } else {
1647 checkInput(&painter, &y, QString(tr("%1 minutes at %2°C")).arg(product->mashs.at(i).step_time)
1648 .arg(product->mashs.at(i).step_temp, 1, 'f', 1), QString(tr("Brix")));
1649 }
1650 if (loop == 0)
1651 checkInput(&painter, &y, QString(tr("Measure and adjust pH (target %1 pH)")).arg(product->mash_ph, 1, 'f', 2), QString(tr("pH")));
1652 loop++;
1653 }
1654 double est_masg_sg = 0, sugardensity = 1.611, grainabsorbtion = 0;
1655 for (int i = 0; i < product->fermentables.size(); i++) {
1656 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
1657 double d = product->fermentables.at(i).f_amount * factor * (product->fermentables.at(i).f_yield / 100) *
1658 (1 - product->fermentables.at(i).f_moisture / 100);
1659 mvol += product->fermentables.at(i).f_amount * factor * (product->fermentables.at(i).f_moisture / 100);
1660 grainabsorbtion += my_grain_absorbtion * product->fermentables.at(i).f_amount * factor;
1661 msugars += d;
1662 }
1663 }
1664 double v = msugars / sugardensity + mvol;
1665 double plato = 1000.0 * msugars / (v * 10.0); // deg. Plato
1666 double mash_sg = Utils::plato_to_sg(plato);
1667 checkInput(&painter, &y, QString(tr("Target SG end mash: ")) + strDensity(mash_sg), QString(tr("SG")));
1668 if ((y + 140) > painter.device()->height()) {
1669 printer->newPage();
1670 printHeader(&painter);
1671 y = 120;
1672 } else {
1673 y += 20;
1674 }
1675
1676 checkHeader(&painter, &y, tr("Lauter and Sparge"));
1677 checkLine(&painter, &y, QString(tr("Heat %1 liter sparge water to %2°C")).arg(product->sparge_volume * factor, 1, 'f', 1)
1678 .arg(product->sparge_temp, 1, 'f', 1));
1679 checkInput(&painter, &y, QString(tr("Bring to %1 pH with %2 ml. `%3`")).arg(product->sparge_ph, 1, 'f', 2)
1680 .arg(product->sparge_acid_amount * 1000 * factor, 1, 'f', 2).arg(my_acids.at(product->sparge_acid_type).name_en), QString(tr("pH")));
1681 checkLine(&painter, &y, QString(tr("Sparge with close to %1 liter water"))
1682 .arg(((product->boil_size * factor) - mashwater + grainabsorbtion + product->eq_lauter_deadspace) * 1.03, 1, 'f', 1));
1683 checkInput(&painter, &y, QString(tr("Target volume in boil kettle: %1 liter (%2 cm below kettle top)"))
1684 .arg(product->boil_size * factor * 1.04, 1, 'f', 1)
1685 .arg(Utils::kettle_cm(product->boil_size * factor * 1.04, product->eq_kettle_volume, product->eq_kettle_height), 1, 'f', 1),
1686 QString(tr("cm")));
1687 checkInput(&painter, &y, QString(tr("Target SG in boil kettle: ")) + strDensity(product->preboil_sg), QString(tr("SG")));
1688 checkInput(&painter, &y, "", QString(tr("pH")));
1689 for (int i = 0; i < product->hops.size(); i++) {
1690 if (product->hops.at(i).h_useat == HOP_USEAT_FWH) {
1691 checkLine(&painter, &y, QString(tr("Add %1 gr `%2` hop after sparge")).arg(product->hops.at(i).h_amount * 1000 * factor, 1, 'f', 1)
1692 .arg(product->hops.at(i).h_name));
1693 }
1694 }
1695
1696 if (checkSplit(&painter, &y, 1))
1697 factor = 1;
1698 /* Boil, how much space do we need */
1699 int lines = 0;
1700 if (product->boil_time == 0) {
1701 lines = 3;
1702 } else {
1703 lines = 5;
1704 if (product->brew_cooling_method == 1)
1705 lines++;
1706 for (int i = 0; i < product->fermentables.size(); i++) {
1707 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOIL)
1708 lines++;
1709 }
1710 for (int i = 0; i < product->hops.size(); i++) {
1711 if (product->hops.at(i).h_useat == HOP_USEAT_BOIL || product->hops.at(i).h_useat == HOP_USEAT_AROMA)
1712 lines++;
1713 }
1714 for (int i = 0; i < product->miscs.size(); i++) {
1715 if (product->miscs.at(i).m_use_use == MISC_USES_BOIL)
1716 lines++;
1717 }
1718 }
1719 qDebug() << "check" << lines << y + (lines * 20) << painter.device()->height();
1720 if ((y + (lines * 20)) > painter.device()->height()) {
1721 printer->newPage();
1722 printHeader(&painter);
1723 y = 120;
1724 } else {
1725 y += 20;
1726 }
1727 checkHeader(&painter, &y, tr("Boil"));
1728 if (product->boil_time > 0) {
1729 checkLine(&painter, &y, QString(tr("Total boiltime: %1 minutes")).arg(product->boil_time, 1, 'f', 0));
1730 for (int i = product->boil_time; i >= 0; i--) {
1731 if (i == 10) {
1732 for (int j = 0; j < product->fermentables.size(); j++) {
1733 if (product->fermentables.at(j).f_added == FERMENTABLE_ADDED_BOIL)
1734 checkLine(&painter, &y, QString(tr("%1 kg `%2` at 10 minutes before end of boil"))
1735 .arg(product->fermentables.at(j).f_amount * factor, 1, 'f', 3)
1736 .arg(product->fermentables.at(j).f_name));
1737 }
1738 if (product->brew_cooling_method == 1)
1739 checkLine(&painter, &y, QString(tr("Place emersion chiller at 10 minutes before end of boil")));
1740 }
1741 for (int j = 0; j < product->hops.size(); j++) {
1742 if ((product->hops.at(j).h_useat == HOP_USEAT_BOIL || product->hops.at(j).h_useat == HOP_USEAT_AROMA) && product->hops.at(j).h_time == i) {
1743 if (i == 0)
1744 checkLine(&painter, &y, QString(tr("%1 gr `%2` at flameout")).arg(product->hops.at(j).h_amount * 1000 * factor, 1, 'f', 2)
1745 .arg(product->hops.at(j).h_name));
1746 else
1747 checkLine(&painter, &y, QString(tr("%1 gr `%2` at %3 minutes before end of boil"))
1748 .arg(product->hops.at(j).h_amount * 1000 * factor, 1, 'f', 2).arg(product->hops.at(j).h_name).arg(i));
1749 }
1750 }
1751 for (int j = 0; j < product->miscs.size(); j++) {
1752 if (product->miscs.at(j).m_use_use == MISC_USES_BOIL && product->miscs.at(j).m_time == i) {
1753 QString unit = (product->miscs.at(j).m_amount_is_weight) ? "gr":"ml";
1754 if (i == 0)
1755 checkLine(&painter, &y, QString(tr("%1 %2 `%3` at flameout"))
1756 .arg(product->miscs.at(j).m_amount * 1000 * factor, 1, 'f', 2).arg(unit).arg(product->miscs.at(j).m_name));
1757 else
1758 checkLine(&painter, &y, QString(tr("%1 %2 `%3` at %4 minutes before end of boil"))
1759 .arg(product->miscs.at(j).m_amount * 1000 * factor, 1, 'f', 2).arg(unit).arg(product->miscs.at(j).m_name).arg(i));
1760 }
1761 }
1762 }
1763 checkInput(&painter, &y, QString(tr("Target volume at end of boil: %1 liter (%2 cm below kettle top)"))
1764 .arg(product->batch_size * 1.04 * factor, 1, 'f', 1)
1765 .arg(Utils::kettle_cm(product->batch_size * 1.04 * factor, product->eq_kettle_volume, product->eq_kettle_height)),
1766 QString(tr("cm")));
1767 checkInput(&painter, &y, QString(tr("Target SG at end of boil: ")) + strDensity(product->est_og3), QString(tr("SG")));
1768 checkInput(&painter, &y, "", QString(tr("pH")));
1769 if (checkSplit(&painter, &y, 2))
1770 factor = 1;
1771 } else {
1772 checkLine(&painter, &y, QString(tr("This is a `no-boil` recipe")));
1773 }
1774
1775 /* Whirlpools and chilling */
1776 lines = 5;
1777 if (product->brew_whirlpool9)
1778 lines++;
1779 if (product->brew_whirlpool7)
1780 lines++;
1781 if (product->brew_whirlpool6)
1782 lines++;
1783 if (product->brew_whirlpool2)
1784 lines++;
1785 for (int i = 0; i < product->hops.size(); i++) {
1786 if (product->hops.at(i).h_useat == HOP_USEAT_WHIRLPOOL)
1787 lines++;
1788 }
1789 if ((y + (lines * 20)) > painter.device()->height()) {
1790 printer->newPage();
1791 printHeader(&painter);
1792 y = 120;
1793 } else {
1794 y += 20;
1795 }
1796 if ((product->brew_whirlpool9 + product->brew_whirlpool7 + product->brew_whirlpool6 + product->brew_whirlpool2) > 0) {
1797 checkHeader(&painter, &y, tr("Whirlpool(s) and cooling"));
1798 if (product->brew_whirlpool9 > 0)
1799 checkLine(&painter, &y, QString(tr("Wirlpool for %1 minutes. Keep temp above 85°C")).arg(product->brew_whirlpool9, 1, 'f', 0));
1800 if (product->brew_whirlpool7 > 0)
1801 checkLine(&painter, &y, QString(tr("Wirlpool for %1 minutes. Keep temp between 72 and 79°C")).arg(product->brew_whirlpool7, 1, 'f', 0));
1802 if (product->brew_whirlpool6 > 0)
1803 checkLine(&painter, &y, QString(tr("Wirlpool for %1 minutes. Keep temp between 60 and 66°C")).arg(product->brew_whirlpool6, 1, 'f', 0));
1804 for (int i = 0; i < product->hops.size(); i++) {
1805 if (product->hops.at(i).h_useat == HOP_USEAT_WHIRLPOOL)
1806 checkLine(&painter, &y, QString(tr("%1 gr `%2` for %3 minutes in the whirlpool"))
1807 .arg(product->hops.at(i).h_amount * 1000 * factor, 1, 'f', 1).arg(product->hops.at(i).h_name)
1808 .arg(product->hops.at(i).h_time));
1809 }
1810 checkLine(&painter, &y, QString(tr("Cool to %1°C")).arg(product->brew_cooling_to, 1, 'f', 1));
1811 if (product->brew_whirlpool2 > 0)
1812 checkLine(&painter, &y, QString(tr("Wirlpool for %1 minutes.")).arg(product->brew_whirlpool2, 1, 'f', 0));
1813 } else {
1814 checkHeader(&painter, &y, tr("Cooling"));
1815 checkLine(&painter, &y, QString(tr("Cool to %1°C")).arg(product->brew_cooling_to, 1, 'f', 1));
1816 }
1817 checkLine(&painter, &y, QString(tr("Desinfect fermenter and pump and hoses if needed")));
1818 checkInput(&painter, &y, QString(tr("Transfer wort to fermenter")), QString(tr("Liter")));
1819 if (checkSplit(&painter, &y, 3))
1820 factor = 1;
1821
1822 double climate = product->brew_cooling_to;
1823 lines = 3;
1824 for (int i = 0; i < product->yeasts.size(); i++) {
1825 if (product->yeasts.at(i).y_use == YEAST_USE_PRIMARY) {
1826 lines++;
1827 if (product->yeasts.at(i).y_type == YEAST_TYPES_KVEIK && (product->yeasts.at(i).y_pitch_temperature > 0))
1828 lines++;
1829 }
1830 }
1831 if (product->brew_aeration_type > 0)
1832 lines++;
1833 if (product->brew_fermenter_extrawater > 0)
1834 lines++;
1835 if ((y + (lines * 20)) > painter.device()->height()) {
1836 printer->newPage();
1837 printHeader(&painter);
1838 y = 120;
1839 } else {
1840 y += 20;
1841 }
1842 double dry = 0;
1843 checkHeader(&painter, &y, tr("Yeast pitching and fermentation"));
1844 for (int i = 0; i < product->yeasts.size(); i++) {
1845 if (product->yeasts.at(i).y_use == YEAST_USE_PRIMARY) {
1846 switch (product->yeasts.at(i).y_form) {
1847 case YEAST_FORMS_LIQUID: checkLine(&painter, &y, QString(tr("%1 pack %2, `%3` yeast")).arg(product->yeasts.at(i).y_amount)
1848 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1849 break;
1850 case YEAST_FORMS_DRY: dry += product->yeasts.at(i).y_amount * 1000 * factor;
1851 case YEAST_FORMS_DRIED: checkLine(&painter, &y, QString(tr("%1 gram %2, `%3` yeast"))
1852 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
1853 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1854 break;
1855 default: checkLine(&painter, &y, QString(tr("%1 ml %2, `%3` yeast"))
1856 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 0)
1857 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1858 break;
1859 }
1860 if (product->yeasts.at(i).y_type == YEAST_TYPES_KVEIK && (product->yeasts.at(i).y_pitch_temperature > 0)) {
1861 checkLine(&painter, &y, QString(tr("Pitch yeast at %1°C")).arg(product->yeasts.at(i).y_pitch_temperature, 1, 'f', 1));
1862 climate = product->yeasts.at(i).y_pitch_temperature;
1863 }
1864 }
1865 }
1866 if (dry > 0) {
1867 checkLine(&painter, &y, QString(tr("Pitch yeast dry into the wort")));
1868 } else {
1869 if (product->starter_enable && product->prop_volume[0])
1870 checkLine(&painter, &y, QString(tr("Add decanted yeast starter")));
1871 else
1872 checkLine(&painter, &y, QString(tr("Add the yeast")));
1873 }
1874 if (product->brew_fermenter_extrawater)
1875 checkLine(&painter, &y, QString(tr("Add %1 liter water in the fermenter")).arg(product->brew_fermenter_extrawater * factor, 1, 'f', 1));
1876 if (product->brew_aeration_type > 0)
1877 checkLine(&painter, &y, QString(tr("Aerate %1 minutes with %2")).arg(product->brew_aeration_time)
1878 .arg((product->brew_aeration_type == 1) ? "air":"oxygen"));
1879 checkLine(&painter, &y, QString(tr("Set fermentation start temperature to %1°C")).arg(climate, 1, 'f', 1));
1880 checkLine(&painter, &y, QString(tr("Start fermentation")));
1881
1882 /* During primary fermentation */
1883 lines = 0;
1884 for (int i = 0; i < product->fermentables.size(); i++)
1885 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_FERMENTATION)
1886 lines++;
1887 for (int i = 0; i < product->miscs.size(); i++)
1888 if (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY)
1889 lines++;
1890 if (lines) {
1891 if ((y + 20 + (lines * 20)) > painter.device()->height()) {
1892 printer->newPage();
1893 printHeader(&painter);
1894 y = 120;
1895 } else {
1896 y += 20;
1897 }
1898 checkHeader(&painter, &y, tr("Primary fermentation"));
1899 for (int i = 0; i < product->fermentables.size(); i++) {
1900 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_FERMENTATION)
1901 checkLine(&painter, &y, QString(tr("Add %1 kg `%2` on day 3 or 4")).arg(product->fermentables.at(i).f_amount * factor, 1, 'f', 3)
1902 .arg(product->fermentables.at(i).f_name));
1903 }
1904 for (int i = 0; i < product->miscs.size(); i++) {
1905 if (product->miscs.at(i).m_use_use == MISC_USES_PRIMARY) {
1906 QString unit = (product->miscs.at(i).m_amount_is_weight) ? "gr":"ml";
1907 checkLine(&painter, &y, QString(tr("Add %1 %2 `%3` on day 3 or 4")).arg(product->miscs.at(i).m_amount * factor, 1, 'f', 3)
1908 .arg(unit).arg(product->miscs.at(i).m_name));
1909 }
1910 }
1911 }
1912 if (checkSplit(&painter, &y, 4))
1913 factor = 1;
1914
1915 /* During secondary fermentation, yeast */
1916 lines = 0;
1917 for (int i = 0; i < product->yeasts.size(); i++) {
1918 if (product->yeasts.at(i).y_use == YEAST_USE_SECONDARY)
1919 lines++;
1920 if (product->yeasts.at(i).y_harvest_time > 0)
1921 lines++;
1922 }
1923 if (lines) {
1924 if ((y + 20 + (lines * 20)) > painter.device()->height()) {
1925 printer->newPage();
1926 printHeader(&painter);
1927 y = 120;
1928 } else {
1929 y += 20;
1930 }
1931 checkHeader(&painter, &y, tr("Secondary fermentation"));
1932 for (int i = 0; i < product->yeasts.size(); i++) {
1933 if (product->yeasts.at(i).y_use == YEAST_USE_SECONDARY) {
1934 if (product->yeasts.at(i).y_form == YEAST_FORMS_LIQUID) {
1935 checkLine(&painter, &y, QString(tr("Add %1 pack %2, `%3` yeast (with starter if needed)"))
1936 .arg(product->yeasts.at(i).y_amount).arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1937 } else if (product->yeasts.at(i).y_form == YEAST_FORMS_DRY) {
1938 checkLine(&painter, &y, QString(tr("Add %1 gram %2, `%3`")).arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
1939 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1940 } else {
1941 checkLine(&painter, &y, QString(tr("Add %1 gram %2, `%3` yeast (with starter if needed)"))
1942 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
1943 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1944 }
1945 }
1946 if (product->yeasts.at(i).y_harvest_time > 0) {
1947 checkLine(&painter, &y, QString(tr("After %1 hours harvest yeast from the %2")).arg(product->yeasts.at(i).y_harvest_time)
1948 .arg((product->yeasts.at(i).y_harvest_top > 0) ? "top":"bottom"));
1949 }
1950 }
1951 }
1952 if (checkSplit(&painter, &y, 5))
1953 factor = 1;
1954
1955 /* During tertiary fermentation */
1956 lines = 0;
1957 for (int i = 0; i < product->fermentables.size(); i++)
1958 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_LAGERING)
1959 lines++;
1960 for (int i = 0; i < product->hops.size(); i++)
1961 if (product->hops.at(i).h_useat == HOP_USEAT_DRY_HOP)
1962 lines++;
1963 for (int i = 0; i < product->miscs.size(); i++)
1964 if (product->miscs.at(i).m_use_use == MISC_USES_SECONDARY)
1965 lines++;
1966 for (int i = 0; i < product->yeasts.size(); i++) {
1967 if (product->yeasts.at(i).y_use == YEAST_USE_TERTIARY)
1968 lines++;
1969 }
1970 if (lines) {
1971 if ((y + 20 + (lines * 20)) > painter.device()->height()) {
1972 printer->newPage();
1973 printHeader(&painter);
1974 y = 120;
1975 } else {
1976 y += 20;
1977 }
1978 checkHeader(&painter, &y, tr("Tertiary fermentation"));
1979 for (int i = 0; i < product->fermentables.size(); i++) {
1980 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_LAGERING)
1981 checkLine(&painter, &y, QString(tr("Add %1 kg `%2`")).arg(product->fermentables.at(i).f_amount * factor, 1, 'f', 3)
1982 .arg(product->fermentables.at(i).f_name));
1983 }
1984 for (int i = 0; i < product->hops.size(); i++) {
1985 if (product->hops.at(i).h_useat == HOP_USEAT_DRY_HOP) {
1986 checkLine(&painter, &y, QString(tr("Add %1 gram `%2` for %3 days")).arg(product->hops.at(i).h_amount * 1000 * factor, 1, 'f', 1)
1987 .arg(product->hops.at(i).h_name).arg(product->hops.at(i).h_time / 1440));
1988 }
1989 }
1990 for (int i = 0; i < product->yeasts.size(); i++) {
1991 if (product->yeasts.at(i).y_use == YEAST_USE_TERTIARY) {
1992 if (product->yeasts.at(i).y_form == YEAST_FORMS_LIQUID) {
1993 checkLine(&painter, &y, QString(tr("Add %1 pack %2, `%3` yeast (with starter if needed)"))
1994 .arg(product->yeasts.at(i).y_amount).arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1995 } else if (product->yeasts.at(i).y_form == YEAST_FORMS_DRY) {
1996 checkLine(&painter, &y, QString(tr("Add %1 gram %2, `%3`")).arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
1997 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
1998 } else {
1999 checkLine(&painter, &y, QString(tr("Add %1 ml %2, `%3` yeast (with starter if needed)"))
2000 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
2001 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
2002 }
2003 }
2004 }
2005 for (int i = 0; i < product->miscs.size(); i++) {
2006 if (product->miscs.at(i).m_use_use == MISC_USES_SECONDARY) {
2007 QString unit = (product->miscs.at(i).m_amount_is_weight) ? "gr":"ml";
2008 checkLine(&painter, &y, QString(tr("Add %1 %2 `%3` for %4 days")).arg(product->miscs.at(i).m_amount * factor, 1, 'f', 3)
2009 .arg(unit).arg(product->miscs.at(i).m_name).arg(product->miscs.at(i).m_time / 1440));
2010 }
2011 }
2012 }
2013 if (checkSplit(&painter, &y, 6))
2014 factor = 1;
2015
2016 /* During packaging */
2017 lines = 0;
2018 for (int i = 0; i < product->fermentables.size(); i++)
2019 if (product->fermentables.at(i).f_added >= FERMENTABLE_ADDED_BOTTLE)
2020 lines++;
2021 for (int i = 0; i < product->miscs.size(); i++)
2022 if (product->miscs.at(i).m_use_use == MISC_USES_BOTTLING)
2023 lines++;
2024 for (int i = 0; i < product->yeasts.size(); i++)
2025 if (product->yeasts.at(i).y_use == YEAST_USE_BOTTLE)
2026 lines++;
2027 if (lines) {
2028 if ((y + 20 + (lines * 20)) > painter.device()->height()) {
2029 printer->newPage();
2030 printHeader(&painter);
2031 y = 120;
2032 } else {
2033 y += 20;
2034 }
2035 checkHeader(&painter, &y, tr("Packaging"));
2036 for (int i = 0; i < product->fermentables.size(); i++) {
2037 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOTTLE)
2038 checkLine(&painter, &y, QString(tr("Bottling add %1 kg `%2` with %3 liter water"))
2039 .arg(product->fermentables.at(i).f_amount * factor, 1, 'f', 3)
2040 .arg(product->fermentables.at(i).f_name).arg(product->bottle_priming_water * factor, 1, 'f', 3));
2041 if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_KEGS)
2042 checkLine(&painter, &y, QString(tr("Kegging add %1 kg `%2` with %3 liter water"))
2043 .arg(product->fermentables.at(i).f_amount * factor, 1, 'f', 3)
2044 .arg(product->fermentables.at(i).f_name).arg(product->keg_priming_water * factor, 1, 'f', 3));
2045 }
2046 for (int i = 0; i < product->yeasts.size(); i++) {
2047 if (product->yeasts.at(i).y_use == YEAST_USE_BOTTLE) {
2048 if (product->yeasts.at(i).y_form == YEAST_FORMS_LIQUID) {
2049 checkLine(&painter, &y, QString(tr("Add %1, `%2` as bottle yeast"))
2050 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
2051 } else if (product->yeasts.at(i).y_form == YEAST_FORMS_DRY) {
2052 checkLine(&painter, &y, QString(tr("Add %1 gram %2, `%3` as bottle yeast"))
2053 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
2054 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
2055 } else {
2056 checkLine(&painter, &y, QString(tr("Add %1 ml %2, `%3` as bottle yeast"))
2057 .arg(product->yeasts.at(i).y_amount * 1000 * factor, 1, 'f', 1)
2058 .arg(product->yeasts.at(i).y_product_id).arg(product->yeasts.at(i).y_name));
2059 }
2060 }
2061 }
2062 for (int i = 0; i < product->miscs.size(); i++) {
2063 if (product->miscs.at(i).m_use_use == MISC_USES_BOTTLING) {
2064 QString unit = (product->miscs.at(i).m_amount_is_weight) ? "gr":"ml";
2065 checkLine(&painter, &y, QString(tr("Add %1 %2 `%3` during bottling")).arg(product->miscs.at(i).m_amount * factor, 1, 'f', 3)
2066 .arg(unit).arg(product->miscs.at(i).m_name));
2067 }
2068 }
2069 }
1525 } 2070 }
1526 2071
1527 painter.end(); 2072 painter.end();
2073 }
2074
2075
2076 void PrinterDialog::checkHeader(QPainter *painter, qreal *y, QString text)
2077 {
2078 painter->setFont(QFont("Arial", 10, QFont::Bold));
2079 painter->setPen(Qt::black);
2080 painter->drawText(30, *y, 700, 20, Qt::AlignLeft, text);
2081 painter->setFont(QFont("Arial", 10, QFont::Normal));
2082 *y += 20;
2083 }
2084
2085
2086 /*
2087 * Draw a checkbox and text.
2088 */
2089 void PrinterDialog::checkLine(QPainter *painter, qreal *y, QString text)
2090 {
2091 painter->drawRect( 4, *y, 16, 16);
2092 painter->drawText(30, *y,650, 20, Qt::AlignLeft, text);
2093 *y += 20;
2094 }
2095
2096
2097 void PrinterDialog::checkInput(QPainter *painter, qreal *y, QString text, QString prompt)
2098 {
2099 if (text != "") {
2100 painter->drawRect( 4, *y, 16, 16);
2101 painter->drawText(30, *y,500, 20, Qt::AlignLeft, text);
2102 }
2103 painter->drawText(515, *y, 150, 20, Qt::AlignRight, QString(tr("Measured:")) + QString(" _________"));
2104 painter->drawText(675, *y, 60, 20, Qt::AlignLeft, prompt);
2105 *y += 20;
2106 }
2107
2108
2109 bool PrinterDialog::checkSplit(QPainter *painter, qreal *y, int moment)
2110 {
2111 if (product->divide_type && product->divide_type == moment) {
2112 *y += 20;
2113 painter->setFont(QFont("Helvetica", 14, QFont::Bold));
2114 painter->drawText(0, *y, 735, 20, Qt::AlignCenter, QString(tr("%1 split the batch here!")).arg(prod_split[product->divide_type]));
2115 painter->setFont(QFont("Arial", 10, QFont::Normal));
2116 *y += 26;
2117 return true;
2118 }
2119 return false;
1528 } 2120 }
1529 2121
1530 2122
1531 QString PrinterDialog::strDiff(double v1, double v2, int decimals, QString suffix) 2123 QString PrinterDialog::strDiff(double v1, double v2, int decimals, QString suffix)
1532 { 2124 {
1561 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Inventory") + " " + my_brewery_name); 2153 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Inventory") + " " + my_brewery_name);
1562 } else if (p_job == PR_YEASTBANK) { 2154 } else if (p_job == PR_YEASTBANK) {
1563 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + my_brewery_name); 2155 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + my_brewery_name);
1564 } else if (p_job == PR_RECIPE) { 2156 } else if (p_job == PR_RECIPE) {
1565 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, recipe->name); 2157 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, recipe->name);
1566 } else if (p_job == PR_PRODUCT) { 2158 } else if (p_job == PR_PRODUCT || p_job == PR_CHECKLIST) {
1567 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, product->code + " " + product->name); 2159 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, product->code + " " + product->name);
1568 } else { 2160 } else {
1569 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, "?? " + my_brewery_name); 2161 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, "?? " + my_brewery_name);
1570 } 2162 }
1571 /* The first normal header line */ 2163 /* The first normal header line */
1574 painter->drawText(200,35, 400, 20, Qt::AlignLeft, ": " + QDateTime::currentDateTime().toString("dd-MMM-yyyy hh:mm")); 2166 painter->drawText(200,35, 400, 20, Qt::AlignLeft, ": " + QDateTime::currentDateTime().toString("dd-MMM-yyyy hh:mm"));
1575 if (p_job == PR_RECIPE) { 2167 if (p_job == PR_RECIPE) {
1576 painter->drawText(120,55, 80, 20, Qt::AlignLeft, tr("Beer style")); 2168 painter->drawText(120,55, 80, 20, Qt::AlignLeft, tr("Beer style"));
1577 painter->drawText(200,55, 400, 20, Qt::AlignLeft, ": " + recipe->st_name); 2169 painter->drawText(200,55, 400, 20, Qt::AlignLeft, ": " + recipe->st_name);
1578 } 2170 }
1579 if (p_job == PR_PRODUCT) { 2171 if (p_job == PR_PRODUCT || p_job == PR_CHECKLIST) {
1580 painter->drawText(120,55, 80, 20, Qt::AlignLeft, tr("Beer style")); 2172 painter->drawText(120,55, 80, 20, Qt::AlignLeft, tr("Beer style"));
1581 painter->drawText(200,55, 400, 20, Qt::AlignLeft, ": " + product->st_name); 2173 painter->drawText(200,55, 400, 20, Qt::AlignLeft, ": " + product->st_name);
1582 } 2174 }
1583 /* The report itself may print more lines from y = 55. */ 2175 /* The report itself may print more lines from y = 55. */
1584 } 2176 }

mercurial