File indexing completed on 2024-05-19 15:27:52
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 /* This file was part of the KDE project 0020 Copyright (C) 2005 Jarosław Staniek <staniek@kde.org> 0021 0022 This program is free software; you can redistribute it and/or 0023 modify it under the terms of the GNU Library General Public 0024 License as published by the Free Software Foundation; either 0025 version 2 of the License, or (at your option) any later version. 0026 */ 0027 0028 #ifndef KGVSIMPLEPRINTINGENGINE_H 0029 #define KGVSIMPLEPRINTINGENGINE_H 0030 0031 #include "KgvPageLayoutDia.h" 0032 0033 #include <qfont.h> 0034 #include <qfontmetrics.h> 0035 // Added by qt3to4: 0036 #include <QPixmap> 0037 0038 class QPaintDevice; 0039 0040 #include "dotgraphview.h" 0041 0042 namespace KGraphViewer 0043 { 0044 class KGVSimplePrintingSettings; 0045 0046 /*! @short An engine painting data on pages using QPainter. 0047 The engine allows for random access to any page. */ 0048 class KGVSimplePrintingEngine : public QObject 0049 { 0050 Q_OBJECT 0051 0052 public: 0053 KGVSimplePrintingEngine(KGVSimplePrintingSettings *settings, QObject *parent); 0054 ~KGVSimplePrintingEngine(); 0055 0056 bool init(DotGraphView &data, const QString &titleText, QString &errorMessage); 0057 0058 void setTitleText(const QString &titleText); 0059 0060 //! Calculates page count that can be later obtained using pagesCount(). 0061 //! Page count can depend on \a painter (printer/screen) and on printing settings. 0062 void calculatePagesCount(QPainter &painter); 0063 0064 bool done(); 0065 void clear(); 0066 KGVSimplePrintingSettings *settings() 0067 { 0068 return m_settings; 0069 } 0070 0071 //! \return true when all records has been painted 0072 bool eof() const 0073 { 0074 return m_eof; 0075 } 0076 0077 //! \return number of pages. Can be used after calculatePagesCount(). 0078 uint pagesCount() 0079 { 0080 return m_pagesCount; 0081 } 0082 0083 uint maxHorizFit() const; 0084 uint maxVertFit() const; 0085 0086 inline DotGraphView *data() 0087 { 0088 return m_data; 0089 } 0090 0091 public Q_SLOTS: 0092 /*! Paints a page number \a pageNumber (counted from 0) on \a painter. 0093 If \a paint is false, drawings are only computed but not painted, 0094 so this can be used for calculating page number before printing or previewing. */ 0095 void paintPage(int pageNumber, QPainter &painter, bool paint = true); 0096 0097 protected: 0098 KGVSimplePrintingSettings *m_settings; 0099 0100 QFont m_mainFont; 0101 int m_dpiX, m_dpiY; 0102 uint m_pageWidth, m_pageHeight; 0103 // QFontMetrics m_headerFM, m_mainFM; 0104 DotGraphView *m_data; 0105 QString m_headerText; 0106 QString m_dateTimeText; 0107 uint m_dateTimeWidth; 0108 QRect m_headerTextRect; 0109 int m_mainLineSpacing; 0110 uint m_pagesCount; 0111 bool m_eof; 0112 bool m_paintInitialized; //!< used by paintPage() 0113 double leftMargin; 0114 double rightMargin; 0115 double topMargin; 0116 double bottomMargin; 0117 double m_fx, m_fy; 0118 0119 QPixmap m_painting; 0120 }; 0121 0122 } 0123 0124 #endif