#include "printer.h"
#include <QPrinter>
#include <QPrintPreviewDialog>
#include <QPageSetupDialog>
#include <QTextDocument>
#include <QTextEdit>
printer::printer(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
, m_printer(NULL)
{
ui.setupUi(this);
m_printer = new QPrinter();
m_printer->setFullPage(true);
m_printer->setOrientation(QPrinter::Portrait);
m_printer->setOutputFormat(QPrinter::NativeFormat);
m_printer->setPageSize(QPrinter::Custom);
m_printer->setPaperSize(QSizeF(280, 125), QPrinter::Millimeter);
connect(ui.m_pbPrinter, SIGNAL(clicked()), this, SLOT(print()));
m_textEdit = new QTextEdit(this);
m_textEdit->setGeometry(0,0, 300, 400);
}
printer::~printer()
{
delete m_printer;
delete m_textEdit;
}
void printer::print()
{
// QPageSetupDialog setupDialog(m_printer, this);
// setupDialog.exec();
QPrintPreviewDialog preview(m_printer, this);
connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printPreview(QPrinter*)));
preview.exec();
}
void printer::printPreview(QPrinter *printer)
{
// QTextDocument doc;
// QFont font;
// font.setPointSize(10);
//
// doc.setDefaultFont(font);
// doc.setPlainText(text);
//doc.print(printer);
m_textEdit->print(printer);
}