1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/* This file is part of the KDE project
Copyright (C) 2005-2007 Jaroslaw Staniek <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KEXISIMPLEPRINTINGENGINE_H
#define KEXISIMPLEPRINTINGENGINE_H
class KexiSimplePrintingSettings;
#include <kexidb/connection.h>
#include <kexidb/tableschema.h>
#include <kexidb/cursor.h>
#include <kexidb/utils.h>
#include <kexidb/queryschema.h>
#include <widget/tableview/kexitableviewdata.h>
#include <KoPageLayoutDia.h>
#include <tqpaintdevicemetrics.h>
#include <tqfontmetrics.h>
#include <tqfont.h>
//! @short Settings data for simple printing engine.
class KexiSimplePrintingSettings
{
public:
KexiSimplePrintingSettings();
~KexiSimplePrintingSettings();
static KexiSimplePrintingSettings load();
void save();
KoPageLayout pageLayout;
KoUnit::Unit unit;
TQFont pageTitleFont;
bool addPageNumbers : 1;
bool addDateAndTime : 1;
bool addTableBorders : 1;
};
/*! @short An engine painting data on pages using TQPainter.
The engine allows for random access to any page. */
class KexiSimplePrintingEngine : public TQObject
{
Q_OBJECT
public:
KexiSimplePrintingEngine( const KexiSimplePrintingSettings& settings, TQObject* parent );
~KexiSimplePrintingEngine();
bool init(KexiDB::Connection& conn, KexiDB::TableOrQuerySchema& tableOrQuery,
const TQString& titleText, TQString& errorMessage);
void setTitleText(const TQString& titleText);
//! Calculates pafe count that can be later obtained using pagesCount().
//! Page count can depend on \a painter (printer/screen) and on printing settings.
void calculatePagesCount(TQPainter& painter);
bool done();
void clear();
const KexiSimplePrintingSettings* settings() const { return m_settings; }
//! \return true when all records has been painted
bool eof() const { return m_eof; }
//! \return number of pages. Can be used after calculatePagesCount().
uint pagesCount() const { return m_pagesCount; }
//! \return number of painted pages so far.
//! If eof() is true, this number is equal to total page count.
uint paintedPages() const { return m_dataOffsets.count(); }
public slots:
/*! Paints a page number \a pageNumber (counted from 0) on \a painter.
If \a paint is false, drawings are only computed but not painted,
so this can be used for calculating page number before printing or previewing. */
void paintPage(int pageNumber, TQPainter& painter, bool paint = true);
protected:
void paintRecord(TQPainter& painter, KexiTableItem *item,
int cellMargin, double &y, uint paintedRows, bool paint, bool printing);
const KexiSimplePrintingSettings* m_settings;
// TQPainter* m_painter;
TQFont m_mainFont, m_headerFont;
TQPaintDeviceMetrics m_pdm;
double m_dpiX, m_dpiY;
uint m_pageWidth, m_pageHeight;
uint m_SCALE;
//TQFontMetrics m_headerFM, m_mainFM;
KexiDB::Cursor *m_cursor;
KexiTableViewData *m_data;
// KexiTableViewData::Iterator *m_dataIterator;
TQPtrList<uint> m_dataOffsets;
TQString m_headerText;
TQString m_dateTimeText;
uint m_dateTimeWidth;
TQRect m_headerTextRect;
int m_maxFieldNameWidth;
int m_mainLineSpacing;
int m_footerHeight;
KexiDB::QueryColumnInfo::Vector m_fieldsExpanded;
uint m_visibleFieldsCount;
uint m_pagesCount;
bool m_eof;
bool m_paintInitialized; //!< used by paintPage()
double m_leftMargin;
double m_rightMargin;
double m_topMargin;
double m_bottomMargin;
double m_fx, m_fy;
};
#endif
|