00001 #ifndef KDREPORTSREPORT_H
00002 #define KDREPORTSREPORT_H
00003
00004 #include "KDReportsErrorDetails.h"
00005 #include "KDReportsGlobal.h"
00006 #include <QtCore/QSizeF>
00007 #include <QtGui/QPrinter>
00008 #include <QtGui/QColor>
00009 #include <QtGui/QFont>
00010 #include <QtGui/QTextOption>
00011
00012 class QDomDocument;
00013 class QTextDocumentFragment;
00014 class QTextDocument;
00015 class QDomElement;
00016 class QDomNode;
00017 class QAbstractItemModel;
00018 class QIODevice;
00019 class QRect;
00020 class QPainter;
00021 namespace KDReports {
00022
00023 class XmlParser;
00024 class Element;
00025 class HeaderReportBuilder;
00026 class Header;
00027 typedef Header Footer;
00028 class ReportPrivate;
00029 class ReportBuilder;
00030 class PreviewDialog;
00031 class TextDocument;
00032 class TableBreakingSettingsDialog;
00033 class AutoTableElement;
00034 class XmlElementHandler;
00035
00058 enum HeaderLocation {
00059 FirstPage = 1,
00060 EvenPages = 2,
00061 OddPages = 4,
00062 LastPage = 8,
00063 AllPages = OddPages | EvenPages
00064 };
00065 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
00066
00067
00076 class KDREPORTS_EXPORT Report : public QObject
00077 {
00078 Q_OBJECT
00079
00080 public:
00085 Report( QObject* parent = 0 );
00089 ~Report();
00090
00095 void setDefaultFont( const QFont& font );
00096
00104 void addInlineElement( const Element& element );
00105
00120 void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft,
00121 const QColor& backgroundColor = QColor() );
00122
00128 void addVerticalSpacing( qreal space );
00129
00136 void addFragment( const QTextDocumentFragment& fragment );
00137
00146 void addPageBreak();
00147
00171 #if QT_VERSION >= 0x040400
00172 void setTabPositions( const QList<QTextOption::Tab>& tabs );
00173 #endif
00174
00180 void setPageSize( const QPrinter::PageSize& size );
00181
00182 #if QT_VERSION >= 0x040400
00183
00187 void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit );
00188 #endif
00189
00193 QPrinter::PageSize pageSize() const;
00197 void setOrientation( QPrinter::Orientation orientation );
00201 QPrinter::Orientation orientation() const;
00202
00216 void setWidthForEndlessPrinter( qreal widthMM );
00217
00221 void setMargins( qreal top, qreal left, qreal bottom, qreal right );
00222
00227 void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const;
00228
00234 void setHeaderBodySpacing( qreal spacing );
00235
00241 void setFooterBodySpacing( qreal spacing );
00242
00259 Header& header( HeaderLocations hl = AllPages );
00260
00268 Footer& footer( HeaderLocations hl = AllPages );
00269
00276 void associateModel( const QString& modelKey, QAbstractItemModel* model );
00277
00289 void associateTextValue( const QString& id, const QString& value );
00290
00301 void associateImageValue( const QString& id, const QPixmap& value );
00302
00313 bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 );
00314
00327 bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 );
00328
00337 void setXmlElementHandler( KDReports::XmlElementHandler* handler );
00338
00344 bool printWithDialog( QWidget* parent );
00345
00357 bool print( QPrinter* printer, QWidget* parent = 0 );
00358
00365 bool exportToFile( const QString& fileName, QWidget* parent = 0 );
00366
00373 bool exportToImage( const QSize& size, const QString& fileName, const char* format );
00374
00382 bool exportToHtml( const QString& fileName );
00383
00389 void paintPage( int pageNumber, QPainter& painter );
00390
00394 int numberOfPages() const;
00395
00417 void setTableBreakingEnabled( bool tableBreakingEnabled );
00418
00423 bool isTableBreakingEnabled() const;
00424
00425 enum TableBreakingPageOrder { DownThenRight, RightThenDown };
00426
00441 void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
00442
00447 TableBreakingPageOrder tableBreakingPageOrder() const;
00448
00458 void setFontScalingFactor( qreal factor );
00459
00464 qreal fontScalingFactor() const;
00465
00488 void scaleTo( int numPagesHorizontally, int numPagesVertically );
00489
00494 int maximumNumberOfPagesForHorizontalScaling() const;
00499 int maximumNumberOfPagesForVerticalScaling() const;
00500
00507 QList<KDReports::AutoTableElement *> autoTableElements() const;
00508
00515 void regenerateAutoTables();
00516
00522 void regenerateAutoTableForModel( QAbstractItemModel* model );
00523
00533 void setWatermarkText( const QString& text,
00534 int rotation = 0,
00535 const QColor& color = QColor( 204, 204, 204 ),
00536 const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
00537
00541 QString watermarkText() const;
00542
00546 int watermarkRotation() const;
00547
00551 QColor watermarkColor() const;
00552
00556 QFont watermarkFont() const;
00557
00568 void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
00569
00575 QPixmap watermarkPixmap() const;
00576
00581 void setWatermarkImage( const QImage& image );
00582
00587 QImage watermarkImage() const;
00588
00592 QSizeF paperSize() const;
00593
00597 void dump() const;
00598
00599 private:
00600 friend class Test;
00601 KDReports::TextDocument& doc() const;
00602
00603 QString asHtml() const;
00604
00605 private:
00606 Q_DISABLE_COPY( Report )
00607 friend class HeaderReportBuilder;
00608 friend class ImageElement;
00609 friend class ChartElement;
00610 friend class XmlParser;
00611 friend class Header;
00612 ReportPrivate* const d;
00613 };
00614
00615 }
00616
00617 #endif