1 /***************************************************************************
2 FET
3 -------------------
4 copyright : (C) by Liviu Lalescu, Volker Dirr
5 email : Liviu Lalescu: see https://lalescu.ro/liviu/ , Volker Dirr: see https://www.timetabling.de/
6 ***************************************************************************
7 statisticsprintform.cpp - description
8 -------------------
9 begin : November 2013
10 copyright : (C) by Volker Dirr
11 : https://www.timetabling.de/
12 ***************************************************************************
13 * *
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU Affero General Public License as *
16 * published by the Free Software Foundation, either version 3 of the *
17 * License, or (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21 #include <QtGlobal>
22 #include <QSizePolicy>
23
24 #include "statisticsprintform.h"
25
26 #include "timetable.h"
27 #include "timetable_defs.h"
28
29 #include "longtextmessagebox.h"
30
31 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
32 #include <QtWidgets>
33 #else
34 #include <QtGui>
35 #endif
36
37 #include <QString>
38 #include <QStringList>
39 #include <QSet>
40 #include <QList>
41 #include <QMap>
42
43 #ifndef QT_NO_PRINTER
44 #include <QPrinter>
45 #include <QPrintDialog>
46 #include <QPrintPreviewDialog>
47
48 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
49 #include <QPageSize>
50 #endif
51
52 #endif
53
54 extern Timetable gt;
55
56 extern QString generationLocalizedTime;
57
58 extern const QString COMPANY;
59 extern const QString PROGRAM;
60
61 //static int numberOfPlacedActivities1;
62
63 #ifdef QT_NO_PRINTER
64 static QMap<LocaleString, int> paperSizesMap;
65 #else
66
67 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
68 static QMap<LocaleString, QPageSize> paperSizesMap;
69 #else
70 static QMap<LocaleString, QPrinter::PaperSize> paperSizesMap;
71 #endif
72
73 #endif
74
75 //const QString CBTablesState="/timetables-combo-box-state";
76
77 const QString studentSubjectRBState="/student-subject-state-radio-button-state";
78 const QString studentTeacherRBState="/student-teacher-state-radio-button-state";
79 const QString teacherSubjectRBState="/teacher-subject-state-radio-button-state";
80 const QString teacherStudentRBState="/teacher-student-state-radio-button-state";
81 const QString subjectStudentRBState="/subject-student-state-radio-button-state";
82 const QString subjectTeacherRBState="/subject-teacher-state-radio-button-state";
83
84 const QString CBBreakState="/page-break-combo-box-state";
85 const QString CBWhiteSpaceState="/white-space-combo-box-state";
86 const QString CBprinterModeState="/printer-mode-combo-box-state";
87 const QString CBpaperSizeState="/paper-size-combo-box-state";
88 const QString CBorientationModeState="/orientation-mode-combo-box-state";
89
90 const QString printDetailedTablesState="/print-detailed-tables-check-box-state";
91 const QString printActivityTagsState="/print-activity-tags-check-box-state";
92
93 const QString activitiesPaddingState="/activity-padding-spin-box-value-state";
94 const QString tablePaddingState="/table-padding-spin-box-value-state";
95 const QString fontSizeTableState="/font-size-spin-box-value-state";
96 const QString maxNamesState="/max-names-spin-box-value-state";
97 const QString leftPageMarginState="/left-page-margin-spin-box-value-state";
98 const QString topPageMarginState="/top-page-margin-spin-box-value-state";
99 const QString rightPageMarginState="/right-page-margin-spin-box-value-state";
100 const QString bottomPageMarginState="/bottom-page-margin-spin-box-value-state";
101
StartStatisticsPrint()102 StartStatisticsPrint::StartStatisticsPrint()
103 {
104 }
105
~StartStatisticsPrint()106 StartStatisticsPrint::~StartStatisticsPrint()
107 {
108 }
109
startStatisticsPrint(QWidget * parent)110 void StartStatisticsPrint::startStatisticsPrint(QWidget* parent)
111 {
112 if(gt.rules.initialized){ //TODO: is this needed?
113 //prepare calculation
114 StatisticsPrintForm tpfd(parent);
115 tpfd.exec();
116 }
117 else{
118 QMessageBox::warning(parent, tr("FET warning"),
119 tr("Printing is currently not possible."));
120 }
121 }
122
StatisticsPrintForm(QWidget * parent)123 StatisticsPrintForm::StatisticsPrintForm(QWidget *parent): QDialog(parent){
124 StatisticsExport::computeHashForIDsStatistics(&statisticValues);
125 StatisticsExport::getNamesAndHours(&statisticValues);
126
127 this->setWindowTitle(tr("Print statistics matrix dialog"));
128
129 QHBoxLayout* wholeDialog=new QHBoxLayout(this);
130
131 QVBoxLayout* leftDialog=new QVBoxLayout();
132
133 namesList = new QListWidget();
134 namesList->setSelectionMode(QAbstractItemView::MultiSelection);
135
136 QHBoxLayout* selectUnselect=new QHBoxLayout();
137 pbSelectAll=new QPushButton(tr("All", "Refers to a list of items, select all. Please keep translation short"));
138 //pbSelectAll->setAutoDefault(false);
139 pbUnselectAll=new QPushButton(tr("None", "Refers to a list of items, select none. Please keep translation short"));
140 selectUnselect->addWidget(pbSelectAll);
141 selectUnselect->addWidget(pbUnselectAll);
142
143 leftDialog->addWidget(namesList);
144 leftDialog->addLayout(selectUnselect);
145
146 QVBoxLayout* rightDialog=new QVBoxLayout();
147
148 /*QGroupBox**/ actionsBox=new QGroupBox(tr("Print"));
149 QGridLayout* actionsBoxGrid=new QGridLayout();
150 studentSubjectRB= new QRadioButton(tr("students-subjects"));
151 studentTeacherRB= new QRadioButton(tr("students-teachers"));
152 teacherSubjectRB= new QRadioButton(tr("teachers-subjects"));
153 teacherStudentRB= new QRadioButton(tr("teachers-students"));
154 subjectStudentRB= new QRadioButton(tr("subjects-students"));
155 subjectTeacherRB= new QRadioButton(tr("subjects-teachers"));
156
157 actionsBoxGrid->addWidget(studentSubjectRB,0,0);
158 actionsBoxGrid->addWidget(studentTeacherRB,0,1);
159 actionsBoxGrid->addWidget(teacherSubjectRB,1,0);
160 actionsBoxGrid->addWidget(teacherStudentRB,1,1);
161 actionsBoxGrid->addWidget(subjectStudentRB,2,0);
162 actionsBoxGrid->addWidget(subjectTeacherRB,2,1);
163 studentSubjectRB->setChecked(true);
164 actionsBox->setLayout(actionsBoxGrid);
165
166 /*QGroupBox**/ optionsBox=new QGroupBox(tr("Options"));
167 QGridLayout* optionsBoxGrid=new QGridLayout();
168
169 QStringList breakStrings;
170 breakStrings<<tr("Page-break: none", "No page-break between statistics. Please keep translation short")
171 <<tr("Page-break: always", "Page-break after each statistic. Please keep translation short")
172 <<tr("Page-break: even", "Page-break after each even statistic. Please keep translation short");
173 CBBreak=new QComboBox();
174 CBBreak->addItems(breakStrings);
175 CBBreak->setCurrentIndex(1);
176 CBBreak->setSizePolicy(QSizePolicy::Expanding, CBBreak->sizePolicy().verticalPolicy());
177
178 QStringList whiteSpaceStrings;
179 whiteSpaceStrings<<QString("normal")<<QString("pre")<<QString("nowrap")<<QString("pre-wrap"); //don't translate these strings, because they are css parameters!
180 CBWhiteSpace=new QComboBox();
181 CBWhiteSpace->addItems(whiteSpaceStrings);
182 CBWhiteSpace->setCurrentIndex(0);
183 CBWhiteSpace->setSizePolicy(QSizePolicy::Expanding, CBWhiteSpace->sizePolicy().verticalPolicy());
184
185 QStringList printerOrientationStrings;
186 printerOrientationStrings<<tr("Portrait")<<tr("Landscape");
187 CBorientationMode=new QComboBox();
188 CBorientationMode->addItems(printerOrientationStrings);
189 CBorientationMode->setCurrentIndex(0);
190 //CBorientationMode->setDisabled(true);
191 CBorientationMode->setSizePolicy(QSizePolicy::Expanding, CBorientationMode->sizePolicy().verticalPolicy());
192
193 /* QStringList printerModeStrings;
194 printerModeStrings<<tr("ScreenResolution")<<tr("PrinterResolution")<<tr("HighResolution");
195 CBprinterMode=new QComboBox();
196 CBprinterMode->addItems(printerModeStrings);
197 CBprinterMode->setCurrentIndex(2);
198 CBprinterMode->setDisabled(true);
199 CBprinterMode->setSizePolicy(QSizePolicy::Expanding, CBprinterMode->sizePolicy().verticalPolicy());
200 */
201 paperSizesMap.clear();
202 #ifdef QT_NO_PRINTER
203 paperSizesMap.insert(tr("Custom", "Type of paper size"), 30);
204 #else
205
206 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
207 paperSizesMap.insert(tr("A0", "Type of paper size"), QPageSize(QPageSize::A0));
208 paperSizesMap.insert(tr("A1", "Type of paper size"), QPageSize(QPageSize::A1));
209 paperSizesMap.insert(tr("A2", "Type of paper size"), QPageSize(QPageSize::A2));
210 paperSizesMap.insert(tr("A3", "Type of paper size"), QPageSize(QPageSize::A3));
211 paperSizesMap.insert(tr("A4", "Type of paper size"), QPageSize(QPageSize::A4));
212 paperSizesMap.insert(tr("A5", "Type of paper size"), QPageSize(QPageSize::A5));
213 paperSizesMap.insert(tr("A6", "Type of paper size"), QPageSize(QPageSize::A6));
214 paperSizesMap.insert(tr("A7", "Type of paper size"), QPageSize(QPageSize::A7));
215 paperSizesMap.insert(tr("A8", "Type of paper size"), QPageSize(QPageSize::A8));
216 paperSizesMap.insert(tr("A9", "Type of paper size"), QPageSize(QPageSize::A9));
217 paperSizesMap.insert(tr("B0", "Type of paper size"), QPageSize(QPageSize::B0));
218 paperSizesMap.insert(tr("B1", "Type of paper size"), QPageSize(QPageSize::B1));
219 paperSizesMap.insert(tr("B2", "Type of paper size"), QPageSize(QPageSize::B2));
220 paperSizesMap.insert(tr("B3", "Type of paper size"), QPageSize(QPageSize::B3));
221 paperSizesMap.insert(tr("B4", "Type of paper size"), QPageSize(QPageSize::B4));
222 paperSizesMap.insert(tr("B5", "Type of paper size"), QPageSize(QPageSize::B5));
223 paperSizesMap.insert(tr("B6", "Type of paper size"), QPageSize(QPageSize::B6));
224 paperSizesMap.insert(tr("B7", "Type of paper size"), QPageSize(QPageSize::B7));
225 paperSizesMap.insert(tr("B8", "Type of paper size"), QPageSize(QPageSize::B8));
226 paperSizesMap.insert(tr("B9", "Type of paper size"), QPageSize(QPageSize::B9));
227 paperSizesMap.insert(tr("B10", "Type of paper size"), QPageSize(QPageSize::B10));
228 paperSizesMap.insert(tr("C5E", "Type of paper size"), QPageSize(QPageSize::C5E));
229 paperSizesMap.insert(tr("Comm10E", "Type of paper size"), QPageSize(QPageSize::Comm10E));
230 paperSizesMap.insert(tr("DLE", "Type of paper size"), QPageSize(QPageSize::DLE));
231 paperSizesMap.insert(tr("Executive", "Type of paper size"), QPageSize(QPageSize::Executive));
232 paperSizesMap.insert(tr("Folio", "Type of paper size"), QPageSize(QPageSize::Folio));
233 paperSizesMap.insert(tr("Ledger", "Type of paper size"), QPageSize(QPageSize::Ledger));
234 paperSizesMap.insert(tr("Legal", "Type of paper size"), QPageSize(QPageSize::Legal));
235 paperSizesMap.insert(tr("Letter", "Type of paper size"), QPageSize(QPageSize::Letter));
236 paperSizesMap.insert(tr("Tabloid", "Type of paper size"), QPageSize(QPageSize::Tabloid));
237 #else
238 paperSizesMap.insert(tr("A0", "Type of paper size"), QPrinter::A0);
239 paperSizesMap.insert(tr("A1", "Type of paper size"), QPrinter::A1);
240 paperSizesMap.insert(tr("A2", "Type of paper size"), QPrinter::A2);
241 paperSizesMap.insert(tr("A3", "Type of paper size"), QPrinter::A3);
242 paperSizesMap.insert(tr("A4", "Type of paper size"), QPrinter::A4);
243 paperSizesMap.insert(tr("A5", "Type of paper size"), QPrinter::A5);
244 paperSizesMap.insert(tr("A6", "Type of paper size"), QPrinter::A6);
245 paperSizesMap.insert(tr("A7", "Type of paper size"), QPrinter::A7);
246 paperSizesMap.insert(tr("A8", "Type of paper size"), QPrinter::A8);
247 paperSizesMap.insert(tr("A9", "Type of paper size"), QPrinter::A9);
248 paperSizesMap.insert(tr("B0", "Type of paper size"), QPrinter::B0);
249 paperSizesMap.insert(tr("B1", "Type of paper size"), QPrinter::B1);
250 paperSizesMap.insert(tr("B2", "Type of paper size"), QPrinter::B2);
251 paperSizesMap.insert(tr("B3", "Type of paper size"), QPrinter::B3);
252 paperSizesMap.insert(tr("B4", "Type of paper size"), QPrinter::B4);
253 paperSizesMap.insert(tr("B5", "Type of paper size"), QPrinter::B5);
254 paperSizesMap.insert(tr("B6", "Type of paper size"), QPrinter::B6);
255 paperSizesMap.insert(tr("B7", "Type of paper size"), QPrinter::B7);
256 paperSizesMap.insert(tr("B8", "Type of paper size"), QPrinter::B8);
257 paperSizesMap.insert(tr("B9", "Type of paper size"), QPrinter::B9);
258 paperSizesMap.insert(tr("B10", "Type of paper size"), QPrinter::B10);
259 paperSizesMap.insert(tr("C5E", "Type of paper size"), QPrinter::C5E);
260 paperSizesMap.insert(tr("Comm10E", "Type of paper size"), QPrinter::Comm10E);
261 paperSizesMap.insert(tr("DLE", "Type of paper size"), QPrinter::DLE);
262 paperSizesMap.insert(tr("Executive", "Type of paper size"), QPrinter::Executive);
263 paperSizesMap.insert(tr("Folio", "Type of paper size"), QPrinter::Folio);
264 paperSizesMap.insert(tr("Ledger", "Type of paper size"), QPrinter::Ledger);
265 paperSizesMap.insert(tr("Legal", "Type of paper size"), QPrinter::Legal);
266 paperSizesMap.insert(tr("Letter", "Type of paper size"), QPrinter::Letter);
267 paperSizesMap.insert(tr("Tabloid", "Type of paper size"), QPrinter::Tabloid);
268 #endif
269
270 #endif
271
272 CBpaperSize=new QComboBox();
273
274 //CBpaperSize->addItems(paperSizesMap.keys());
275 QList<LocaleString> items=paperSizesMap.keys();
276 for(const LocaleString& s : qAsConst(items))
277 CBpaperSize->addItem(s);
278
279 if(CBpaperSize->count()>=5)
280 CBpaperSize->setCurrentIndex(4);
281 else if(CBpaperSize->count()>=1)
282 CBpaperSize->setCurrentIndex(0);
283 CBpaperSize->setSizePolicy(QSizePolicy::Expanding, CBpaperSize->sizePolicy().verticalPolicy());
284
285 // markNotAvailable=new QCheckBox(tr("Mark not available"));
286 // markNotAvailable->setChecked(true);
287
288 // markBreak=new QCheckBox(tr("Mark break"));
289 // markBreak->setChecked(true);
290
291 // printSameStartingTime=new QCheckBox(tr("Print same starting time"));
292 // printSameStartingTime->setChecked(false);
293
294 // printDetailedTables=new QCheckBox(tr("Detailed tables"));
295 // printDetailedTables->setChecked(true);
296
297 printActivityTags=new QCheckBox(tr("Activity tags"));
298 printActivityTags->setChecked(true);
299
300 fontSizeTable=new QSpinBox;
301 fontSizeTable->setRange(4, 20);
302 fontSizeTable->setValue(8);
303
304 /*QString str, left, right;
305 str=tr("Font size: %1 pt");
306 dividePrefixSuffix(str, left, right);
307 fontSizeTable->setPrefix(left);
308 fontSizeTable->setSuffix(right);*/
309
310 QString s=tr("Font size: %1 pt", "pt means points for font size, when printing the statistics");
311 QStringList sl=s.split("%1");
312 QString prefix=sl.at(0);
313 QString suffix;
314 if(sl.count()<2)
315 suffix=QString("");
316 else
317 suffix=sl.at(1);
318 fontSizeTable->setPrefix(prefix);
319 fontSizeTable->setSuffix(suffix);
320 //fontSizeTable->setPrefix(tr("Font size:")+QString(" "));
321 //fontSizeTable->setSuffix(QString(" ")+tr("pt", "Means points for font size, when printing the statistics"));
322
323 fontSizeTable->setSizePolicy(QSizePolicy::Expanding, fontSizeTable->sizePolicy().verticalPolicy());
324
325 activitiesPadding=new QSpinBox;
326 activitiesPadding->setRange(0, 25);
327 activitiesPadding->setValue(0);
328
329 /*str=tr("Activities padding: %1 px");
330 dividePrefixSuffix(str, left, right);
331 activitiesPadding->setPrefix(left);
332 activitiesPadding->setSuffix(right);*/
333
334 s=tr("Activities padding: %1 px", "px means pixels, when printing the statistics");
335 sl=s.split("%1");
336 prefix=sl.at(0);
337 if(sl.count()<2)
338 suffix=QString("");
339 else
340 suffix=sl.at(1);
341 activitiesPadding->setPrefix(prefix);
342 activitiesPadding->setSuffix(suffix);
343 //activitiesPadding->setPrefix(tr("Activities padding:")+QString(" "));
344 //activitiesPadding->setSuffix(QString(" ")+tr("px", "Means pixels, when printing the statistics"));
345
346 activitiesPadding->setSizePolicy(QSizePolicy::Expanding, activitiesPadding->sizePolicy().verticalPolicy());
347
348 tablePadding=new QSpinBox;
349 tablePadding->setRange(1, 99);
350 tablePadding->setValue(1);
351
352 /*str=tr("Space after table: +%1 px");
353 dividePrefixSuffix(str, left, right);
354 tablePadding->setPrefix(left);
355 tablePadding->setSuffix(right);*/
356
357 s=tr("Space after table: +%1 px", "px means pixels, when printing the statistics");
358 sl=s.split("%1");
359 prefix=sl.at(0);
360 if(sl.count()<2)
361 suffix=QString("");
362 else
363 suffix=sl.at(1);
364 tablePadding->setPrefix(prefix);
365 tablePadding->setSuffix(suffix);
366 //tablePadding->setPrefix(tr("Space after table:")+QString(" +"));
367 //tablePadding->setSuffix(QString(" ")+tr("px", "Means pixels, when printing the statistics"));
368
369 tablePadding->setSizePolicy(QSizePolicy::Expanding, tablePadding->sizePolicy().verticalPolicy());
370
371 maxNames=new QSpinBox;
372 maxNames->setRange(1, 999);
373 maxNames->setValue(10);
374
375 /*str=tr("Split after %1 names");
376 dividePrefixSuffix(str, left, right);
377 maxNames->setPrefix(left);
378 maxNames->setSuffix(right);*/
379
380 s=tr("Split after: %1 names");
381 sl=s.split("%1");
382 prefix=sl.at(0);
383 if(sl.count()<2)
384 suffix=QString("");
385 else
386 suffix=sl.at(1);
387 maxNames->setPrefix(prefix);
388 maxNames->setSuffix(suffix);
389 //maxNames->setPrefix(tr("Split after:", "When printing, the whole phrase is 'Split after ... names'")+QString(" "));
390 //maxNames->setSuffix(QString(" ")+tr("names", "When printing, the whole phrase is 'Split after ... names'"));
391
392 maxNames->setSizePolicy(QSizePolicy::Expanding, maxNames->sizePolicy().verticalPolicy());
393
394 leftPageMargin=new QSpinBox;
395 leftPageMargin->setRange(0, 50);
396 leftPageMargin->setValue(10);
397
398 /*str=tr("Left margin: %1 mm");
399 dividePrefixSuffix(str, left, right);
400 leftPageMargin->setPrefix(left);
401 leftPageMargin->setSuffix(right);*/
402
403 s=tr("Left margin: %1 mm", "mm means millimeters");
404 sl=s.split("%1");
405 prefix=sl.at(0);
406 if(sl.count()<2)
407 suffix=QString("");
408 else
409 suffix=sl.at(1);
410 leftPageMargin->setPrefix(prefix);
411 leftPageMargin->setSuffix(suffix);
412 //leftPageMargin->setPrefix(tr("Left margin:")+QString(" "));
413 //leftPageMargin->setSuffix(QString(" ")+tr("mm", "Means milimeter, when setting page margin"));
414
415 leftPageMargin->setSizePolicy(QSizePolicy::Expanding, leftPageMargin->sizePolicy().verticalPolicy());
416
417 topPageMargin=new QSpinBox;
418 topPageMargin->setRange(0, 50);
419 topPageMargin->setValue(10);
420
421 /*str=tr("Top margin: %1 mm");
422 dividePrefixSuffix(str, left, right);
423 topPageMargin->setPrefix(left);
424 topPageMargin->setSuffix(right);*/
425
426 s=tr("Top margin: %1 mm", "mm means millimeters");
427 sl=s.split("%1");
428 prefix=sl.at(0);
429 if(sl.count()<2)
430 suffix=QString("");
431 else
432 suffix=sl.at(1);
433 topPageMargin->setPrefix(prefix);
434 topPageMargin->setSuffix(suffix);
435 //topPageMargin->setPrefix(tr("Top margin:")+QString(" "));
436 //topPageMargin->setSuffix(QString(" ")+tr("mm", "Means milimeter, when setting page margin"));
437
438 topPageMargin->setSizePolicy(QSizePolicy::Expanding, topPageMargin->sizePolicy().verticalPolicy());
439
440 rightPageMargin=new QSpinBox;
441 rightPageMargin->setRange(0, 50);
442 rightPageMargin->setValue(10);
443
444 /*str=tr("Right margin: %1 mm");
445 dividePrefixSuffix(str, left, right);
446 rightPageMargin->setPrefix(left);
447 rightPageMargin->setSuffix(right);*/
448
449 s=tr("Right margin: %1 mm", "mm means millimeters");
450 sl=s.split("%1");
451 prefix=sl.at(0);
452 if(sl.count()<2)
453 suffix=QString("");
454 else
455 suffix=sl.at(1);
456 rightPageMargin->setPrefix(prefix);
457 rightPageMargin->setSuffix(suffix);
458 //rightPageMargin->setPrefix(tr("Right margin:")+QString(" "));
459 //rightPageMargin->setSuffix(QString(" ")+tr("mm", "Means milimeter, when setting page margin"));
460
461 rightPageMargin->setSizePolicy(QSizePolicy::Expanding, rightPageMargin->sizePolicy().verticalPolicy());
462
463 bottomPageMargin=new QSpinBox;
464 bottomPageMargin->setRange(0, 50);
465 bottomPageMargin->setValue(10);
466
467 /*str=tr("Bottom margin: %1 mm");
468 dividePrefixSuffix(str, left, right);
469 bottomPageMargin->setPrefix(left);
470 bottomPageMargin->setSuffix(right);*/
471
472 s=tr("Bottom margin: %1 mm", "mm means millimeters");
473 sl=s.split("%1");
474 prefix=sl.at(0);
475 if(sl.count()<2)
476 suffix=QString("");
477 else
478 suffix=sl.at(1);
479 bottomPageMargin->setPrefix(prefix);
480 bottomPageMargin->setSuffix(suffix);
481 //bottomPageMargin->setPrefix(tr("Bottom margin:")+QString(" "));
482 //bottomPageMargin->setSuffix(QString(" ")+tr("mm", "Means milimeter, when setting page margin"));
483
484 bottomPageMargin->setSizePolicy(QSizePolicy::Expanding, bottomPageMargin->sizePolicy().verticalPolicy());
485
486 pbPrintPreviewSmall=new QPushButton(tr("Teaser", "Small print preview. Please keep translation short"));
487 pbPrintPreviewFull=new QPushButton(tr("Preview", "Full print preview. Please keep translation short"));
488 pbPrint=new QPushButton(tr("Print", "Please keep translation short"));
489
490 pbClose=new QPushButton(tr("Close", "Please keep translation short"));
491 pbClose->setAutoDefault(false);
492
493 optionsBoxGrid->addWidget(leftPageMargin,0,0);
494 optionsBoxGrid->addWidget(rightPageMargin,1,0);
495 optionsBoxGrid->addWidget(topPageMargin,2,0);
496 optionsBoxGrid->addWidget(bottomPageMargin,3,0);
497
498 optionsBoxGrid->addWidget(fontSizeTable,0,1);
499 optionsBoxGrid->addWidget(maxNames,1,1);
500 optionsBoxGrid->addWidget(activitiesPadding,2,1);
501 optionsBoxGrid->addWidget(tablePadding,3,1);
502
503 optionsBoxGrid->addWidget(CBpaperSize,4,0);
504 optionsBoxGrid->addWidget(CBWhiteSpace,4,1);
505 optionsBoxGrid->addWidget(CBorientationMode,5,0);
506 optionsBoxGrid->addWidget(CBBreak,5,1);
507 // optionsBoxGrid->addWidget(CBprinterMode,5,0);
508 optionsBoxGrid->addWidget(printActivityTags,6,0);
509 // optionsBoxGrid->addWidget(printDetailedTables,6,1);
510
511 optionsBox->setLayout(optionsBoxGrid);
512 optionsBox->setSizePolicy(QSizePolicy::Expanding, optionsBox->sizePolicy().verticalPolicy());
513
514 QHBoxLayout* previewPrintClose=new QHBoxLayout();
515 previewPrintClose->addStretch();
516 previewPrintClose->addWidget(pbPrintPreviewSmall);
517 previewPrintClose->addWidget(pbPrintPreviewFull);
518 previewPrintClose->addWidget(pbPrint);
519 previewPrintClose->addStretch();
520 previewPrintClose->addWidget(pbClose);
521
522 rightDialog->addWidget(actionsBox);
523 rightDialog->addWidget(optionsBox);
524 rightDialog->addStretch();
525 rightDialog->addLayout(previewPrintClose);
526
527 //wholeDialog->addWidget(textDocument);
528 wholeDialog->addLayout(leftDialog);
529 wholeDialog->addLayout(rightDialog);
530
531 updateNamesList();
532
533 connect(pbSelectAll, SIGNAL(clicked()), this, SLOT(selectAll()));
534 connect(pbUnselectAll, SIGNAL(clicked()), this, SLOT(unselectAll()));
535 connect(pbPrint, SIGNAL(clicked()), this, SLOT(print()));
536 connect(pbPrintPreviewSmall, SIGNAL(clicked()), this, SLOT(printPreviewSmall()));
537 connect(pbPrintPreviewFull, SIGNAL(clicked()), this, SLOT(printPreviewFull()));
538 connect(pbClose, SIGNAL(clicked()), this, SLOT(close()));
539
540 connect(studentSubjectRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
541 connect(studentTeacherRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
542 connect(teacherSubjectRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
543 connect(teacherStudentRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
544 connect(subjectStudentRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
545 connect(subjectTeacherRB, SIGNAL(toggled(bool)), this, SLOT(updateNamesList()));
546
547 int ww=this->sizeHint().width();
548 if(ww>900)
549 ww=900;
550 if(ww<700)
551 ww=700;
552
553 int hh=this->sizeHint().height();
554 if(hh>650)
555 hh=650;
556 if(hh<500)
557 hh=500;
558
559 this->resize(ww, hh);
560 centerWidgetOnScreen(this);
561 restoreFETDialogGeometry(this);
562
563 QSettings settings(COMPANY, PROGRAM);
564
565 if(settings.contains(this->metaObject()->className()+studentSubjectRBState))
566 studentSubjectRB->setChecked(settings.value(this->metaObject()->className()+studentSubjectRBState).toBool());
567 if(settings.contains(this->metaObject()->className()+studentTeacherRBState))
568 studentTeacherRB->setChecked(settings.value(this->metaObject()->className()+studentTeacherRBState).toBool());
569 if(settings.contains(this->metaObject()->className()+teacherSubjectRBState))
570 teacherSubjectRB->setChecked(settings.value(this->metaObject()->className()+teacherSubjectRBState).toBool());
571 if(settings.contains(this->metaObject()->className()+teacherStudentRBState))
572 teacherStudentRB->setChecked(settings.value(this->metaObject()->className()+teacherStudentRBState).toBool());
573 if(settings.contains(this->metaObject()->className()+subjectStudentRBState))
574 subjectStudentRB->setChecked(settings.value(this->metaObject()->className()+subjectStudentRBState).toBool());
575 if(settings.contains(this->metaObject()->className()+subjectTeacherRBState))
576 subjectTeacherRB->setChecked(settings.value(this->metaObject()->className()+subjectTeacherRBState).toBool());
577 //
578 if(settings.contains(this->metaObject()->className()+CBBreakState))
579 CBBreak->setCurrentIndex(settings.value(this->metaObject()->className()+CBBreakState).toInt());
580 if(settings.contains(this->metaObject()->className()+CBWhiteSpaceState))
581 CBWhiteSpace->setCurrentIndex(settings.value(this->metaObject()->className()+CBWhiteSpaceState).toInt());
582 //if(settings.contains(this->metaObject()->className()+CBprinterModeState))
583 // CBprinterMode->setCurrentIndex(settings.value(this->metaObject()->className()+CBprinterModeState).toInt());
584 if(settings.contains(this->metaObject()->className()+CBpaperSizeState))
585 CBpaperSize->setCurrentIndex(settings.value(this->metaObject()->className()+CBpaperSizeState).toInt());
586 if(settings.contains(this->metaObject()->className()+CBorientationModeState))
587 CBorientationMode->setCurrentIndex(settings.value(this->metaObject()->className()+CBorientationModeState).toInt());
588 // if(settings.contains(this->metaObject()->className()+printDetailedTablesState))
589 // printDetailedTables->setChecked(settings.value(this->metaObject()->className()+printDetailedTablesState).toBool());
590 if(settings.contains(this->metaObject()->className()+printActivityTagsState))
591 printActivityTags->setChecked(settings.value(this->metaObject()->className()+printActivityTagsState).toBool());
592 //
593 if(settings.contains(this->metaObject()->className()+activitiesPaddingState))
594 activitiesPadding->setValue(settings.value(this->metaObject()->className()+activitiesPaddingState).toInt());
595 if(settings.contains(this->metaObject()->className()+tablePaddingState))
596 tablePadding->setValue(settings.value(this->metaObject()->className()+tablePaddingState).toInt());
597 if(settings.contains(this->metaObject()->className()+fontSizeTableState))
598 fontSizeTable->setValue(settings.value(this->metaObject()->className()+fontSizeTableState).toInt());
599 if(settings.contains(this->metaObject()->className()+maxNamesState))
600 maxNames->setValue(settings.value(this->metaObject()->className()+maxNamesState).toInt());
601 if(settings.contains(this->metaObject()->className()+leftPageMarginState))
602 leftPageMargin->setValue(settings.value(this->metaObject()->className()+leftPageMarginState).toInt());
603 if(settings.contains(this->metaObject()->className()+topPageMarginState))
604 topPageMargin->setValue(settings.value(this->metaObject()->className()+topPageMarginState).toInt());
605 if(settings.contains(this->metaObject()->className()+CBorientationModeState))
606 rightPageMargin->setValue(settings.value(this->metaObject()->className()+rightPageMarginState).toInt());
607 if(settings.contains(this->metaObject()->className()+bottomPageMarginState))
608 bottomPageMargin->setValue(settings.value(this->metaObject()->className()+bottomPageMarginState).toInt());
609 }
610
~StatisticsPrintForm()611 StatisticsPrintForm::~StatisticsPrintForm(){
612 saveFETDialogGeometry(this);
613
614 QSettings settings(COMPANY, PROGRAM);
615 //save other settings
616
617 settings.setValue(this->metaObject()->className()+studentSubjectRBState, studentSubjectRB->isChecked());
618 settings.setValue(this->metaObject()->className()+studentTeacherRBState, studentTeacherRB->isChecked());
619 settings.setValue(this->metaObject()->className()+teacherSubjectRBState, teacherSubjectRB->isChecked());
620 settings.setValue(this->metaObject()->className()+teacherStudentRBState, teacherStudentRB->isChecked());
621 settings.setValue(this->metaObject()->className()+subjectStudentRBState, subjectStudentRB->isChecked());
622 settings.setValue(this->metaObject()->className()+subjectTeacherRBState, subjectTeacherRB->isChecked());
623 //
624 settings.setValue(this->metaObject()->className()+CBBreakState, CBBreak->currentIndex());
625 settings.setValue(this->metaObject()->className()+CBWhiteSpaceState, CBWhiteSpace->currentIndex());
626 //settings.setValue(this->metaObject()->className()+CBprinterModeState, CBprinterMode->currentIndex());
627 settings.setValue(this->metaObject()->className()+CBpaperSizeState, CBpaperSize->currentIndex());
628 settings.setValue(this->metaObject()->className()+CBorientationModeState, CBorientationMode->currentIndex());
629 //
630 // settings.setValue(this->metaObject()->className()+printDetailedTablesState, printDetailedTables->isChecked());
631 settings.setValue(this->metaObject()->className()+printActivityTagsState, printActivityTags->isChecked());
632 //
633 settings.setValue(this->metaObject()->className()+activitiesPaddingState, activitiesPadding->value());
634 settings.setValue(this->metaObject()->className()+tablePaddingState, tablePadding->value());
635 settings.setValue(this->metaObject()->className()+fontSizeTableState, fontSizeTable->value());
636 settings.setValue(this->metaObject()->className()+maxNamesState, maxNames->value());
637 settings.setValue(this->metaObject()->className()+leftPageMarginState, leftPageMargin->value());
638 settings.setValue(this->metaObject()->className()+topPageMarginState, topPageMargin->value());
639 settings.setValue(this->metaObject()->className()+rightPageMarginState, rightPageMargin->value());
640 settings.setValue(this->metaObject()->className()+bottomPageMarginState, bottomPageMargin->value());
641 }
642
selectAll()643 void StatisticsPrintForm::selectAll(){
644 namesList->selectAll();
645 }
646
unselectAll()647 void StatisticsPrintForm::unselectAll(){
648 namesList->clearSelection();
649 }
650
updateNamesList()651 void StatisticsPrintForm::updateNamesList(){
652 namesList->clear();
653
654 if(studentSubjectRB->isChecked() || studentTeacherRB->isChecked()){
655 int count=0;
656 for(const QString& student : qAsConst(statisticValues.allStudentsNames)){
657 namesList->addItem(student);
658 QListWidgetItem* tmpItem=namesList->item(count);
659 tmpItem->setSelected(true);
660 count++;
661 }
662 }
663 if(teacherSubjectRB->isChecked() || teacherStudentRB->isChecked()){
664 int count=0;
665 for(const QString& teacher : qAsConst(statisticValues.allTeachersNames)){
666 namesList->addItem(teacher);
667 QListWidgetItem* tmpItem=namesList->item(count);
668 tmpItem->setSelected(true);
669 count++;
670 }
671 }
672 if(subjectStudentRB->isChecked() || subjectTeacherRB->isChecked()){
673 int count=0;
674 for(const QString& subject : qAsConst(statisticValues.allSubjectsNames)){
675 namesList->addItem(subject);
676 QListWidgetItem* tmpItem=namesList->item(count);
677 tmpItem->setSelected(true);
678 count++;
679 }
680 }
681 }
682
updateHTMLprintString(bool printAll)683 QString StatisticsPrintForm::updateHTMLprintString(bool printAll){
684 QString saveTime=generationLocalizedTime;
685
686 QString tmp;
687 tmp+="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
688 tmp+=" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n";
689
690 if(LANGUAGE_STYLE_RIGHT_TO_LEFT==false)
691 tmp+="<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\""+LANGUAGE_FOR_HTML+"\" xml:lang=\""+LANGUAGE_FOR_HTML+"\">\n";
692 else
693 tmp+="<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\""+LANGUAGE_FOR_HTML+"\" xml:lang=\""+LANGUAGE_FOR_HTML+"\" dir=\"rtl\">\n";
694
695 //QTBUG-9438
696 //QTBUG-2730
697 tmp+=" <head>\n";
698 tmp+=" <title>"+protect2(gt.rules.institutionName)+"</title>\n";
699 tmp+=" <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n";
700 tmp+=" <style type=\"text/css\">\n";
701
702 //this variant doesn't need the "back" stuff, but there will be an empty last page!
703 //but you need to care about correct odd and even like in the groups tables
704 /* tmp+=" table.even_table {\n";
705 if(CBBreak->currentIndex()==1 || CBBreak->currentIndex()==2){
706 tmp+=" page-break-after: always;";
707 } //else {
708 //tmp+=" padding-top: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug. (*1*)
709 //tmp+=" padding-bottom: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug. (*1*)
710 //}
711 tmp+=" }\n";
712 tmp+=" table.odd_table {\n";
713 if(CBBreak->currentIndex()==1){
714 tmp+=" page-break-after: always;";
715 } //else {
716 //tmp+=" padding-top: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug. (*1*)
717 //tmp+=" padding-bottom: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug. (*1*)
718 //}
719 tmp+=" }\n";
720 */
721
722 //start. the "back" stuff is needed because of a qt bug (*1*). it also solves the last empty page problem.
723 tmp+=" p.back0 {\n"; //i can't to that with a class in table, because of a qt bug
724 if(CBBreak->currentIndex()==0)
725 tmp+=" font-size: "+QString::number(tablePadding->value())+"pt;\n"; //i can't do that in table, because it will also afect detailed table cells. it is not possible with a class, because of a qt bug.
726 else
727 tmp+=" font-size: 1pt;\n"; //font size 0 is not possible.
728 // tmp+=" padding-top: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug.
729 // tmp+=" padding-bottom: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug.
730 if(CBBreak->currentIndex()==1 || CBBreak->currentIndex()==2)
731 tmp+=" page-break-after: always;";
732 tmp+=" }\n";
733 tmp+=" p.back1 {\n"; //i can't to that with a class in table, because of a qt bug
734 if(CBBreak->currentIndex()==0 || CBBreak->currentIndex()==2)
735 tmp+=" font-size: "+QString::number(tablePadding->value())+"pt;\n"; //i can't do that in table, because it will also afect detailed table cells. it is not possible with a class, because of a qt bug.
736 else
737 tmp+=" font-size: 1pt;\n"; //font size 0 is not possible.
738 // tmp+=" padding-top: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug.
739 // tmp+=" padding-bottom: "+QString::number(tablePadding->value())+"px;\n"; //not possible: qt bug.
740 if(CBBreak->currentIndex()==1)
741 tmp+=" page-break-after: always;";
742 tmp+=" }\n";
743 //end. the "back" stuff is only needed because of a qt bug (*1*). delete this as soon as bug is solved
744
745 tmp+=" table {\n";
746 tmp+=" font-size: "+QString::number(fontSizeTable->value())+"pt;\n";
747 tmp+=" padding-top: "+QString::number(tablePadding->value())+"px;\n";
748 tmp+=" }\n";
749 tmp+=" th {\n";
750 tmp+=" text-align: center;\n"; //currently no effect because of a qt bug (compare http://bugreports.qt.nokia.com/browse/QTBUG-2730 )
751 tmp+=" vertical-align: middle;\n";
752 tmp+=" white-space: "+CBWhiteSpace->currentText()+";\n";
753 tmp+=" }\n";
754 tmp+=" td {\n";
755 tmp+=" text-align: center;\n"; //currently no effect because of a qt bug (compare http://bugreports.qt.nokia.com/browse/QTBUG-2730 )
756 tmp+=" vertical-align: middle;\n";
757 tmp+=" white-space: "+CBWhiteSpace->currentText()+";\n";
758 tmp+=" padding-left: "+QString::number(activitiesPadding->value())+"px;\n";
759 tmp+=" padding-right: "+QString::number(activitiesPadding->value())+"px;\n";
760 tmp+=" }\n";
761 tmp+=" td.detailed {\n";
762 // tmp+=" padding-left: 4px;\n";
763 // tmp+=" padding-right: 4px;\n";
764 tmp+=" }\n";
765 tmp+=" th.xAxis {\n"; //need level 2
766 // tmp+=" padding-left: 4px;\n";
767 // tmp+=" padding-right: 4px;\n";
768 tmp+=" }\n";
769 tmp+=" th.yAxis {\n"; //need level 2
770 // tmp+=" padding-top: 4px;\n";
771 // tmp+=" padding-bottom: 4px;\n";
772 tmp+=" }\n";
773 tmp+=" tr.line0, div.line0 {\n"; //need level 3
774 tmp+=" /*font-size: 12pt;*/\n";
775 tmp+=" color: gray;\n";
776 tmp+=" }\n";
777 tmp+=" tr.line1, div.line1 {\n"; //need level 3
778 tmp+=" /*font-size: 12pt;*/\n";
779 tmp+=" }\n";
780 tmp+=" tr.line2, div.line2 {\n"; //need level 3
781 tmp+=" /*font-size: 12pt;*/\n";
782 tmp+=" color: gray;\n";
783 tmp+=" }\n";
784 tmp+=" tr.line3, div.line3 {\n"; //need level 3
785 tmp+=" /*font-size: 12pt;*/\n";
786 tmp+=" color: silver;\n";
787 tmp+=" }\n";
788 tmp+=" </style>\n";
789 tmp+=" </head>\n\n";
790 tmp+=" <body id=\"top\">\n";
791
792 //if(numberOfPlacedActivities1!=gt.rules.nInternalActivities)
793 // tmp+=" <h1>"+tr("Warning! Only %1 out of %2 activities placed!").arg(numberOfPlacedActivities1).arg(gt.rules.nInternalActivities)+"</h1>\n";
794
795 //QList<int> includedNamesIndex;
796 QSet<int> excludedNamesIndex;
797 for(int nameIndex=0; nameIndex<namesList->count(); nameIndex++){
798 QListWidgetItem* tmpItem=namesList->item(nameIndex);
799 if(tmpItem->isSelected()){
800 //includedNamesIndex<<nameIndex;
801 } else {
802 excludedNamesIndex<<nameIndex;
803 }
804 }
805
806 //maybe TODO: do the pagebreak similar in timetableexport. (so remove the odd and even table tag and use only back1 and back2 (maybe rename to odd and even))
807 // check the GroupsTimetableDaysHorizontalHtml and Year parameter then (iNi%2) isn't needed anymore then.
808
809 if(studentSubjectRB->isChecked()){
810 int count=0;
811 while(excludedNamesIndex.size()<namesList->count()){
812 tmp+=StatisticsExport::exportStatisticsStudentsSubjectsHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
813 if(excludedNamesIndex.size()<namesList->count()){
814 if(count%2==0){
815 tmp+=" <p class=\"back1\"><br /></p>\n\n";
816 } else {
817 if(!printAll) break;
818 tmp+=" <p class=\"back0\"><br /></p>\n\n";
819 }
820 count++;
821 }
822 }
823 }
824 if(studentTeacherRB->isChecked()){
825 int count=0;
826 while(excludedNamesIndex.size()<namesList->count()){
827 tmp+=StatisticsExport::exportStatisticsStudentsTeachersHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
828 if(excludedNamesIndex.size()<namesList->count()){
829 if(count%2==0){
830 tmp+=" <p class=\"back1\"><br /></p>\n\n";
831 } else {
832 if(!printAll) break;
833 tmp+=" <p class=\"back0\"><br /></p>\n\n";
834 }
835 count++;
836 }
837 }
838 }
839 if(teacherSubjectRB->isChecked()){
840 int count=0;
841 while(excludedNamesIndex.size()<namesList->count()){
842 tmp+=StatisticsExport::exportStatisticsTeachersSubjectsHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
843 if(excludedNamesIndex.size()<namesList->count()){
844 if(count%2==0){
845 tmp+=" <p class=\"back1\"><br /></p>\n\n";
846 } else {
847 if(!printAll) break;
848 tmp+=" <p class=\"back0\"><br /></p>\n\n";
849 }
850 count++;
851 }
852 }
853 }
854 if(teacherStudentRB->isChecked()){
855 int count=0;
856 while(excludedNamesIndex.size()<namesList->count()){
857 tmp+=StatisticsExport::exportStatisticsTeachersStudentsHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
858 if(excludedNamesIndex.size()<namesList->count()){
859 if(count%2==0){
860 tmp+=" <p class=\"back1\"><br /></p>\n\n";
861 } else {
862 if(!printAll) break;
863 tmp+=" <p class=\"back0\"><br /></p>\n\n";
864 }
865 count++;
866 }
867 }
868 }
869 if(subjectStudentRB->isChecked()){
870 int count=0;
871 while(excludedNamesIndex.size()<namesList->count()){
872 tmp+=StatisticsExport::exportStatisticsSubjectsStudentsHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
873 if(excludedNamesIndex.size()<namesList->count()){
874 if(count%2==0){
875 tmp+=" <p class=\"back1\"><br /></p>\n\n";
876 } else {
877 if(!printAll) break;
878 tmp+=" <p class=\"back0\"><br /></p>\n\n";
879 }
880 count++;
881 }
882 }
883 }
884 if(subjectTeacherRB->isChecked()){
885 int count=0;
886 while(excludedNamesIndex.size()<namesList->count()){
887 tmp+=StatisticsExport::exportStatisticsSubjectsTeachersHtml(nullptr/*parent*/, saveTime, statisticValues, 3, printActivityTags->isChecked(), maxNames->value(), &excludedNamesIndex);
888 if(excludedNamesIndex.size()<namesList->count()){
889 if(count%2==0){
890 tmp+=" <p class=\"back1\"><br /></p>\n\n";
891 } else {
892 if(!printAll) break;
893 tmp+=" <p class=\"back0\"><br /></p>\n\n";
894 }
895 count++;
896 }
897 }
898 }
899 // end
900
901 tmp+=" </body>\n";
902 tmp+="</html>\n\n";
903 return tmp;
904 }
905
906 /*void StatisticsPrintForm::updateCBDivideTimeAxisByDay()
907 {
908 CBDivideTimeAxisByDay->setDisabled(RBDaysHorizontal->isChecked() || RBDaysVertical->isChecked());
909 }*/
910
print()911 void StatisticsPrintForm::print(){
912 #ifdef QT_NO_PRINTER
913 QMessageBox::warning(this, tr("FET warning"), tr("FET is compiled without printer support "
914 "- it is impossible to print from this dialog. Please export and open the HTML statistics from the results directory"));
915 #else
916 QPrinter printer(QPrinter::HighResolution);
917
918 assert(paperSizesMap.contains(CBpaperSize->currentText()));
919 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
920 printer.setPageSize(paperSizesMap.value(CBpaperSize->currentText()));
921 #else
922 printer.setPaperSize(paperSizesMap.value(CBpaperSize->currentText()));
923 #endif
924
925 switch(CBorientationMode->currentIndex()){
926 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
927 case 0: printer.setPageOrientation(QPageLayout::Portrait); break;
928 case 1: printer.setPageOrientation(QPageLayout::Landscape); break;
929 #else
930 case 0: printer.setOrientation(QPrinter::Portrait); break;
931 case 1: printer.setOrientation(QPrinter::Landscape); break;
932 #endif
933 default: assert(0==1);
934 }
935 #if QT_VERSION >= QT_VERSION_CHECK(5,3,0)
936 QMarginsF printerMargins;
937 printerMargins.setLeft(leftPageMargin->value());
938 printerMargins.setRight(rightPageMargin->value());
939 printerMargins.setBottom(bottomPageMargin->value());
940 printerMargins.setTop(topPageMargin->value());
941 if(!printer.setPageMargins(printerMargins, QPageLayout::Millimeter)){
942 printerMargins=printer.pageLayout().minimumMargins();
943 QMessageBox::warning(this, tr("FET warning"), tr("No margins set, because at least one value is too small. "
944 "You need to enter at least:\nLeft: %1\nRight: %2\nTop: %3\nBottom: %4")
945 .arg(printerMargins.left()).arg(printerMargins.right()).arg(printerMargins.top()).arg(printerMargins.bottom()));
946 }
947 #else
948 printer.setPageMargins(leftPageMargin->value(), topPageMargin->value(), rightPageMargin->value(), bottomPageMargin->value(), QPrinter::Millimeter);
949 #endif
950 //QPrintDialog *printDialog = new QPrintDialog(&printer, this);
951 QPrintDialog printDialog(&printer, this);
952 printDialog.setWindowTitle(tr("Print statistics"));
953 if (printDialog.exec() == QDialog::Accepted) {
954 QTextDocument textDocument;
955 textDocument.documentLayout()->setPaintDevice(&printer);
956 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
957 textDocument.setPageSize(QSizeF(printer.pageLayout().paintRectPixels(printer.resolution()).size()));
958 #else
959 textDocument.setPageSize(QSizeF(printer.pageRect().size()));
960 #endif
961 textDocument.setHtml(updateHTMLprintString(true));
962 textDocument.print(&printer);
963 }
964 //delete printDialog;
965 #endif
966 }
967
printPreviewFull()968 void StatisticsPrintForm::printPreviewFull(){
969 #ifdef QT_NO_PRINTER
970 QMessageBox::warning(this, tr("FET warning"), tr("FET is compiled without printer support "
971 "- it is impossible to print from this dialog. Please export and open the HTML statistics from the results directory"));
972 #else
973 QPrinter printer(QPrinter::HighResolution);
974
975 assert(paperSizesMap.contains(CBpaperSize->currentText()));
976 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
977 printer.setPageSize(paperSizesMap.value(CBpaperSize->currentText()));
978 #else
979 printer.setPaperSize(paperSizesMap.value(CBpaperSize->currentText()));
980 #endif
981
982 switch(CBorientationMode->currentIndex()){
983 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
984 case 0: printer.setPageOrientation(QPageLayout::Portrait); break;
985 case 1: printer.setPageOrientation(QPageLayout::Landscape); break;
986 #else
987 case 0: printer.setOrientation(QPrinter::Portrait); break;
988 case 1: printer.setOrientation(QPrinter::Landscape); break;
989 #endif
990 default: assert(0==1);
991 }
992 #if QT_VERSION >= QT_VERSION_CHECK(5,3,0)
993 QMarginsF printerMargins;
994 printerMargins.setLeft(leftPageMargin->value());
995 printerMargins.setRight(rightPageMargin->value());
996 printerMargins.setBottom(bottomPageMargin->value());
997 printerMargins.setTop(topPageMargin->value());
998 if(!printer.setPageMargins(printerMargins, QPageLayout::Millimeter)){
999 printerMargins=printer.pageLayout().minimumMargins();
1000 QMessageBox::warning(this, tr("FET warning"), tr("No margins set, because at least one value is too small. "
1001 "You need to enter at least:\nLeft: %1\nRight: %2\nTop: %3\nBottom: %4")
1002 .arg(printerMargins.left()).arg(printerMargins.right()).arg(printerMargins.top()).arg(printerMargins.bottom()));
1003 }
1004 #else
1005 printer.setPageMargins(leftPageMargin->value(), topPageMargin->value(), rightPageMargin->value(), bottomPageMargin->value(), QPrinter::Millimeter);
1006 #endif
1007 QPrintPreviewDialog printPreviewFull(&printer, this);
1008 connect(&printPreviewFull, SIGNAL(paintRequested(QPrinter*)), SLOT(updatePreviewFull(QPrinter*)));
1009 printPreviewFull.exec();
1010 #endif
1011 }
1012
updatePreviewFull(QPrinter * printer)1013 void StatisticsPrintForm::updatePreviewFull(QPrinter* printer){
1014 #ifdef QT_NO_PRINTER
1015 Q_UNUSED(printer);
1016
1017 QMessageBox::warning(this, tr("FET warning"), tr("FET is compiled without printer support "
1018 "- it is impossible to print from this dialog. Please export and open the HTML statistics from the results directory"));
1019 #else
1020 QTextDocument textDocument;
1021 textDocument.documentLayout()->setPaintDevice(printer);
1022 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
1023 textDocument.setPageSize(QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()));
1024 #else
1025 textDocument.setPageSize(QSizeF(printer->pageRect().size()));
1026 #endif
1027 textDocument.setHtml(updateHTMLprintString(true));
1028 textDocument.print(printer);
1029 #endif
1030 }
1031
printPreviewSmall()1032 void StatisticsPrintForm::printPreviewSmall(){
1033 #ifdef QT_NO_PRINTER
1034 QMessageBox::warning(this, tr("FET warning"), tr("FET is compiled without printer support "
1035 "- it is impossible to print from this dialog. Please export and open the HTML statistics from the results directory"));
1036 #else
1037 QPrinter printer(QPrinter::HighResolution);
1038
1039 assert(paperSizesMap.contains(CBpaperSize->currentText()));
1040 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
1041 #else
1042 printer.setPaperSize(paperSizesMap.value(CBpaperSize->currentText()));
1043 #endif
1044
1045 switch(CBorientationMode->currentIndex()){
1046 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
1047 case 0: printer.setPageOrientation(QPageLayout::Portrait); break;
1048 case 1: printer.setPageOrientation(QPageLayout::Landscape); break;
1049 #else
1050 case 0: printer.setOrientation(QPrinter::Portrait); break;
1051 case 1: printer.setOrientation(QPrinter::Landscape); break;
1052 #endif
1053 default: assert(0==1);
1054 }
1055 #if QT_VERSION >= QT_VERSION_CHECK(5,3,0)
1056 QMarginsF printerMargins;
1057 printerMargins.setLeft(leftPageMargin->value());
1058 printerMargins.setRight(rightPageMargin->value());
1059 printerMargins.setBottom(bottomPageMargin->value());
1060 printerMargins.setTop(topPageMargin->value());
1061 if(!printer.setPageMargins(printerMargins, QPageLayout::Millimeter)){
1062 printerMargins=printer.pageLayout().minimumMargins();
1063 QMessageBox::warning(this, tr("FET warning"), tr("No margins set, because at least one value is too small. "
1064 "You need to enter at least:\nLeft: %1\nRight: %2\nTop: %3\nBottom: %4")
1065 .arg(printerMargins.left()).arg(printerMargins.right()).arg(printerMargins.top()).arg(printerMargins.bottom()));
1066 }
1067 #else
1068 printer.setPageMargins(leftPageMargin->value(), topPageMargin->value(), rightPageMargin->value(), bottomPageMargin->value(), QPrinter::Millimeter);
1069 #endif
1070 QPrintPreviewDialog printPreviewSmall(&printer, this);
1071 connect(&printPreviewSmall, SIGNAL(paintRequested(QPrinter*)), SLOT(updatePreviewSmall(QPrinter*)));
1072 printPreviewSmall.exec();
1073 #endif
1074 }
1075
updatePreviewSmall(QPrinter * printer)1076 void StatisticsPrintForm::updatePreviewSmall(QPrinter* printer){
1077 #ifdef QT_NO_PRINTER
1078 Q_UNUSED(printer);
1079
1080 QMessageBox::warning(this, tr("FET warning"), tr("FET is compiled without printer support "
1081 "- it is impossible to print from this dialog. Please export and open the HTML statistics from the results directory"));
1082 #else
1083 QTextDocument textDocument;
1084 textDocument.documentLayout()->setPaintDevice(printer);
1085 #if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
1086 textDocument.setPageSize(QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()));
1087 #else
1088 textDocument.setPageSize(QSizeF(printer->pageRect().size()));
1089 #endif
1090 textDocument.setHtml(updateHTMLprintString(false));
1091 textDocument.print(printer);
1092 #endif
1093 }
1094