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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/****************************************************************************
**
** Implementation of TQt3CairoPaintDevice class
**
** Copyright (C) 2012 Timothy Pearson. All rights reserved.
**
** This file is part of the TDE Qt4 style interface
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#include "tqtcairopainter.h"
#define TQT_NO_COMPAT_NAMES
#include "tqpainter.h"
#include "tqpixmap.h"
#include "tqbitmap.h"
#include "tqimage.h"
#include "tqfile.h"
#include "tqpaintdevicemetrics.h"
#undef Qt
/*!
\class TQt3CairoPaintDevice tdeqt4painter.h
\brief The TQt3CairoPaintDevice class is a paint device that translates
Qt paint events to a TQt painter.
\ingroup graphics
\ingroup shared
*/
/*!
Constructs TQt3CairoPaintDevice on an existing QPainter
*/
TQt3CairoPaintDevice::TQt3CairoPaintDevice( cairo_surface_t *cairosurface )
: TQPaintDevice( TQInternal::Picture | TQInternal::ExternalDevice )
{
m_surface = cairosurface;
m_painter = cairo_create(m_surface);
}
/*!
Destroys the TQt3CairoPaintDevice.
*/
TQt3CairoPaintDevice::~TQt3CairoPaintDevice()
{
cairo_destroy(m_painter);
}
/*!
\internal
Implementation of the function forwarded above to the internal data struct.
*/
bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
{
Q_UNUSED(pt);
unsigned int i;
int x;
int y;
int index;
int count;
int lineCount;
switch ( c ) { // exec cmd
case PdcNOP:
break;
#if 0
case PdcDrawPoint:
m_qt4painter->drawPoint( qt4point1 );
break;
case PdcMoveTo:
curPt = qt4point1;
break;
case PdcLineTo:
prevPt = curPt;
curPt = qt4point1;
m_qt4painter->drawLine( prevPt, curPt );
break;
case PdcDrawLine:
m_qt4painter->drawLine( qt4point1, qt4point2 );
break;
case PdcDrawRect:
m_qt4painter->drawRect( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter) );
break;
case PdcDrawRoundRect:
m_qt4painter->drawRoundedRect( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival );
break;
case PdcDrawEllipse:
m_qt4painter->drawEllipse( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter) );
break;
case PdcDrawArc:
m_qt4painter->drawArc( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival );
break;
case PdcDrawPie:
m_qt4painter->drawPie( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival );
break;
case PdcDrawChord:
m_qt4painter->drawChord( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival );
break;
case PdcDrawLineSegments:
index = 0;
count = -1;
lineCount = (count == -1) ? (qt4polygon.size() - index) / 2 : count;
m_qt4painter->drawLines(qt4polygon.constData() + index * 2, lineCount);
break;
case PdcDrawPolyline:
m_qt4painter->drawPolyline( qt4polygon );
break;
case PdcDrawPolygon:
m_qt4painter->drawPolygon( qt4polygon, (p[1].ival == 0)?Qt::OddEvenFill:Qt::WindingFill );
break;
case PdcDrawCubicBezier:
index = 0;
path.moveTo(qt4polygon.at(index));
path.cubicTo(qt4polygon.at(index+1), qt4polygon.at(index+2), qt4polygon.at(index+3));
m_qt4painter->strokePath(path, m_qt4painter->pen());
break;
case PdcDrawText:
m_qt4painter->drawText( qt4point1, qt4string );
break;
case PdcDrawTextFormatted:
m_qt4painter->drawText( qt4rect, qt4formattedtextflags, qt4string );
break;
case PdcDrawText2:
m_qt4painter->drawText( qt4point1, qt4string );
break;
case PdcDrawText2Formatted:
m_qt4painter->drawText( qt4rect, qt4formattedtextflags, qt4string );
break;
case PdcDrawPixmap:
m_qt4painter->drawPixmap( qt4rect, qt4pixmap );
break;
#if 0
case PdcDrawImage: {
TQImage image;
if ( d->formatMajor < 4 ) {
s >> p >> image;
painter->drawImage( p, image );
} else {
s >> r >> image;
painter->drawImage( r, image );
}
}
break;
#endif
case PdcBegin:
if (m_qt4painter->isActive()) {
// KEEP THIS DEACTIVATED
// QPaintDevice* pd = m_qt4painter->device();
// m_qt4painter->end();
// m_qt4painter->begin(pd);
}
#if defined(QT_CHECK_RANGE)
else {
tqWarning( "TQt3CairoPaintDevice::cmd: Painter has no paint device available" );
}
#endif
break;
case PdcEnd:
// KEEP THIS DEACTIVATED
// m_qt4painter->end();
break;
case PdcSave:
m_qt4painter->save();
break;
case PdcRestore:
m_qt4painter->restore();
break;
case PdcSetBkColor:
m_qt4painter->setBackground( QBrush(QColor(p[0].color->red(), p[0].color->green(), p[0].color->blue())) );
break;
case PdcSetBkMode:
m_qt4painter->setBackgroundMode( qt4bkmode );
break;
case PdcSetROP:
m_qt4painter->setCompositionMode(qt4compositionmode);
break;
case PdcSetBrushOrigin:
m_qt4painter->setBrushOrigin( qt4point1 );
break;
case PdcSetFont:
m_qt4painter->setFont( qt4font );
break;
case PdcSetPen:
m_qt4painter->setPen( qt4pen );
break;
case PdcSetBrush:
m_qt4painter->setBrush( qt4brush );
break;
#if 0
case PdcSetTabStops:
s >> i_16;
painter->setTabStops( i_16 );
break;
case PdcSetTabArray:
s >> i_16;
if ( i_16 == 0 ) {
painter->setTabArray( 0 );
} else {
int *ta = new int[i_16];
TQ_CHECK_PTR( ta );
for ( int i=0; i<i_16; i++ ) {
s >> i1_16;
ta[i] = i1_16;
}
painter->setTabArray( ta );
delete [] ta;
}
break;
case PdcSetVXform:
s >> i_8;
#ifndef QT_NO_TRANSFORMATIONS
painter->setViewXForm( i_8 );
#endif
break;
case PdcSetWindow:
s >> r;
#ifndef QT_NO_TRANSFORMATIONS
painter->setWindow( r );
#endif
break;
case PdcSetViewport:
s >> r;
#ifndef QT_NO_TRANSFORMATIONS
painter->setViewport( r );
#endif
break;
#endif
case PdcSetWXform:
m_qt4painter->setWorldMatrixEnabled( p[0].ival );
break;
case PdcSetWMatrix:
m_qt4painter->setWorldMatrix( qt4matrix, p[1].ival );
break;
#if 0
#ifndef QT_NO_TRANSFORMATIONS
case PdcSaveWMatrix:
painter->saveWorldMatrix();
break;
case PdcRestoreWMatrix:
painter->restoreWorldMatrix();
break;
#endif
#endif
case PdcSetClip:
m_qt4painter->setClipping( p[0].ival );
break;
case PdcSetClipRegion:
m_qt4painter->setClipRegion( qt4region, Qt::ReplaceClip );
break;
#endif
default:
#if defined(QT_CHECK_RANGE)
tqWarning( "TQt3CairoPaintDevice::cmd: Invalid command %d", c );
#endif
}
return TRUE;
}
/*!
Internal implementation of the virtual TQPaintDevice::metric()
function.
Use the TQPaintDeviceMetrics class instead.
A picture has the following hard-coded values: dpi=72,
numcolors=16777216 and depth=24.
\a m is the metric to get.
*/
int TQt3CairoPaintDevice::metric( int m ) const
{
int val;
if (m_surface) {
double x_pixels_per_inch;
double y_pixels_per_inch;
cairo_format_t format;
switch ( m ) {
// ### hard coded dpi and color depth values !
case TQPaintDeviceMetrics::PdmWidth:
val = cairo_image_surface_get_width(m_surface);
break;
case TQPaintDeviceMetrics::PdmHeight:
val = cairo_image_surface_get_height(m_surface);
break;
case TQPaintDeviceMetrics::PdmWidthMM:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = ((cairo_image_surface_get_width(m_surface)/x_pixels_per_inch)*25.4);
break;
case TQPaintDeviceMetrics::PdmHeightMM:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = ((cairo_image_surface_get_height(m_surface)/y_pixels_per_inch)*25.4);
break;
case TQPaintDeviceMetrics::PdmDpiX:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = x_pixels_per_inch;
break;
case TQPaintDeviceMetrics::PdmPhysicalDpiX:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = x_pixels_per_inch;
break;
case TQPaintDeviceMetrics::PdmDpiY:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = y_pixels_per_inch;
break;
case TQPaintDeviceMetrics::PdmPhysicalDpiY:
cairo_surface_get_fallback_resolution(m_surface, &x_pixels_per_inch, &y_pixels_per_inch);
val = y_pixels_per_inch;
break;
case TQPaintDeviceMetrics::PdmNumColors:
format = cairo_image_surface_get_format(m_surface);
if (format == CAIRO_FORMAT_ARGB32) {
val = INT_MAX;
}
else if (format == CAIRO_FORMAT_RGB24) {
val = 16777216;
}
else {
val = 16777216;
}
break;
case TQPaintDeviceMetrics::PdmDepth:
format = cairo_image_surface_get_format(m_surface);
if (format == CAIRO_FORMAT_ARGB32) {
val = 32;
}
else if (format == CAIRO_FORMAT_RGB24) {
val = 24;
}
else {
val = 24;
}
break;
default:
val = 0;
#if defined(QT_CHECK_RANGE)
tqWarning( "TQt3CairoPaintDevice::metric: Invalid metric command" );
#endif
}
}
else {
val = 0;
#if defined(QT_CHECK_RANGE)
tqWarning( "TQt3CairoPaintDevice::metric: No Cairo surface available" );
#endif
}
return val;
}
|