00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KDREPORTSREPORT_H
00024 #define KDREPORTSREPORT_H
00025
00026 #include "KDReportsErrorDetails.h"
00027 #include "KDReportsGlobal.h"
00028 #include <QtCore/QSizeF>
00029 #include <QtGui/QPrinter>
00030 #include <QtGui/QColor>
00031 #include <QtGui/QFont>
00032 #include <QtGui/QTextOption>
00033
00034 class QDomDocument;
00035 class QTextDocumentFragment;
00036 class QTextDocument;
00037 class QDomElement;
00038 class QDomNode;
00039 class QAbstractItemModel;
00040 class QIODevice;
00041 class QRect;
00042 class QPainter;
00043 namespace KDReports {
00044
00045 class MainTable;
00046 class XmlParser;
00047 class Element;
00048 class HeaderReportBuilder;
00049 class Header;
00050 typedef Header Footer;
00051 class ReportPrivate;
00052 class ReportBuilder;
00053 class PreviewDialog;
00054 class TextDocument;
00055 class TableBreakingSettingsDialog;
00056 class AutoTableElement;
00057 class XmlElementHandler;
00058
00082 enum HeaderLocation {
00083 FirstPage = 1,
00084 EvenPages = 2,
00085 OddPages = 4,
00086 LastPage = 8,
00087 AllPages = OddPages | EvenPages
00088 };
00089 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
00090
00091
00100 class KDREPORTS_EXPORT Report : public QObject
00101 {
00102 Q_OBJECT
00103
00104 public:
00109 Report( QObject* parent = 0 );
00113 ~Report();
00114
00115 enum ReportMode {
00116 WordProcessing = 0,
00117 SpreadSheet = 1
00118 };
00119
00139 void setReportMode( ReportMode reportMode );
00140
00145 ReportMode reportMode() const;
00146
00151 void setDefaultFont( const QFont& font );
00152
00156 MainTable* mainTable() const;
00157
00165 void addInlineElement( const Element& element );
00166
00181 void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft,
00182 const QColor& backgroundColor = QColor() );
00183
00189 void addVerticalSpacing( qreal space );
00190
00197 void addFragment( const QTextDocumentFragment& fragment );
00198
00210 void addPageBreak();
00211
00233 void setTabPositions( const QList<QTextOption::Tab>& tabs );
00234
00240 QTextOption::Tab rightAlignedTab() const;
00241
00248 QTextOption::Tab middleAlignedTab() const;
00249
00255 void setParagraphMargins( qreal left, qreal top, qreal right, qreal bottom );
00256
00262 void setPageSize( const QPrinter::PageSize& size );
00263
00268 void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit );
00269
00273 QPrinter::PageSize pageSize() const;
00277 void setOrientation( QPrinter::Orientation orientation );
00281 QPrinter::Orientation orientation() const;
00282
00296 void setWidthForEndlessPrinter( qreal widthMM );
00297
00301 void setMargins( qreal top, qreal left, qreal bottom, qreal right );
00302
00307 void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const;
00308
00314 void setHeaderBodySpacing( qreal spacing );
00315
00321 void setFooterBodySpacing( qreal spacing );
00322
00339 Header& header( HeaderLocations hl = AllPages );
00340
00348 Footer& footer( HeaderLocations hl = AllPages );
00349
00356 void associateModel( const QString& modelKey, QAbstractItemModel* model );
00357
00369 void associateTextValue( const QString& id, const QString& value );
00370
00381 void associateImageValue( const QString& id, const QPixmap& value );
00382
00396 void associateImageValue( const QString& id, const QImage& value );
00397
00408 bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 );
00409
00422 bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 );
00423
00432 void setXmlElementHandler( KDReports::XmlElementHandler* handler );
00433
00440 void setCurrentRow( const QAbstractItemModel *model, int row );
00441
00447 bool printWithDialog( QWidget* parent );
00448
00461 bool print( QPrinter* printer, QWidget* parent = 0 );
00462
00469 bool exportToFile( const QString& fileName, QWidget* parent = 0 );
00470
00477 bool exportToImage( const QSize& size, const QString& fileName, const char* format );
00478
00486 bool exportToHtml( const QString& fileName );
00487
00493 void paintPage( int pageNumber, QPainter& painter );
00494
00498 int numberOfPages() const;
00499
00523 void setTableBreakingEnabled( bool tableBreakingEnabled );
00524
00529 bool isTableBreakingEnabled() const;
00530
00531 enum TableBreakingPageOrder { DownThenRight, RightThenDown };
00532
00540 void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
00541
00546 TableBreakingPageOrder tableBreakingPageOrder() const;
00547
00557 void setFontScalingFactor( qreal factor );
00558
00563 qreal fontScalingFactor() const;
00564
00587 void scaleTo( int numPagesHorizontally, int numPagesVertically );
00588
00593 int maximumNumberOfPagesForHorizontalScaling() const;
00598 int maximumNumberOfPagesForVerticalScaling() const;
00599
00608 QList<KDReports::AutoTableElement *> autoTableElements() const;
00609
00615 void regenerateAutoTables();
00616
00622 void regenerateAutoTableForModel( QAbstractItemModel* model );
00623
00633 void setWatermarkText( const QString& text,
00634 int rotation = 0,
00635 const QColor& color = QColor( 204, 204, 204 ),
00636 const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
00637
00641 QString watermarkText() const;
00642
00646 int watermarkRotation() const;
00647
00651 QColor watermarkColor() const;
00652
00656 QFont watermarkFont() const;
00657
00668 void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
00669
00675 QPixmap watermarkPixmap() const;
00676
00681 void setWatermarkImage( const QImage& image );
00682
00687 QImage watermarkImage() const;
00688
00692 QSizeF paperSize() const;
00693
00697 void dump() const;
00698
00699 private:
00700 friend class Test;
00701 KDReports::TextDocument& doc() const;
00702
00703 QString asHtml() const;
00704
00705 private:
00706 Q_DISABLE_COPY( Report )
00707 friend class HeaderReportBuilder;
00708 friend class ImageElement;
00709 friend class ChartElement;
00710 friend class XmlParser;
00711 friend class Header;
00712 ReportPrivate* const d;
00713 };
00714
00715 }
00716
00717 #endif