src/PrinterDialog.cpp

Sun, 24 Apr 2022 14:15:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 24 Apr 2022 14:15:20 +0200
changeset 158
24bc2de721d9
parent 155
f671c599f65b
child 159
231f5c8002e3
permissions
-rw-r--r--

Activated print recipe button. The recipe record structure is now global. Added global product record structure.

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"
158
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
18 #include "EditRecipe.h"
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
19 #include "config.h"
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
20 #include "global.h"
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
21
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 #include <QPrintPreviewDialog>
90
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
23 #include <QDebug>
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
24 #include <QtSql>
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
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
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 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
28 {
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 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
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 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
32 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
33
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 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
35 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
36 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
37 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
38 }
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
88
64cf5468fd22 Improve the CMakeLists.txt. Cleanup unused variables. Removed som debug messages.
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
41 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
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
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 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
45 {
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 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
47
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 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
49 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
50 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
51 QString w;
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
52 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
53
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
54 const QColor c_header(255, 150, 100, 255);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
55 const QColor c_line1(210, 245, 255, 255);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
56 const QColor c_line2(255, 255, 210, 255);
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")});
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
58
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
59 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
60 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
61
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 if (p_job == PR_SUPPLIES) {
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
63 /*
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
64 * Print supplies in stock
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
65 */
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
66 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
67
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
68 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
69 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
70 /* 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
71 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
72 painter.setPen(Qt::black);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
82 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
83 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
84 for (int i = 0 ; i < query.size() ; i++ ) {
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
85 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
86 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
87 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
88 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
89 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
90 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
155
f671c599f65b Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
91 painter.drawText( 0, y+4, 90, 20, Qt::AlignLeft, fermentable_types[query.value(0).toInt()]);
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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 }
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
104 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
105 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
106 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
107 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
108 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
109
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
110 /* 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
111 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
112 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
113 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
114 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
115 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
116 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
117 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
118 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
119 }
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
120 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
121 painter.setPen(Qt::black);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 for (int i = 0; i < query.size(); i++) {
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
132 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
133 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
134 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
135 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
136 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
137 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
138 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
139 painter.drawText(120, y+4, 260, 20, Qt::AlignLeft, query.value(0).toString());
155
f671c599f65b Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
140 painter.drawText(380, y+4, 80, 20, Qt::AlignLeft, hop_forms[query.value(1).toInt()]);
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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 }
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
154 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
155 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
156 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
157 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
158 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
159
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
160 /* 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
161 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
162 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
163 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
164 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
165 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
166 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
167 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
168 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
169 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
170 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
171 painter.setPen(Qt::black);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
172 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
173 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
174 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
175 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
176 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
177 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
178 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
179 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
180 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
181 for (int i = 0; i < query.size(); i++) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
182 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
183 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
184 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
185 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
186 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
187 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
188 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
189 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
190 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
191 if (query.value(3).toInt() == 0)
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
192 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
193 else
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() * 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
195 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
196 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
197 painter.drawText(575, y+4, 80, 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(4).toDouble() * query.value(5).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
199 tot_yeasts += (query.value(4).toDouble() * query.value(5).toDouble());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
200 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
201 query.next();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
202 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
203 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
204 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
205 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
206 w = QString("%1 €").arg(tot_yeasts, 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
207 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
208 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
209
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
210 /* 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
211 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
212 query.first();
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
213 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
214 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
215 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
216 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
217 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
218 y += 40;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
219 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
220 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
221 painter.setPen(Qt::black);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
222 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
223 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
224 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
225 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
226 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
227 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
228 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
229 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
230 for (int i = 0; i < query.size(); i++) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
231 if ((y + 20) > painter.device()->height()) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
232 printer->newPage();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
233 printHeader(&painter);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
234 y = 120;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
235 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
236 painter.fillRect( 0, y, 735, 20, (i % 2) ? c_line1:c_line2);
155
f671c599f65b Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
237 painter.drawText( 0, y+4, 120, 20, Qt::AlignLeft, misc_types[query.value(1).toInt()]);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
238 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
239 if (query.value(2).toInt())
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
240 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
241 else
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
242 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
243 painter.drawText(460, y+4, 115, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
244 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
245 painter.drawText(575, y+4, 80, 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(3).toDouble() * query.value(4).toDouble(), 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
247 tot_miscs += (query.value(3).toDouble() * query.value(4).toDouble());
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
248 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
249 query.next();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
250 y += 20;
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
251 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
252 painter.fillRect( 0, y, 735, 20, c_header);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
253 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
254 w = QString("%1 €").arg(tot_miscs, 8, 'f', 2);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
255 painter.drawText(655, y+4, 80, 20, Qt::AlignRight, w);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
256 y += 20;
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
257
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
258 } else if (p_job == PR_YEASTBANK) {
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 * Print yeast in the private yeast bank.
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 printHeader(&painter);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
263 y = 120;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
264
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
265 painter.setFont(QFont("Helvetica", 9, QFont::Bold));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
266 painter.setPen(Qt::black);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
267 painter.fillRect( 0, y, 735, 20, c_header);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
268 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
269 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
270 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
271 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
272 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
273 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
274 y += 20;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
275 painter.setFont(QFont("Helvetica", 9, QFont::Normal));
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
276 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
277 "FROM inventory_yeasts WHERE inventory > 0 AND laboratory = :my_lab ORDER BY product_id");
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
278 query.bindValue(":my_lab", my_yeastlab);
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
279 query.exec();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
280 query.first();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
281 for (int i = 0; i < query.size(); i++) {
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
282 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
283 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
284 painter.drawText(200, y+4, 230, 20, Qt::AlignLeft, query.value(5).toString());
155
f671c599f65b Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
285 painter.drawText(430, y+4, 80, 20, Qt::AlignCenter, yeast_types[query.value(1).toInt()]);
f671c599f65b Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
286 painter.drawText(510, y+4, 80, 20, Qt::AlignCenter, yeast_forms[query.value(2).toInt()]);
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
287
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
288 if (query.value(2).toInt() == 0)
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
289 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
290 else
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
291 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
292 painter.drawText(590, y+4, 70, 20, Qt::AlignRight, w);
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
293 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
294 query.next();
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
295 y += 20;
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
296 }
158
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
297 } else if (p_job == PR_RECIPE) {
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
298
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
299 printHeader(&painter);
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
300 y = 120;
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
301
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
302 }
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 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
306 }
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
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
310 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
311 {
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 QPixmap outPixmap = QPixmap();
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
313 outPixmap.loadFromData(my_logoByteArray);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
314 int w = outPixmap.width();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
315 int h = outPixmap.height();
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
316 /* Make sure to keep the logo aspect ratio */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
317 if (w == h) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
318 painter->drawPixmap(0, 0, 100, 100, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
319 } else if (w > h) {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
320 painter->drawPixmap(0, 0, 100, (h * 100) / w, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
321 } else {
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
322 painter->drawPixmap(0, 0, (w * 100) / h, 100, outPixmap);
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
323 }
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
324
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
325 /* The fat header line */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
326 painter->setFont(QFont("Helvetica",18, QFont::Bold));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
327 if (p_job == PR_SUPPLIES) {
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
328 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Inventory") + " " + my_brewery_name);
54
bba7be9034be Added print private yeastbank
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
329 } else if (p_job == PR_YEASTBANK) {
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
330 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, tr("Yeastbank") + " " + my_brewery_name);
158
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
331 } else if (p_job == PR_RECIPE) {
24bc2de721d9 Activated print recipe button. The recipe record structure is now global. Added global product record structure.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
332 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, recipe->name);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
333 } else {
133
08635b028dcf Load waters during recipe startup. Started calcWater() function. Load profile_setup record global. The print function uses the globals now too instead of loading from the database.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
334 painter->drawText(120, 0, 500, 40, Qt::AlignLeft, "?? " + my_brewery_name);
53
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
335 }
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
336 /* The first normal header line */
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
337 painter->setFont(QFont("Helvetica",10, QFont::Normal));
d36879f13d32 Completed printing inventory supplies.
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
338 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
339 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
340 /* 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
341 }
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
342
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

mercurial