src/PrinterDialog.cpp

Sun, 27 Mar 2022 11:59:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Mar 2022 11:59:15 +0200
changeset 88
64cf5468fd22
parent 83
6f744c602139
child 90
2396457a8167
permissions
-rw-r--r--

Improve the CMakeLists.txt. Cleanup unused variables. Removed som debug messages.

52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Printer.cpp is part of bmsapp.
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "PrinterDialog.h"
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "config.h"
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "bmsapp.h"
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include <QPrintPreviewDialog>
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 PrinterDialog::PrinterDialog(int job, int rec, QWidget* parent) : QDialog(parent)
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 {
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "PrinterDialog start job" << job << "rec" << rec;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 p_job = job;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 p_rec = rec;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 QPrinter printer(QPrinter::ScreenResolution);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 QPrintPreviewDialog preview(&printer, this);
88
64cf5468fd22 Improve the CMakeLists.txt. Cleanup unused variables. Removed som debug messages.
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
33 connect(&preview, &QPrintPreviewDialog::paintRequested, this, &PrinterDialog::printDocument);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 preview.exec();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 }
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
88
64cf5468fd22 Improve the CMakeLists.txt. Cleanup unused variables. Removed som debug messages.
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
38 PrinterDialog::~PrinterDialog() {}
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 void PrinterDialog::printDocument(QPrinter *printer)
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 {
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 qDebug() << "PrinterDialog printDocument()";
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 QRect rectangle;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 QRect boundingRect;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 QPainter painter;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 QString w;
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
49 QSqlQuery query;
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
51 const QColor c_header(255, 150, 100, 255);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
52 const QColor c_line1(210, 245, 255, 255);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
53 const QColor c_line2(255, 255, 210, 255);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 const QStringList f_types({tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct")});
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 const QStringList h_form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")});
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 const QStringList m_types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")});
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
57 const QStringList y_unit({tr("pkg"), tr("gr"), tr("ml"), tr("ml"), tr("ml"), tr("ml"), tr("gr")});
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
58 const QStringList y_types({tr("Lager"), tr("Ale"), tr("Wheat"), tr("Wine"), tr("Champagne"), tr("Brett"), tr("Kveik"), tr("Hybrid")});
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
59 const QStringList y_form({tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried")});
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 painter.begin(printer);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 qreal y = 0;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 if (p_job == PR_SUPPLIES) {
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
65 /*
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
66 * Print supplies in stock
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
67 */
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 double tot_fermentables = 0, tot_hops = 0, tot_yeasts = 0, tot_miscs = 0;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
70 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
71 y = 120;
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 /* Fermentables supplies header */
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 painter.setPen(Qt::black);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
75 painter.fillRect( 0, y, 735, 20, c_header);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 painter.drawText( 0, y+4, 90, 20, Qt::AlignLeft, tr("Type"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 painter.drawText( 90, y+4, 100, 20, Qt::AlignLeft, tr("Supplier"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 painter.drawText(190, y+4, 270, 20, Qt::AlignLeft, tr("Fermentable"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, tr("Stock"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, tr("Price/Kg"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, tr("Value"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
84 query.exec("SELECT type,name,supplier,inventory,cost FROM inventory_fermentables WHERE inventory > 0 ORDER BY type,supplier,name");
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 query.first();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 for (int i = 0 ; i < query.size() ; i++ ) {
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
87 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
88 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
89 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
90 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
91 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
92 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 painter.drawText( 0, y+4, 90, 20, Qt::AlignLeft, f_types[query.value(0).toInt()]);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 painter.drawText( 90, y+4, 100, 20, Qt::AlignLeft, query.value(2).toString());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 painter.drawText(190, y+4, 270, 20, Qt::AlignLeft, query.value(1).toString());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 w = QString("%1 kg").arg(query.value(3).toDouble(), 10, 'f', 3);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 w = QString("%1 €").arg(query.value(4).toDouble(), 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 w = QString("%1 €").arg(query.value(3).toDouble() * query.value(4).toDouble(), 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 tot_fermentables += (query.value(3).toDouble() * query.value(4).toDouble());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 query.next();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 }
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
106 painter.fillRect( 0, y, 735, 20, c_header);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 painter.drawText( 0, y+4, 100, 20, Qt::AlignLeft, tr("Total"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 w = QString("%1 €").arg(tot_fermentables, 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
112 /* Hops supplies */
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 query.exec("SELECT name,form,origin,inventory,cost FROM inventory_hops WHERE inventory > 0 ORDER BY origin,name");
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
115 if ((y + 80 + (query.size() * 20)) > painter.device()->height()) { /* Rows + header + footer + blank */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
116 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
117 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
118 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
119 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
120 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
121 }
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 painter.setPen(Qt::black);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
124 painter.fillRect( 0, y, 735, 20, c_header);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Country"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 painter.drawText(120, y+4, 260, 20, Qt::AlignLeft, tr("Hop name"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 painter.drawText(380, y+4, 80, 20, Qt::AlignLeft, tr("Form"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, tr("Stock"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, tr("Price/Kg"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, tr("Value"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 for (int i = 0; i < query.size(); i++) {
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
134 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
135 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
136 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
137 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
138 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
139 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, query.value(2).toString());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 painter.drawText(120, y+4, 260, 20, Qt::AlignLeft, query.value(0).toString());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 painter.drawText(380, y+4, 80, 20, Qt::AlignLeft, h_form[query.value(1).toInt()]);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 if (query.value(3).toDouble() < 0.6)
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 w = QString("%1 gr").arg(query.value(3).toDouble() * 1000.0, 10, 'f', 1);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 else
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 w = QString("%1 kg").arg(query.value(3).toDouble(), 10, 'f', 3);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 w = QString("%1 €").arg(query.value(4).toDouble(), 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 w = QString("%1 €").arg(query.value(3).toDouble() * query.value(4).toDouble(), 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 tot_hops += (query.value(3).toDouble() * query.value(4).toDouble());
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 query.next();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 }
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
156 painter.fillRect( 0, y, 735, 20, c_header);
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 painter.drawText( 0, y+4, 100, 20, Qt::AlignLeft, tr("Total"));
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 w = QString("%1 €").arg(tot_hops, 8, 'f', 2);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 y += 20;
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
162 /* Yeasts supplies */
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 query.exec("SELECT name,laboratory,product_id,form,inventory,cost FROM inventory_yeasts WHERE inventory > 0 ORDER BY laboratory,product_id");
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
165 if ((y + 80 + (query.size() * 20)) > painter.device()->height()) { /* Rows + header + footer + blank */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
166 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
167 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
168 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
169 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
170 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
171 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
172 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
173 painter.setPen(Qt::black);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
174 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
175 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Laboratory"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
176 painter.drawText(120, y+4, 120, 20, Qt::AlignLeft, tr("Product"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
177 painter.drawText(240, y+4, 220, 20, Qt::AlignLeft, tr("Yeast"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
178 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, tr("Stock"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
179 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, tr("Price/Kg"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
180 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, tr("Value"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
181 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
182 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
183 for (int i = 0; i < query.size(); i++) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
184 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
185 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
186 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
187 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
188 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
189 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
190 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, query.value(1).toString());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
191 painter.drawText(120, y+4, 120, 20, Qt::AlignLeft, query.value(2).toString());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
192 painter.drawText(240, y+4, 220, 20, Qt::AlignLeft, query.value(0).toString());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
193 if (query.value(3).toInt() == 0)
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
194 w = QString("%1 %2").arg(query.value(4).toDouble(), 10, 'f', 1).arg(y_unit[query.value(3).toInt()]);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
195 else
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
196 w = QString("%1 %2").arg(query.value(4).toDouble() * 1000.0, 10, 'f', 1).arg(y_unit[query.value(3).toInt()]);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
197 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
198 w = QString("%1 €").arg(query.value(5).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
199 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
200 w = QString("%1 €").arg(query.value(4).toDouble() * query.value(5).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
201 tot_yeasts += (query.value(4).toDouble() * query.value(5).toDouble());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
202 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
203 query.next();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
204 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
205 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
206 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
207 painter.drawText( 0, y+4, 100, 20, Qt::AlignLeft, tr("Total"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
208 w = QString("%1 €").arg(tot_yeasts, 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
209 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
210 y += 20;
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
212 /* Miscs supplies */
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 query.exec("SELECT name,type,amount_is_weight,inventory,cost FROM inventory_miscs WHERE inventory > 0 ORDER BY type,name");
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
215 if ((y + 80 + (query.size() * 20)) > painter.device()->height()) { /* Rows + header + footer + blank */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
216 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
217 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
218 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
219 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
220 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
221 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
222 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
223 painter.setPen(Qt::black);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
224 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
225 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, tr("Type"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
226 painter.drawText(120, y+4, 340, 20, Qt::AlignLeft, tr("Ingredient"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
227 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, tr("Stock"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
228 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, tr("Price/Kg"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
229 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, tr("Value"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
230 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
231 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
232 for (int i = 0; i < query.size(); i++) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
233 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
234 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
235 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
236 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
237 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
238 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
239 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, m_types[query.value(1).toInt()]);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
240 painter.drawText(120, y+4, 340, 20, Qt::AlignLeft, query.value(0).toString());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
241 if (query.value(2).toInt())
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
242 w = QString("%1 gr").arg(query.value(3).toDouble() * 1000.0, 10, 'f', 1);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
243 else
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
244 w = QString("%1 ml").arg(query.value(3).toDouble() * 1000.0, 10, 'f', 1);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
245 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
246 w = QString("%1 €").arg(query.value(4).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
247 painter.drawText(575, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
248 w = QString("%1 €").arg(query.value(3).toDouble() * query.value(4).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
249 tot_miscs += (query.value(3).toDouble() * query.value(4).toDouble());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
250 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
251 query.next();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
252 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
253 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
254 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
255 painter.drawText( 0, y+4, 100, 20, Qt::AlignLeft, tr("Total"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
256 w = QString("%1 €").arg(tot_miscs, 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
257 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
258 y += 20;
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
259
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
260 } else if (p_job == PR_YEASTBANK) {
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
261 /*
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
262 * Print yeast in the private yeast bank.
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
263 */
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
264 query.exec("SELECT brewery_name,my_yeastlab FROM profile_setup WHERE record = '1'");
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
265 query.first();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
266 QString my_lab = query.value(1).toString();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
267 qDebug() << my_lab;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
268 printHeader(&painter);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
269 y = 120;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
270
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
271 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
272 painter.setPen(Qt::black);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
273 painter.fillRect( 0, y, 735, 20, c_header);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
274 painter.drawText( 0, y+4, 200, 20, Qt::AlignLeft, tr("Yeast"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
275 painter.drawText(200, y+4, 230, 20, Qt::AlignLeft, tr("Description"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
276 painter.drawText(430, y+4, 80, 20, Qt::AlignCenter, tr("Type"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
277 painter.drawText(510, y+4, 80, 20, Qt::AlignCenter, tr("Form"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
278 painter.drawText(590, y+4, 70, 20, Qt::AlignRight, tr("Stock"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
279 painter.drawText(665, y+4, 70, 20, Qt::AlignLeft, tr("Date"));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
280 y += 20;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
281 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
282 query.prepare("SELECT name,type,form,inventory,production_date,short_desc "
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
283 "FROM inventory_yeasts WHERE inventory > 0 AND laboratory = :my_lab ORDER BY product_id");
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
284 query.bindValue(":my_lab", my_lab);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
285 query.exec();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
286 query.first();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
287 for (int i = 0; i < query.size(); i++) {
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
288 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
289 painter.drawText( 0, y+4, 200, 20, Qt::AlignLeft, query.value(0).toString());
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
290 painter.drawText(200, y+4, 230, 20, Qt::AlignLeft, query.value(5).toString());
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
291 painter.drawText(430, y+4, 80, 20, Qt::AlignCenter, y_types[query.value(1).toInt()]);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
292 painter.drawText(510, y+4, 80, 20, Qt::AlignCenter, y_form[query.value(2).toInt()]);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
293
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
294 if (query.value(2).toInt() == 0)
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
295 w = QString("%1 %2").arg(query.value(3).toDouble(), 10, 'f', 1).arg(y_unit[query.value(2).toInt()]);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
296 else
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
297 w = QString("%1 %2").arg(query.value(3).toDouble() * 1000.0, 10, 'f', 1).arg(y_unit[query.value(2).toInt()]);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
298 painter.drawText(590, y+4, 70, 20, Qt::AlignRight, w);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
299 painter.drawText(665, y+4, 70, 20, Qt::AlignLeft, query.value(4).toString());
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
300 query.next();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
301 y += 20;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
302 }
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 }
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 painter.end();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 }
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
311 void PrinterDialog::printHeader(QPainter *painter)
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 {
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
313 QSqlQuery query("SELECT brewery_logo,brewery_name FROM profile_setup");
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 query.first();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 QByteArray logoByteArray = query.value(0).toByteArray();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 QPixmap outPixmap = QPixmap();
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 outPixmap.loadFromData(logoByteArray);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
318 int w = outPixmap.width();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
319 int h = outPixmap.height();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
320 /* Make sure to keep the logo aspect ratio */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
321 if (w == h) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
322 painter->drawPixmap(0, 0, 100, 100, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
323 } else if (w > h) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
324 painter->drawPixmap(0, 0, 100, (h * 100) / w, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
325 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
326 painter->drawPixmap(0, 0, (w * 100) / h, 100, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
327 }
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
329 /* The fat header line */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
330 painter->setFont(QFont("Helvetica",18, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
331 if (p_job == PR_SUPPLIES) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
332 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Inventory") + " " + query.value(1).toString());
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
333 } else if (p_job == PR_YEASTBANK) {
55
2d8dbbc1ffab Updated translations.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
334 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + query.value(1).toString());
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
335 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
336 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, "?? " + query.value(1).toString());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
337 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
338 /* The first normal header line */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
339 painter->setFont(QFont("Helvetica",10, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
340 painter->drawText(120,35, 80, 20, Qt::AlignLeft, tr("Date and time"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
341 painter->drawText(200,35, 400, 20, Qt::AlignLeft, ": " + QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm"));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
342 /* The report itself may print more lines from y = 55. */
52
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 }
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344
ff7b3a41c9b5 After several days experimenting, trials and a lot of errors, a working and nice looking printer support has been added to the application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345

mercurial