summaryrefslogtreecommitdiffstats
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
parent0bb5952228cc19402d90e0adf8c88c7ae4ddfd60 (diff)
downloadgtk3-tqt-engine-827cba3a.tar.gz
gtk3-tqt-engine-827cba3a.zip
Add initial interface code skeleton for later development
-rw-r--r--configure.ac1
-rw-r--r--tdegtk/Makefile.am7
-rw-r--r--tdegtk/tqtcairopainter.cpp367
-rw-r--r--tdegtk/tqtcairopainter.h45
-rw-r--r--tests/Makefile.am15
-rw-r--r--tests/test-painter.cpp27
6 files changed, 459 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index b6b1471..d8addef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,7 @@ AC_SUBST(PACKAGE_VERSION_NANO)
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AM_PROG_CC_C_O
+AC_PROG_CXX
LT_INIT
AC_C_CONST
AC_C_INLINE
diff --git a/tdegtk/Makefile.am b/tdegtk/Makefile.am
index 7bf792b..cc3eef3 100644
--- a/tdegtk/Makefile.am
+++ b/tdegtk/Makefile.am
@@ -7,7 +7,8 @@ source_h = \
$(srcdir)/tdegtk-draw.h \
$(srcdir)/tdegtk-engine.h \
$(srcdir)/tdegtk-support.h \
- $(srcdir)/tdegtk-types.h
+ $(srcdir)/tdegtk-types.h \
+ $(srcdir)/tqtcairopainter.h
source_c = \
$(srcdir)/exponential-blur.c \
@@ -17,7 +18,8 @@ source_c = \
$(srcdir)/tdegtk-draw.c \
$(srcdir)/tdegtk-engine.c \
$(srcdir)/tdegtk-support.c \
- $(srcdir)/tdegtk-theme.c
+ $(srcdir)/tdegtk-theme.c \
+ $(srcdir)/tqtcairopainter.cpp
enginedir = $(libdir)/gtk-3.0/$(GTK_VERSION)/theming-engines
engine_LTLIBRARIES = libtdegtk.la
@@ -25,6 +27,7 @@ engine_LTLIBRARIES = libtdegtk.la
libtdegtk_la_SOURCES = $(source_h) $(source_c)
libtdegtk_la_CFLAGS = $(TDEGTK_CFLAGS)
+libtdegtk_la_CXXFLAGS = $(TDEGTK_CXXFLAGS) -I/usr/include/tqt -I/usr/include/tqt3 $(TDEGTK_CFLAGS)
libtdegtk_la_LIBADD = $(TDEGTK_LIBADD)
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;
+}
+
diff --git a/tdegtk/tqtcairopainter.h b/tdegtk/tqtcairopainter.h
new file mode 100644
index 0000000..aa45e9b
--- /dev/null
+++ b/tdegtk/tqtcairopainter.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Definition 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.
+**
+**********************************************************************/
+
+#ifndef TDEQT4PAINTER_H
+#define TDEQT4PAINTER_H
+
+#define TQT_NO_COMPAT_NAMES
+#include "ntqpaintdevice.h"
+#include "ntqbuffer.h"
+
+#include <cairo.h>
+
+class Q_EXPORT TQt3CairoPaintDevice : public TQPaintDevice // picture class
+{
+public:
+ TQt3CairoPaintDevice( cairo_surface_t * );
+ ~TQt3CairoPaintDevice();
+
+protected:
+ bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ int metric( int ) const;
+
+private:
+ cairo_surface_t *m_surface;
+ cairo_t *m_painter;
+};
+
+#endif // TDEQT4PAINTER_H
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9bae1df..50880e2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,8 @@ EXTRA_DIST = \
test-widgets.glade
noinst_PROGRAMS = \
- test-widgets
+ test-widgets \
+ test-painter
test_widgets_CFLAGS = \
-I$(top_srcdir) \
@@ -14,4 +15,16 @@ test_widgets_LDADD = \
test_widgets_LDFLAGS = \
$(TDEGTK_LDFLAGS)
+test_painter_SOURCES = test-painter.cpp
+
+test_painter_CXXFLAGS = \
+ -I$(top_srcdir) \
+ $(TDEGTK_CFLAGS)
+
+test_painter_LDADD = \
+ $(TDEGTK_LIBADD)
+
+test_painter_LDFLAGS = \
+ $(TDEGTK_LDFLAGS)
+
# FIXME(Cimi): Figure out what tests must be compiled and add them here.
diff --git a/tests/test-painter.cpp b/tests/test-painter.cpp
new file mode 100644
index 0000000..c8bb77b
--- /dev/null
+++ b/tests/test-painter.cpp
@@ -0,0 +1,27 @@
+#include <cairo.h>
+
+int
+main (int argc, char *argv[])
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 120, 120);
+ cr = cairo_create (surface);
+ /* Examples are in 1.0 x 1.0 coordinate space */
+ cairo_scale (cr, 120, 120);
+
+ /* Drawing code goes here */
+ cairo_set_line_width (cr, 0.1);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_rectangle (cr, 0.25, 0.25, 0.5, 0.5);
+ cairo_stroke (cr);
+
+ /* Write output and clean up */
+ cairo_surface_write_to_png (surface, "stroke.png");
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return 0;
+}
+