summaryrefslogtreecommitdiffstats
path: root/tdegtk/tqtcairopainter.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-15 15:06:40 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-15 15:06:40 -0500
commit827cba3a39a4afe688bfa848fc7dd7c5899b506f (patch)
treed2fdfc1f057a2fa358dc7f418129e4fedf3678cb /tdegtk/tqtcairopainter.cpp
parent0bb5952228cc19402d90e0adf8c88c7ae4ddfd60 (diff)
downloadgtk3-tqt-engine-827cba3a39a4afe688bfa848fc7dd7c5899b506f.tar.gz
gtk3-tqt-engine-827cba3a39a4afe688bfa848fc7dd7c5899b506f.zip
Add initial interface code skeleton for later development
Diffstat (limited to 'tdegtk/tqtcairopainter.cpp')
-rw-r--r--tdegtk/tqtcairopainter.cpp367
1 files changed, 367 insertions, 0 deletions
diff --git a/tdegtk/tqtcairopainter.cpp b/tdegtk/tqtcairopainter.cpp
new file mode 100644
index 0000000..8b38bc7
--- /dev/null
+++ b/tdegtk/tqtcairopainter.cpp
@@ -0,0 +1,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;
+}
+