30 #include "../../core/pattern/mvc/ItemObserver.h"
31 #include "../../core/PaperConfig.h"
32 #include "../../core/pattern/singleton/Context.h"
39 #include <QGraphicsScene>
40 #include <QGraphicsItem>
43 #include <QPrintPreviewDialog>
44 #include <QFileDialog>
45 #include <QApplication>
46 #include <QMessageBox>
51 m_printState(
te::layout::NoPrinter)
66 QPrinter* printer = createPrinter();
68 QPrintPreviewDialog *preview =
new QPrintPreviewDialog(printer);
69 connect(preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPaper(QPrinter*)));
101 QPainter newPainter(printer);
102 newPainter.setRenderHint(QPainter::Antialiasing);
118 renderScene(&newPainter, printer);
140 QPrinter* printer =
new QPrinter(QPrinter::HighResolution);
142 printer->setPaperSize(sf, QPrinter::Millimeter);
152 printer->pageRect(QPrinter::Millimeter);
168 if(m_printState == NoPrinter)
184 QRectF mmSourceRect(0, 0, w, h);
187 QRect pxTargetRect(0, 0, newPainter->device()->width(), newPainter->device()->height());
193 QSizeF paperPixelBox = printer->paperSize(QPrinter::DevicePixel);
196 newPainter->translate( paperPixelBox.width() / 2, paperPixelBox.height() / 2 );
197 newPainter->scale( 1, -1 );
198 newPainter->translate( -(paperPixelBox.width() / 2), -(paperPixelBox.height() / 2) );
202 m_scene->render(newPainter, pxTargetRect, mmSourceRect);
207 QWidget* wg = (QWidget*)QApplication::desktop();
208 QString fileName = QFileDialog::getSaveFileName(wg, tr(
"Save Image File"), QDir::currentPath(), tr(
"PDF Files (*.pdf)"));
210 if(fileName.isEmpty())
215 QPrinter* printer= createPrinter();
217 printer->setOutputFormat(QPrinter::PdfFormat);
218 printer->setOutputFileName(fileName);
228 msgBox.setIcon(QMessageBox::Information);
229 msgBox.setText(
"PDF exported successfully!");
240 QList<QGraphicsItem*> graphicsItems = m_scene->items();
241 foreach( QGraphicsItem *item, graphicsItems)
245 item->setSelected(
false);
void setDpiY(double dpiY)
Class responsible for paper setting. Size, orientation, custom size, etc.
virtual bool exportToPDF()
void setZoomFactor(double zoomFactor)
Change current zoom factor. Ex.: 0.5 (50%)
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
PrintScene(QGraphicsScene *scene, PaperConfig *config)
virtual LayoutOrientationType getPaperOrientantion()
Returns paper orientation type enum.
void setDpiX(double dpiX)
virtual void onChangeZoomFactor(double currentFactor)
It is called immediately when the zoom factor is changed in the Context.
static Context & getInstance()
It returns a reference to the singleton instance.
virtual void renderScene(QPainter *newPainter, QPrinter *printer)
virtual void printPreview()
virtual void redrawItems()
virtual void printPaper(QPrinter *printer)
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
virtual void getPaperSize(double &w, double &h)
Returns paper size. Height and Width.
PaperConfig * getPaperConfig() const
Returns paper setting.
virtual void deselectAllItems()
double getZoomFactor()
Returns current zoom factor. Ex.: 0.5 (50%)
virtual QPrinter * createPrinter()
Class responsible for printing the entire content or part of the scene. As the scene is upside down...