5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "printdialog.h"
22 #include "ui_printdialog.h"
25 #include <QPrintDialog>
27 PrintDialog::PrintDialog(QWidget
*parent
, Firmware
* firmware
, GeneralSettings
& generalSettings
, ModelData
& model
, const QString
& filename
) :
30 generalSettings(generalSettings
),
32 printfilename(filename
),
33 ui(new Ui::PrintDialog
),
34 multimodelprinter(firmware
)
37 setWindowIcon(CompanionIcon("print.png"));
38 setWindowTitle(model
.name
);
39 multimodelprinter
.setModel(0, &model
, &generalSettings
);
40 ui
->textEdit
->setHtml(multimodelprinter
.print(ui
->textEdit
->document()));
41 if (!printfilename
.isEmpty()) {
43 QTimer::singleShot(0, this, SLOT(autoClose()));
47 void PrintDialog::closeEvent(QCloseEvent
*event
)
51 PrintDialog::~PrintDialog()
56 void PrintDialog::on_printButton_clicked()
59 printer
.setPageMargins(10.0,10.0,10.0,10.0,printer
.Millimeter
);
60 QPrintDialog
*dialog
= new QPrintDialog(&printer
, this);
61 dialog
->setWindowTitle(tr("Print Document"));
62 if (dialog
->exec() != QDialog::Accepted
)
64 ui
->textEdit
->print(&printer
);
67 void PrintDialog::on_printFileButton_clicked()
69 QString fn
= QFileDialog::getSaveFileName(this,tr("Select PDF output file"),QString(),tr("ODF files (*.odt);;PDF Files(*.pdf);;HTML-Files (*.htm *.html);;All Files (*)"));
72 if (! (fn
.endsWith(".odt", Qt::CaseInsensitive
) || fn
.endsWith(".pdf", Qt::CaseInsensitive
) || fn
.endsWith(".htm", Qt::CaseInsensitive
) || fn
.endsWith(".html", Qt::CaseInsensitive
)) )
73 fn
+= ".pdf"; // default
74 if (fn
.endsWith(".pdf", Qt::CaseInsensitive
)) {
76 printer
.setPageMargins(10.0,10.0,10.0,10.0,printer
.Millimeter
);
77 printer
.setOutputFormat(QPrinter::PdfFormat
);
78 printer
.setColorMode(QPrinter::Color
);
79 printer
.setOutputFileName(fn
);
80 ui
->textEdit
->print(&printer
);
83 QTextDocumentWriter
writer(fn
);
84 writer
.write(ui
->textEdit
->document());
88 void PrintDialog::printToFile()
90 if (printfilename
.isEmpty())
92 if (! (printfilename
.endsWith(".odt", Qt::CaseInsensitive
) || printfilename
.endsWith(".pdf", Qt::CaseInsensitive
) || printfilename
.endsWith(".htm", Qt::CaseInsensitive
) || printfilename
.endsWith(".html", Qt::CaseInsensitive
)) )
93 printfilename
+= ".pdf"; // default
94 if (printfilename
.endsWith(".pdf", Qt::CaseInsensitive
)) {
96 printer
.setPageMargins(10.0,10.0,10.0,10.0,printer
.Millimeter
);
97 printer
.setOutputFormat(QPrinter::PdfFormat
);
98 printer
.setColorMode(QPrinter::Color
);
99 printer
.setOutputFileName(printfilename
);
100 ui
->textEdit
->print(&printer
);
103 QTextDocumentWriter
writer(printfilename
);
104 writer
.write(ui
->textEdit
->document());
108 void PrintDialog::autoClose()