Changeset View
Changeset View
Standalone View
Standalone View
src/part/simpleprintingengine.cpp
Show All 20 Lines | 19 | /* This file was part of the KDE project | |||
---|---|---|---|---|---|
21 | 21 | | |||
22 | This program is free software; you can redistribute it and/or | 22 | This program is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU Library General Public | 23 | modify it under the terms of the GNU Library General Public | ||
24 | License as published by the Free Software Foundation; either | 24 | License as published by the Free Software Foundation; either | ||
25 | version 2 of the License, or (at your option) any later version. | 25 | version 2 of the License, or (at your option) any later version. | ||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | #include "simpleprintingengine.h" | 28 | #include "simpleprintingengine.h" | ||
29 | #include "simpleprintingsettings.h" | | |||
30 | #include "kgraphviewerlib_debug.h" | 29 | #include "kgraphviewerlib_debug.h" | ||
30 | #include "simpleprintingsettings.h" | ||||
31 | 31 | | |||
32 | #include <QApplication> | 32 | #include <QApplication> | ||
33 | #include <QIcon> | | |||
34 | #include <QFontDialog> | | |||
35 | #include <kurllabel.h> | | |||
36 | #include <QDebug> | 33 | #include <QDebug> | ||
34 | #include <QFontDialog> | ||||
35 | #include <QIcon> | ||||
37 | #include <kconfig.h> | 36 | #include <kconfig.h> | ||
37 | #include <kurllabel.h> | ||||
38 | 38 | | |||
39 | #include <qcheckbox.h> | ||||
39 | #include <qimage.h> | 40 | #include <qimage.h> | ||
40 | #include <qlabel.h> | 41 | #include <qlabel.h> | ||
41 | #include <qlayout.h> | 42 | #include <qlayout.h> | ||
42 | #include <qpainter.h> | 43 | #include <qpainter.h> | ||
43 | #include <qcheckbox.h> | | |||
44 | 44 | | |||
45 | #include <QPixmap> | | |||
46 | #include <QDateTime> | 45 | #include <QDateTime> | ||
47 | #include <QGraphicsScene> | 46 | #include <QGraphicsScene> | ||
48 | #include <QPaintDevice> | 47 | #include <QPaintDevice> | ||
48 | #include <QPixmap> | ||||
49 | #include <klocalizedstring.h> | 49 | #include <klocalizedstring.h> | ||
50 | #include <math.h> | 50 | #include <math.h> | ||
51 | 51 | | |||
52 | namespace KGraphViewer | 52 | namespace KGraphViewer { | ||
53 | { | | |||
54 | KGVSimplePrintingEngine::KGVSimplePrintingEngine( | 53 | KGVSimplePrintingEngine::KGVSimplePrintingEngine( | ||
55 | KGVSimplePrintingSettings* settings, | 54 | KGVSimplePrintingSettings *settings, QObject *parent) | ||
56 | QObject* parent) : | 55 | : QObject(parent), m_settings(settings), m_data(nullptr) { | ||
57 | QObject(parent), m_settings(settings), | | |||
58 | m_data(nullptr) | | |||
59 | { | | |||
60 | setObjectName("KGVSimplePrintingEngine"); | 56 | setObjectName("KGVSimplePrintingEngine"); | ||
61 | clear(); | 57 | clear(); | ||
62 | } | 58 | } | ||
63 | 59 | | |||
64 | KGVSimplePrintingEngine::~KGVSimplePrintingEngine() | 60 | KGVSimplePrintingEngine::~KGVSimplePrintingEngine() { done(); } | ||
65 | { | | |||
66 | done(); | | |||
67 | } | | |||
68 | 61 | | |||
69 | bool KGVSimplePrintingEngine::init(DotGraphView& data, const QString& titleText, QString& errorMessage) | 62 | bool KGVSimplePrintingEngine::init(DotGraphView &data, const QString &titleText, | ||
70 | { | 63 | QString &errorMessage) { | ||
71 | errorMessage.clear(); | 64 | errorMessage.clear(); | ||
72 | done(); | 65 | done(); | ||
73 | m_headerText = titleText; | 66 | m_headerText = titleText; | ||
74 | 67 | | |||
75 | m_data = &data; | 68 | m_data = &data; | ||
76 | m_eof = false; | 69 | m_eof = false; | ||
77 | 70 | | |||
78 | m_painting = QPixmap(m_data->scene()->sceneRect().size().toSize()); | 71 | m_painting = QPixmap(m_data->scene()->sceneRect().size().toSize()); | ||
79 | QPainter p(&m_painting); | 72 | QPainter p(&m_painting); | ||
80 | m_data->scene()->render( &p ); | 73 | m_data->scene()->render(&p); | ||
81 | 74 | | |||
82 | return true; | 75 | return true; | ||
83 | } | 76 | } | ||
84 | 77 | | |||
85 | bool KGVSimplePrintingEngine::done() | 78 | bool KGVSimplePrintingEngine::done() { | ||
86 | { | | |||
87 | bool result = true; | 79 | bool result = true; | ||
88 | m_data = nullptr; | 80 | m_data = nullptr; | ||
89 | m_pagesCount = 0; | 81 | m_pagesCount = 0; | ||
90 | m_paintInitialized = false; | 82 | m_paintInitialized = false; | ||
91 | return result; | 83 | return result; | ||
92 | } | 84 | } | ||
93 | 85 | | |||
94 | void KGVSimplePrintingEngine::clear() | 86 | void KGVSimplePrintingEngine::clear() { | ||
95 | { | | |||
96 | m_eof = false; | 87 | m_eof = false; | ||
97 | m_pagesCount = 0; | 88 | m_pagesCount = 0; | ||
98 | m_paintInitialized = false; | 89 | m_paintInitialized = false; | ||
99 | } | 90 | } | ||
100 | 91 | | |||
101 | void KGVSimplePrintingEngine::paintPage(int pageNumber, QPainter& painter, bool paint) | 92 | void KGVSimplePrintingEngine::paintPage(int pageNumber, QPainter &painter, | ||
102 | { | 93 | bool paint) { | ||
103 | qCDebug(KGRAPHVIEWERLIB_LOG) << pageNumber << "/" << m_pagesCount << paint; | 94 | qCDebug(KGRAPHVIEWERLIB_LOG) << pageNumber << "/" << m_pagesCount << paint; | ||
104 | 95 | | |||
105 | uint y = 0; | 96 | uint y = 0; | ||
106 | 97 | | |||
107 | if (pageNumber <= m_pagesCount) | 98 | if (pageNumber <= m_pagesCount) { | ||
108 | { | | |||
109 | m_eof = false; | 99 | m_eof = false; | ||
110 | } | 100 | } | ||
111 | int w = 0, h = 0; | 101 | int w = 0, h = 0; | ||
112 | QPaintDevice *pdm = painter.device(); | 102 | QPaintDevice *pdm = painter.device(); | ||
113 | const bool printer = pdm->devType() == QInternal::Printer; | 103 | const bool printer = pdm->devType() == QInternal::Printer; | ||
114 | qCDebug(KGRAPHVIEWERLIB_LOG) << "printer:"<< printer; | 104 | qCDebug(KGRAPHVIEWERLIB_LOG) << "printer:" << printer; | ||
115 | 105 | | |||
116 | if (!printer) { | 106 | if (!printer) { | ||
117 | w = pdm->width(); | 107 | w = pdm->width(); | ||
118 | h = pdm->height(); | 108 | h = pdm->height(); | ||
119 | } | 109 | } else { // QPrinter... | ||
120 | else {//QPrinter... | | |||
121 | w = pdm->widthMM(); | 110 | w = pdm->widthMM(); | ||
122 | h = pdm->heightMM(); | 111 | h = pdm->heightMM(); | ||
123 | } | 112 | } | ||
124 | 113 | | |||
125 | if (!m_paintInitialized) | 114 | if (!m_paintInitialized) { | ||
126 | { | | |||
127 | qCDebug(KGRAPHVIEWERLIB_LOG) << "initializing"; | 115 | qCDebug(KGRAPHVIEWERLIB_LOG) << "initializing"; | ||
128 | // HACK: some functions here do not work properly if were | 116 | // HACK: some functions here do not work properly if were | ||
129 | // are not in a paint event, so repeat this until we actually paint. | 117 | // are not in a paint event, so repeat this until we actually paint. | ||
130 | m_paintInitialized = paint; | 118 | m_paintInitialized = paint; | ||
131 | 119 | | |||
132 | double widthMM = KgvPageFormat::width( | 120 | double widthMM = KgvPageFormat::width( | ||
133 | m_settings->pageLayout.format, m_settings->pageLayout.orientation); | 121 | m_settings->pageLayout.format, m_settings->pageLayout.orientation); | ||
134 | double heightMM = KgvPageFormat::height( | 122 | double heightMM = KgvPageFormat::height( | ||
135 | m_settings->pageLayout.format, m_settings->pageLayout.orientation); | 123 | m_settings->pageLayout.format, m_settings->pageLayout.orientation); | ||
136 | 124 | | |||
137 | m_dpiY = pdm->logicalDpiY(); | 125 | m_dpiY = pdm->logicalDpiY(); | ||
138 | m_dpiX = pdm->logicalDpiX(); | 126 | m_dpiX = pdm->logicalDpiX(); | ||
139 | #ifdef Q_WS_WIN //fix for 120dpi | 127 | #ifdef Q_WS_WIN // fix for 120dpi | ||
140 | if (!printer) | 128 | if (!printer) { | ||
141 | { | | |||
142 | // m_dpiY = 96; | 129 | // m_dpiY = 96; | ||
143 | // m_dpiX = 96; | 130 | // m_dpiX = 96; | ||
144 | m_dpiY = 86; | 131 | m_dpiY = 86; | ||
145 | m_dpiX = 86; | 132 | m_dpiX = 86; | ||
146 | } | 133 | } | ||
147 | #endif | 134 | #endif | ||
148 | int pdWidthMM = pdm->widthMM(); | 135 | int pdWidthMM = pdm->widthMM(); | ||
149 | int pdHeightMM = pdm->heightMM(); | 136 | int pdHeightMM = pdm->heightMM(); | ||
150 | 137 | | |||
151 | double screenF; | 138 | double screenF; | ||
152 | // if (printer) | 139 | // if (printer) | ||
153 | screenF = 1.0; | 140 | screenF = 1.0; | ||
154 | // else | 141 | // else | ||
155 | // screenF = (double)96.0/120.0; | 142 | // screenF = (double)96.0/120.0; | ||
156 | 143 | | |||
157 | leftMargin = POINT_TO_INCH(m_settings->pageLayout.ptLeft)*m_dpiX* screenF; | 144 | leftMargin = | ||
158 | rightMargin = POINT_TO_INCH(m_settings->pageLayout.ptRight)*m_dpiX* screenF; | 145 | POINT_TO_INCH(m_settings->pageLayout.ptLeft) * m_dpiX * screenF; | ||
159 | topMargin = POINT_TO_INCH(m_settings->pageLayout.ptTop)*m_dpiY* screenF; | 146 | rightMargin = | ||
160 | bottomMargin = POINT_TO_INCH(m_settings->pageLayout.ptBottom)*m_dpiY* screenF; | 147 | POINT_TO_INCH(m_settings->pageLayout.ptRight) * m_dpiX * screenF; | ||
148 | topMargin = | ||||
149 | POINT_TO_INCH(m_settings->pageLayout.ptTop) * m_dpiY * screenF; | ||||
150 | bottomMargin = | ||||
151 | POINT_TO_INCH(m_settings->pageLayout.ptBottom) * m_dpiY * screenF; | ||||
161 | 152 | | |||
162 | m_fx = widthMM / (pdWidthMM * screenF); | 153 | m_fx = widthMM / (pdWidthMM * screenF); | ||
163 | m_fy = heightMM / (pdHeightMM * screenF); | 154 | m_fy = heightMM / (pdHeightMM * screenF); | ||
164 | 155 | | |||
165 | //screen only | 156 | // screen only | ||
166 | // painter.fillRect(QRect(0,0,w,h), QBrush(white)); | 157 | // painter.fillRect(QRect(0,0,w,h), QBrush(white)); | ||
167 | m_pageWidth = int( m_fx*(double)pdm->width() - leftMargin - rightMargin); | 158 | m_pageWidth = | ||
168 | m_pageHeight = int( m_fy*(double)pdm->height() - topMargin - bottomMargin); | 159 | int(m_fx * (double)pdm->width() - leftMargin - rightMargin); | ||
160 | m_pageHeight = | ||||
161 | int(m_fy * (double)pdm->height() - topMargin - bottomMargin); | ||||
169 | 162 | | |||
170 | //! @todo add setting | 163 | //! @todo add setting | ||
171 | m_mainFont = m_settings->pageTitleFont; | 164 | m_mainFont = m_settings->pageTitleFont; | ||
172 | if(!printer) | 165 | if (!printer) { | ||
173 | { | 166 | int pixelSize = | ||
174 | int pixelSize = int( POINT_TO_INCH(m_mainFont.pointSizeF())*m_dpiX ); | 167 | int(POINT_TO_INCH(m_mainFont.pointSizeF()) * m_dpiX); | ||
175 | m_mainFont.setPixelSize(pixelSize); | 168 | m_mainFont.setPixelSize(pixelSize); | ||
176 | } | 169 | } | ||
177 | painter.setFont(m_mainFont); | 170 | painter.setFont(m_mainFont); | ||
178 | 171 | | |||
179 | m_dateTimeText = QLocale().toString(QDateTime::currentDateTime()); | 172 | m_dateTimeText = QLocale().toString(QDateTime::currentDateTime()); | ||
180 | m_dateTimeWidth = 0; | 173 | m_dateTimeWidth = 0; | ||
181 | if (m_settings->addDateAndTime) | 174 | if (m_settings->addDateAndTime) { | ||
182 | { | 175 | m_dateTimeWidth = | ||
183 | m_dateTimeWidth = painter.boundingRect(leftMargin, topMargin, m_pageWidth, m_pageHeight, Qt::AlignRight, m_dateTimeText+" ").width(); | 176 | painter | ||
177 | .boundingRect(leftMargin, topMargin, m_pageWidth, | ||||
178 | m_pageHeight, Qt::AlignRight, | ||||
179 | m_dateTimeText + " ") | ||||
180 | .width(); | ||||
184 | } | 181 | } | ||
185 | m_mainLineSpacing = painter.fontMetrics().lineSpacing(); | 182 | m_mainLineSpacing = painter.fontMetrics().lineSpacing(); | ||
186 | m_headerTextRect = painter.boundingRect( | 183 | m_headerTextRect = painter.boundingRect( | ||
187 | (int)leftMargin, (int)topMargin, | 184 | (int)leftMargin, (int)topMargin, m_pageWidth - m_dateTimeWidth, | ||
188 | m_pageWidth - m_dateTimeWidth, | | |||
189 | m_pageHeight, Qt::AlignLeft|Qt::TextWordWrap, m_headerText); | 185 | m_pageHeight, Qt::AlignLeft | Qt::TextWordWrap, m_headerText); | ||
190 | m_headerTextRect.setRight(m_headerTextRect.right()+10); | 186 | m_headerTextRect.setRight(m_headerTextRect.right() + 10); | ||
191 | m_headerTextRect.setWidth( | 187 | m_headerTextRect.setWidth( | ||
192 | qMin(int(m_pageWidth - m_dateTimeWidth), m_headerTextRect.width())); | 188 | qMin(int(m_pageWidth - m_dateTimeWidth), m_headerTextRect.width())); | ||
193 | } | 189 | } | ||
194 | qCDebug(KGRAPHVIEWERLIB_LOG) << "after initialization"; | 190 | qCDebug(KGRAPHVIEWERLIB_LOG) << "after initialization"; | ||
195 | 191 | | |||
196 | //screen only | 192 | // screen only | ||
197 | if(!printer) | 193 | if (!printer) { | ||
198 | { | | |||
199 | painter.setWindow(0, 0, int((double)w*m_fx), int((double)h*m_fy)); | 194 | painter.setWindow(0, 0, int((double)w * m_fx), int((double)h * m_fy)); | ||
200 | } | 195 | } | ||
201 | 196 | | |||
202 | painter.setFont(m_mainFont); | 197 | painter.setFont(m_mainFont); | ||
203 | if (paint) | 198 | if (paint) { | ||
204 | { | | |||
205 | //paint header | 199 | // paint header | ||
206 | painter.drawText(m_headerTextRect, Qt::AlignLeft|Qt::TextWordWrap, m_headerText); | 200 | painter.drawText(m_headerTextRect, Qt::AlignLeft | Qt::TextWordWrap, | ||
207 | if (m_settings->addDateAndTime) | 201 | m_headerText); | ||
208 | { | 202 | if (m_settings->addDateAndTime) { | ||
209 | painter.drawText( | 203 | painter.drawText((int)leftMargin + m_pageWidth - m_dateTimeWidth, | ||
210 | (int)leftMargin + m_pageWidth - m_dateTimeWidth, (int)topMargin, | 204 | (int)topMargin, m_dateTimeWidth, | ||
211 | m_dateTimeWidth, m_headerTextRect.height(), | 205 | m_headerTextRect.height(), Qt::AlignRight, | ||
212 | Qt::AlignRight, m_dateTimeText); | 206 | m_dateTimeText); | ||
213 | } | 207 | } | ||
214 | 208 | | |||
215 | //footer | 209 | // footer | ||
216 | if (m_settings->addPageNumbers) | 210 | if (m_settings->addPageNumbers) { | ||
217 | { | | |||
218 | QString pageNumString; | 211 | QString pageNumString; | ||
219 | if (m_pagesCount>0) | 212 | if (m_pagesCount > 0) { | ||
220 | { | 213 | pageNumString = | ||
221 | pageNumString = i18nc("Page (number) of (total)", "Page %1 of %2",pageNumber+1,m_pagesCount); | 214 | i18nc("Page (number) of (total)", "Page %1 of %2", | ||
222 | } | 215 | pageNumber + 1, m_pagesCount); | ||
223 | else | 216 | } else { | ||
224 | { | | |||
225 | pageNumString = i18n("Page %1",pageNumber+1); | 217 | pageNumString = i18n("Page %1", pageNumber + 1); | ||
226 | } | 218 | } | ||
227 | painter.drawText((int)leftMargin, | 219 | painter.drawText((int)leftMargin, | ||
228 | (int)topMargin + m_pageHeight - m_mainLineSpacing, | 220 | (int)topMargin + m_pageHeight - m_mainLineSpacing, | ||
229 | m_pageWidth, m_mainLineSpacing, | 221 | m_pageWidth, m_mainLineSpacing, | ||
230 | Qt::AlignRight | Qt::AlignBottom, pageNumString); | 222 | Qt::AlignRight | Qt::AlignBottom, pageNumString); | ||
231 | } | 223 | } | ||
232 | } | 224 | } | ||
233 | 225 | | |||
234 | w = m_pageWidth; | 226 | w = m_pageWidth; | ||
235 | h = m_pageHeight; | 227 | h = m_pageHeight; | ||
236 | y = (int)topMargin ; | 228 | y = (int)topMargin; | ||
237 | h -= (m_headerTextRect.height() + 1); | 229 | h -= (m_headerTextRect.height() + 1); | ||
238 | y += (m_headerTextRect.height() ); | 230 | y += (m_headerTextRect.height()); | ||
239 | if (m_settings->addTableBorders) | 231 | if (m_settings->addTableBorders) { | ||
240 | { | 232 | w -= 2; | ||
241 | w -= 2; h -= 2; | 233 | h -= 2; | ||
242 | } | 234 | } | ||
243 | if (m_settings->addPageNumbers) | 235 | if (m_settings->addPageNumbers) { | ||
244 | { | | |||
245 | h -= (m_mainLineSpacing*3/2 + 1); | 236 | h -= (m_mainLineSpacing * 3 / 2 + 1); | ||
246 | } | 237 | } | ||
247 | 238 | | |||
248 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(w, h) = (" << w << ", " << h <<")"; | 239 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(w, h) = (" << w << ", " << h << ")"; | ||
249 | if ( ( (m_settings->fitToOnePage) || | 240 | if (((m_settings->fitToOnePage) || | ||
250 | (m_painting.width()<=w && m_painting.height()<=h) ) | 241 | (m_painting.width() <= w && m_painting.height() <= h)) && | ||
251 | && !m_eof) | 242 | !m_eof) { | ||
252 | { | | |||
253 | qCDebug(KGRAPHVIEWERLIB_LOG) << "single-page printing"; | 243 | qCDebug(KGRAPHVIEWERLIB_LOG) << "single-page printing"; | ||
254 | if (paint) | 244 | if (paint) { | ||
255 | { | 245 | QPixmap pix = m_painting.scaled(w, h, Qt::KeepAspectRatio, | ||
256 | QPixmap pix = m_painting.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation); | 246 | Qt::SmoothTransformation); | ||
257 | qCDebug(KGRAPHVIEWERLIB_LOG) << "drawPixmap"; | 247 | qCDebug(KGRAPHVIEWERLIB_LOG) << "drawPixmap"; | ||
258 | painter.drawPixmap((int)leftMargin, y, pix); | 248 | painter.drawPixmap((int)leftMargin, y, pix); | ||
259 | } | 249 | } | ||
260 | m_eof = true; | 250 | m_eof = true; | ||
261 | } | 251 | } else if (m_settings->horizFitting != 0 || m_settings->vertFitting != 0) { | ||
262 | else if (m_settings->horizFitting != 0 || m_settings->vertFitting != 0) | 252 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
263 | { | 253 | << "fitted multi-pages printing page " << pageNumber; | ||
264 | qCDebug(KGRAPHVIEWERLIB_LOG) << "fitted multi-pages printing page " << pageNumber; | | |||
265 | int nbTilesByRow = (int)(ceil((double)m_painting.width())/w) + 1; | 254 | int nbTilesByRow = (int)(ceil((double)m_painting.width()) / w) + 1; | ||
266 | qCDebug(KGRAPHVIEWERLIB_LOG) << " nb tiles by row = " << nbTilesByRow; | 255 | qCDebug(KGRAPHVIEWERLIB_LOG) << " nb tiles by row = " << nbTilesByRow; | ||
267 | 256 | | |||
268 | int tileWidth = w; | 257 | int tileWidth = w; | ||
269 | int tileHeight = h; | 258 | int tileHeight = h; | ||
270 | 259 | | |||
271 | if (m_settings->horizFitting != 0) | 260 | if (m_settings->horizFitting != 0) { | ||
272 | { | 261 | tileWidth = int( | ||
273 | tileWidth = int(ceil(((double)m_painting.width())/m_settings->horizFitting)); | 262 | ceil(((double)m_painting.width()) / m_settings->horizFitting)); | ||
274 | nbTilesByRow = m_settings->horizFitting; | 263 | nbTilesByRow = m_settings->horizFitting; | ||
275 | } | 264 | } | ||
276 | if (m_settings->vertFitting != 0) | 265 | if (m_settings->vertFitting != 0) { | ||
277 | { | 266 | tileHeight = int( | ||
278 | tileHeight = int(ceil(((double)m_painting.height())/m_settings->vertFitting)); | 267 | ceil(((double)m_painting.height()) / m_settings->vertFitting)); | ||
279 | } | 268 | } | ||
280 | qCDebug(KGRAPHVIEWERLIB_LOG) << " tile size = "<<tileWidth<<"/"<<tileHeight; | 269 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
270 | << " tile size = " << tileWidth << "/" << tileHeight; | ||||
281 | int rowNum = pageNumber / nbTilesByRow; | 271 | int rowNum = pageNumber / nbTilesByRow; | ||
282 | int columnNum = pageNumber % nbTilesByRow; | 272 | int columnNum = pageNumber % nbTilesByRow; | ||
283 | int x1, y1, x2, y2; | 273 | int x1, y1, x2, y2; | ||
284 | x1 = int(tileWidth * columnNum); | 274 | x1 = int(tileWidth * columnNum); | ||
285 | x2 = int(tileWidth * (columnNum+1)); | 275 | x2 = int(tileWidth * (columnNum + 1)); | ||
286 | y1 = int(tileHeight * rowNum); | 276 | y1 = int(tileHeight * rowNum); | ||
287 | y2 = int(tileHeight * (rowNum+1)); | 277 | y2 = int(tileHeight * (rowNum + 1)); | ||
288 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(x1, y1, x2, 2) = ("<<x1<<","<<y1<<","<<x2<<","<<y2<<")"; | 278 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(x1, y1, x2, 2) = (" << x1 << "," << y1 | ||
289 | qCDebug(KGRAPHVIEWERLIB_LOG) << "painting size = ("<<m_painting.width()<<"/"<<m_painting.height()<<")"; | 279 | << "," << x2 << "," << y2 << ")"; | ||
290 | if (paint) | 280 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
291 | { | 281 | << "painting size = (" << m_painting.width() << "/" | ||
282 | << m_painting.height() << ")"; | ||||
283 | if (paint) { | ||||
292 | Qt::AspectRatioMode scaleMode = Qt::IgnoreAspectRatio; | 284 | Qt::AspectRatioMode scaleMode = Qt::IgnoreAspectRatio; | ||
293 | if (m_settings->chainedFittings) | 285 | if (m_settings->chainedFittings) { | ||
294 | { | | |||
295 | scaleMode = Qt::KeepAspectRatio; | 286 | scaleMode = Qt::KeepAspectRatio; | ||
296 | } | 287 | } | ||
297 | QPixmap pix = m_painting.copy(x1, y1, x2-x1+1, y2-y1+1); | 288 | QPixmap pix = m_painting.copy(x1, y1, x2 - x1 + 1, y2 - y1 + 1); | ||
298 | if (m_settings->horizFitting == 0) | 289 | if (m_settings->horizFitting == 0) { | ||
299 | { | 290 | pix = pix.scaled(pix.width(), h, scaleMode, | ||
300 | pix = pix.scaled(pix.width(), h, scaleMode, Qt::SmoothTransformation); | 291 | Qt::SmoothTransformation); | ||
301 | } | 292 | } else if (m_settings->vertFitting == 0) { | ||
302 | else if (m_settings->vertFitting == 0) | 293 | pix = pix.scaled(w, pix.height(), scaleMode, | ||
303 | { | 294 | Qt::SmoothTransformation); | ||
304 | pix = pix.scaled(w, pix.height(), scaleMode, Qt::SmoothTransformation); | 295 | } else { | ||
305 | } | | |||
306 | else | | |||
307 | { | | |||
308 | pix = pix.scaled(w, h, scaleMode, Qt::SmoothTransformation); | 296 | pix = pix.scaled(w, h, scaleMode, Qt::SmoothTransformation); | ||
309 | } | 297 | } | ||
310 | painter.drawPixmap((int)leftMargin, y, pix); | 298 | painter.drawPixmap((int)leftMargin, y, pix); | ||
311 | } | 299 | } | ||
312 | if ( x2 >= m_painting.width() && y2 >= m_painting.height() ) | 300 | if (x2 >= m_painting.width() && y2 >= m_painting.height()) { | ||
313 | { | | |||
314 | m_eof = true; | 301 | m_eof = true; | ||
315 | } | 302 | } | ||
316 | } | 303 | } else { | ||
317 | else | 304 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
318 | { | 305 | << "multi-pages printing page " << pageNumber; | ||
319 | qCDebug(KGRAPHVIEWERLIB_LOG) << "multi-pages printing page " << pageNumber; | | |||
320 | int nbTilesByRow = (int)(((double)m_painting.width())/w) + 1; | 306 | int nbTilesByRow = (int)(((double)m_painting.width()) / w) + 1; | ||
321 | int rowNum = pageNumber / nbTilesByRow; | 307 | int rowNum = pageNumber / nbTilesByRow; | ||
322 | int columnNum = pageNumber % nbTilesByRow; | 308 | int columnNum = pageNumber % nbTilesByRow; | ||
323 | int x1, y1, x2, y2; | 309 | int x1, y1, x2, y2; | ||
324 | x1 = int(w * columnNum); | 310 | x1 = int(w * columnNum); | ||
325 | x2 = int(w * (columnNum+1)); | 311 | x2 = int(w * (columnNum + 1)); | ||
326 | y1 = int(h * rowNum); | 312 | y1 = int(h * rowNum); | ||
327 | y2 = int(h * (rowNum+1)); | 313 | y2 = int(h * (rowNum + 1)); | ||
328 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(x1, y1, x2, 2) = ("<<x1<<","<<y1<<","<<x2<<","<<y2<<")"; | 314 | qCDebug(KGRAPHVIEWERLIB_LOG) << "(x1, y1, x2, 2) = (" << x1 << "," << y1 | ||
329 | if (paint) | 315 | << "," << x2 << "," << y2 << ")"; | ||
330 | { | 316 | if (paint) { | ||
331 | painter.drawPixmap((int)leftMargin, y, m_painting.copy(x1, y1, x2-x1+1, y2-y1+1)); | 317 | painter.drawPixmap( | ||
318 | (int)leftMargin, y, | ||||
319 | m_painting.copy(x1, y1, x2 - x1 + 1, y2 - y1 + 1)); | ||||
332 | } | 320 | } | ||
333 | if ( x2 >= m_painting.width() && y2 >= m_painting.height() ) | 321 | if (x2 >= m_painting.width() && y2 >= m_painting.height()) { | ||
334 | { | | |||
335 | m_eof = true; | 322 | m_eof = true; | ||
336 | } | 323 | } | ||
337 | } | 324 | } | ||
338 | 325 | | |||
339 | if (m_settings->addTableBorders) | 326 | if (m_settings->addTableBorders) { | ||
340 | { | | |||
341 | qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding table borders"; | 327 | qCDebug(KGRAPHVIEWERLIB_LOG) << "Adding table borders"; | ||
342 | int y1 = (int)topMargin ; | 328 | int y1 = (int)topMargin; | ||
343 | y1 += (m_headerTextRect.height()); | 329 | y1 += (m_headerTextRect.height()); | ||
344 | int y2 = (int)topMargin + m_pageHeight; | 330 | int y2 = (int)topMargin + m_pageHeight; | ||
345 | if (m_settings->addPageNumbers) | 331 | if (m_settings->addPageNumbers) { | ||
346 | { | | |||
347 | y2 -= (m_headerTextRect.height() /*+ m_mainLineSpacing*3/2*/ + 1); | 332 | y2 -= (m_headerTextRect.height() /*+ m_mainLineSpacing*3/2*/ + 1); | ||
348 | } | 333 | } | ||
349 | if (paint) | 334 | if (paint) { | ||
350 | { | 335 | painter.drawLine((int)leftMargin, y1, | ||
351 | painter.drawLine((int)leftMargin, y1, (int)leftMargin + m_pageWidth-1, y1); | 336 | (int)leftMargin + m_pageWidth - 1, y1); | ||
352 | painter.drawLine((int)leftMargin + m_pageWidth-1, y1, (int)leftMargin + m_pageWidth-1, y2); | 337 | painter.drawLine((int)leftMargin + m_pageWidth - 1, y1, | ||
353 | painter.drawLine((int)leftMargin + m_pageWidth-1, y2, (int)leftMargin, y2); | 338 | (int)leftMargin + m_pageWidth - 1, y2); | ||
339 | painter.drawLine((int)leftMargin + m_pageWidth - 1, y2, | ||||
340 | (int)leftMargin, y2); | ||||
354 | painter.drawLine((int)leftMargin, y2, (int)leftMargin, y1); | 341 | painter.drawLine((int)leftMargin, y2, (int)leftMargin, y1); | ||
355 | } | 342 | } | ||
356 | } | 343 | } | ||
357 | qCDebug(KGRAPHVIEWERLIB_LOG) << "paintPage done"; | 344 | qCDebug(KGRAPHVIEWERLIB_LOG) << "paintPage done"; | ||
358 | } | 345 | } | ||
359 | 346 | | |||
360 | void KGVSimplePrintingEngine::calculatePagesCount(QPainter& painter) | 347 | void KGVSimplePrintingEngine::calculatePagesCount(QPainter &painter) { | ||
361 | { | | |||
362 | if (m_eof || !m_data) { | 348 | if (m_eof || !m_data) { | ||
363 | m_pagesCount = 0; | 349 | m_pagesCount = 0; | ||
364 | return; | 350 | return; | ||
365 | } | 351 | } | ||
366 | 352 | | |||
367 | uint pageNumber = 0; | 353 | uint pageNumber = 0; | ||
368 | if (m_settings->fitToOnePage) | 354 | if (m_settings->fitToOnePage) { | ||
369 | { | | |||
370 | m_pagesCount = 1; | 355 | m_pagesCount = 1; | ||
371 | } | 356 | } else { | ||
372 | else | | |||
373 | { | | |||
374 | for(;!m_eof; ++pageNumber) { | 357 | for (; !m_eof; ++pageNumber) { | ||
375 | paintPage(pageNumber, painter, false /* !paint */); | 358 | paintPage(pageNumber, painter, false /* !paint */); | ||
376 | } | 359 | } | ||
377 | m_pagesCount = pageNumber; | 360 | m_pagesCount = pageNumber; | ||
378 | } | 361 | } | ||
379 | } | 362 | } | ||
380 | 363 | | |||
381 | void KGVSimplePrintingEngine::setTitleText(const QString& titleText) | 364 | void KGVSimplePrintingEngine::setTitleText(const QString &titleText) { | ||
382 | { | | |||
383 | m_headerText = titleText; | 365 | m_headerText = titleText; | ||
384 | } | 366 | } | ||
385 | 367 | | |||
386 | uint KGVSimplePrintingEngine::maxHorizFit() const | 368 | uint KGVSimplePrintingEngine::maxHorizFit() const { | ||
387 | { | | |||
388 | uint w = m_pageWidth; | 369 | uint w = m_pageWidth; | ||
389 | if (m_settings->addTableBorders) | 370 | if (m_settings->addTableBorders) { | ||
390 | { | | |||
391 | w -= 2; | 371 | w -= 2; | ||
392 | } | 372 | } | ||
393 | // () << "maxHorizFit: " << m_painting.width() << " / " << w | 373 | // () << "maxHorizFit: " << m_painting.width() << " / " << w | ||
394 | // << " = " << m_painting.width()/w; | 374 | // << " = " << m_painting.width()/w; | ||
395 | return (uint)ceil(((double)m_painting.width())/w) + 1; | 375 | return (uint)ceil(((double)m_painting.width()) / w) + 1; | ||
396 | } | 376 | } | ||
397 | 377 | | |||
398 | uint KGVSimplePrintingEngine::maxVertFit() const | 378 | uint KGVSimplePrintingEngine::maxVertFit() const { | ||
399 | { | | |||
400 | uint h = m_pageHeight; | 379 | uint h = m_pageHeight; | ||
401 | h -= (m_headerTextRect.height() + 1); | 380 | h -= (m_headerTextRect.height() + 1); | ||
402 | if (m_settings->addTableBorders) | 381 | if (m_settings->addTableBorders) { | ||
403 | { | | |||
404 | h -= 2; | 382 | h -= 2; | ||
405 | } | 383 | } | ||
406 | if (m_settings->addPageNumbers) | 384 | if (m_settings->addPageNumbers) { | ||
407 | { | | |||
408 | h -= (m_mainLineSpacing*3/2 + 1); | 385 | h -= (m_mainLineSpacing * 3 / 2 + 1); | ||
409 | } | 386 | } | ||
410 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "maxVertFit: " << m_painting.height() << " / " << h | 387 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "maxVertFit: " << m_painting.height() | ||
388 | // << " / " << h | ||||
411 | // << " = " << m_painting.height()/h; | 389 | // << " = " << m_painting.height()/h; | ||
412 | return (uint)ceil(((double)m_painting.height()))/h + 1; | 390 | return (uint)ceil(((double)m_painting.height())) / h + 1; | ||
413 | } | 391 | } | ||
414 | 392 | | |||
415 | } | 393 | } // namespace KGraphViewer |