void mainArea::printPreview(){ QPrinter printer; QPrintPreviewDialog preview( &printer, this ); connect( &preview, SIGNAL(paintRequested(QPrinter *) ), this, SLOT(printDocument(QPrinter*))); preview.exec();}void mainArea::printDocument( QPrinter *printer_ ){ QPainter painter; painter.begin(printer_); this->render( printer_ ); painter.end();}
C++ (Qt)private Q_SLOTS:void printDocument( QPrinter *printer_ );
#ifndef MAINAREA_H#define MAINAREA_H#include <QtGui/QScrollArea>#include <QMouseEvent>#include <QCursor>#include <vector>#include <QPrintPreviewDialog>#include <QPainter>#include <QPrinter>#include <QColor>#include <QMessageBox>#include <QFile>#include <QFileDialog>#include <QIODevice>#include <QByteArray>#include <QHBoxLayout>#include "abstractMainArea.h"#include "area.h"#include "textarea.h"#include "imagearea.h"#include "vector_line.h"using namespace std;enum AbsractNextAction {CURSOR = 0, TEXT = 1, IMG = 2};class mainArea : public abstractMainArea{ // all elements stored here vector<Area*> element; vector<vectorLine*> line; void deleteArea(int id); bool mouseDown; QPoint mouseGotDown, mouseNow;public: void printPreview(); void deleteSelectedAreas(); AbsractNextAction nextAction; mainArea(QWidget* parent=0); void mousePressEvent ( QMouseEvent * e ); void mouseReleaseEvent ( QMouseEvent * e ); void mouseMoveEvent ( QMouseEvent * e ); void paintEvent(QPaintEvent *e); void unselectAll(int eid); void selectAll(); char * Store(); // Genetate text info about elements void addText(int X=0, int Y=0, const QString & data = ""); void addImage(int X=0, int Y=0, const QString & data = ""); void addLine();private slots: void printDocument( QPrinter *printer_ );};#endif // MAINAREA_H
#ifndef MAINAREA_H#define MAINAREA_H#include <QtGui/QScrollArea>#include <QMouseEvent>#include <QCursor>#include <vector>#include <QPrintPreviewDialog>#include <QPainter>#include <QPrinter>#include <QColor>#include <QMessageBox>#include <QFile>#include <QFileDialog>#include <QIODevice>#include <QByteArray>#include <QHBoxLayout>#include "abstractMainArea.h"#include "area.h"#include "textarea.h"#include "imagearea.h"#include "vector_line.h"using namespace std;enum AbsractNextAction {CURSOR = 0, TEXT = 1, IMG = 2};class mainArea : public abstractMainArea{ Q_OBJECT // all elements stored here vector<Area*> element; vector<vectorLine*> line; void deleteArea(int id); bool mouseDown; QPoint mouseGotDown, mouseNow;public: void printPreview(); void deleteSelectedAreas(); AbsractNextAction nextAction; mainArea(QWidget* parent=0); void mousePressEvent ( QMouseEvent * e ); void mouseReleaseEvent ( QMouseEvent * e ); void mouseMoveEvent ( QMouseEvent * e ); void paintEvent(QPaintEvent *e); void unselectAll(int eid); void selectAll(); char * Store(); // Genetate text info about elements void addText(int X=0, int Y=0, const QString & data = ""); void addImage(int X=0, int Y=0, const QString & data = ""); void addLine();private slots: void printDocument( QPrinter *printer_ );};#endif // MAINAREA_H