diff options
Diffstat (limited to 'lib/tdeqt4painter.cpp')
-rw-r--r-- | lib/tdeqt4painter.cpp | 196 |
1 files changed, 108 insertions, 88 deletions
diff --git a/lib/tdeqt4painter.cpp b/lib/tdeqt4painter.cpp index 6c8d4c0..072c4d8 100644 --- a/lib/tdeqt4painter.cpp +++ b/lib/tdeqt4painter.cpp @@ -30,85 +30,46 @@ #undef Qt /*! - \class TDEQt4PaintDevice ntqpicture.h - \brief The TDEQt4PaintDevice class is a paint device that records and - replays TQPainter commands. + \class TDEQt4PaintDevice tdeqt4painter.h + \brief The TDEQt4PaintDevice class is a paint device that translates + Qt paint events to a TQt painter. \ingroup graphics - \ingroup images \ingroup shared - A picture serializes painter commands to an IO device in a - platform-independent format. For example, a picture created under - Windows can be read on a Sun SPARC. - - Pictures are called meta-files on some platforms. - - TQt pictures use a proprietary binary format. Unlike native picture - (meta-file) formats on many window systems, TQt pictures have no - limitations regarding their contents. Everything that can be - painted can also be stored in a picture, e.g. fonts, pixmaps, - regions, transformed graphics, etc. - - TDEQt4PaintDevice is an \link shclass.html implicitly shared\endlink class. - - Example of how to record a picture: - \code - TDEQt4PaintDevice pic; - TQPainter p; - p.begin( &pic ); // paint in picture - p.drawEllipse( 10,20, 80,70 ); // draw an ellipse - p.end(); // painting done - pic.save( "drawing.pic" ); // save picture - \endcode - - Example of how to replay a picture: - \code - TDEQt4PaintDevice pic; - pic.load( "drawing.pic" ); // load picture - TQPainter p; - p.begin( &myWidget ); // paint in myWidget - p.drawPicture( pic ); // draw the picture - p.end(); // painting done - \endcode - - Pictures can also be drawn using play(). Some basic data about a - picture is available, for example, size(), isNull() and - boundingRect(). - */ +inline int qt4PainterRectSubtraction(QPainter* pd) { + QPen pen = pd->pen(); + return pen.style() != Qt::NoPen && pen.width() == 0 ? 1 : 0; +} -/*! - Constructs an empty picture. - - The \a formatVersion parameter may be used to \e create a TDEQt4PaintDevice - that can be read by applications that are compiled with earlier - versions of TQt. - \list - \i \a formatVersion == 1 is binary compatible with TQt 1.x and later. - \i \a formatVersion == 2 is binary compatible with TQt 2.0.x and later. - \i \a formatVersion == 3 is binary compatible with TQt 2.1.x and later. - \i \a formatVersion == 4 is binary compatible with TQt 3.0.x and later. - \i \a formatVersion == 5 is binary compatible with TQt 3.1. - \endlist - - Note that the default formatVersion is -1 which signifies the - current release, i.e. for TQt 3.1 a formatVersion of 5 is the same - as the default formatVersion of -1. +inline QRect qt4PainterAdjustedRectangle(const QRect &r, QPainter* pd) +{ + QRect rect = r.normalized(); + int subtract = qt4PainterRectSubtraction(pd); + if (subtract != 0) { + rect.setSize(QSize(rect.width() - subtract, rect.height() - subtract)); + } + return rect; +} - Reading pictures generated by earlier versions of TQt is supported - and needs no special coding; the format is automatically detected. +/*! + Constructs TDEQt4PaintDevice on an existing QPainter */ TDEQt4PaintDevice::TDEQt4PaintDevice( QPainter *qt4painter ) : TQPaintDevice( TQInternal::Picture | TQInternal::ExternalDevice ) { m_qt4painter = qt4painter; + m_qt4OrigClipping = m_qt4painter->hasClipping(); + m_qt4OrigClipRegion = m_qt4painter->clipRegion(); + m_qt4OrigWorldTransformEnabled = m_qt4painter->worldMatrixEnabled(); + m_qt4OrigWorldTransform = m_qt4painter->worldTransform(); } /*! - Destroys the picture. + Destroys the TDEQt4PaintDevice. */ TDEQt4PaintDevice::~TDEQt4PaintDevice() { @@ -153,24 +114,27 @@ bool TDEQt4PaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) TQRect r = rects[(int)i]; qt4region = qt4region.united(QRegion(QRect(r.x(), r.y(), r.width(), r.height()))); } + { #else // SLOW TQRect tqt3br = p[0].rgn->boundingRect(); - TQBitmap regionMask(tqt3br.x()+tqt3br.width(), tqt3br.y()+tqt3br.height()); - regionMask.fill(TQt::color0); - TQPainter tqt3brpainter(®ionMask); - tqt3brpainter.setClipRegion(*p[0].rgn); - tqt3brpainter.fillRect(0,0,regionMask.width(),regionMask.height(),TQt::color1); - tqt3brpainter.end(); - QBitmap qt4RegionMask = QPixmap::fromX11Pixmap(regionMask.handle(), QPixmap::ImplicitlyShared); - qt4region = QRegion(qt4RegionMask); + if (!tqt3br.isNull()) { + TQBitmap regionMask(tqt3br.x()+tqt3br.width(), tqt3br.y()+tqt3br.height()); + regionMask.fill(TQt::color0); + TQPainter tqt3brpainter(®ionMask); + tqt3brpainter.setClipRegion(*p[0].rgn); + tqt3brpainter.fillRect(0,0,regionMask.width(),regionMask.height(),TQt::color1); + tqt3brpainter.end(); + QBitmap qt4RegionMask = QPixmap::fromX11Pixmap(regionMask.handle(), QPixmap::ImplicitlyShared); + qt4region = QRegion(qt4RegionMask); #endif - TQPainter::CoordinateMode tqt3coordmode = (TQPainter::CoordinateMode)p[1].ival; - if ( tqt3coordmode == TQPainter::CoordDevice ) { - qt4region = qt4region; - } - else { - qt4region = m_qt4painter->transform().map(qt4region); + TQPainter::CoordinateMode tqt3coordmode = (TQPainter::CoordinateMode)p[1].ival; + if ( tqt3coordmode == TQPainter::CoordDevice ) { + qt4region = qt4region; + } + else { + qt4region = m_qt4painter->transform().map(qt4region); + } } } if (c == PdcSetWMatrix) { @@ -487,11 +451,67 @@ bool TDEQt4PaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) } } if (c == PdcSetFont) { - // FIXME - printf("[WARNING] QFont conversion is NOT COMPLETE\n\r"); fflush(stdout); - TQFont qt3font = *p[0].font; qt4font = QFont(QString::fromUtf8(qt3font.family().utf8().data()), qt3font.pointSize(), qt3font.weight(), qt3font.italic()); + + qt4font.setBold(qt3font.bold()); +// qt4font.setCapitalization ( Capitalization caps ) + qt4font.setFamily(QString::fromUtf8(qt3font.family().utf8().data())); + qt4font.setFixedPitch(qt3font.fixedPitch()); + qt4font.setItalic(qt3font.italic()); +// qt4font.setKerning ( bool enable ) +// qt4font.setLetterSpacing ( SpacingType type, qreal spacing ) + qt4font.setOverline(qt3font.overline()); + int pixelSize = qt3font.pixelSize(); + if (pixelSize < 0) { + float pointSizeFloat = qt3font.pointSizeFloat(); + if (pointSizeFloat < 0) { + qt4font.setPointSize(qt3font.pointSize()); + } + else { + qt4font.setPointSizeF(pointSizeFloat); + } + } + else { + qt4font.setPixelSize(pixelSize); + } +// qt4font.setRawMode ( bool enable ) +// qt4font.setRawName(QString::fromUtf8(qt3font.rawName().utf8().data())); + qt4font.setStretch(qt3font.stretch()); + qt4font.setStrikeOut(qt3font.strikeOut()); +// qt4font.setStyle ( Style style ) + + TQFont::StyleHint qt3fontstylehint = qt3font.styleHint(); + QFont::StyleHint qt4fontstylehint = QFont::AnyStyle; + if (qt3fontstylehint == TQFont::Helvetica) qt4fontstylehint = QFont::Helvetica; + else if (qt3fontstylehint == TQFont::SansSerif) qt4fontstylehint = QFont::SansSerif; + else if (qt3fontstylehint == TQFont::Times) qt4fontstylehint = QFont::Times; + else if (qt3fontstylehint == TQFont::Serif) qt4fontstylehint = QFont::Serif; + else if (qt3fontstylehint == TQFont::Courier) qt4fontstylehint = QFont::Courier; + else if (qt3fontstylehint == TQFont::TypeWriter) qt4fontstylehint = QFont::TypeWriter; + else if (qt3fontstylehint == TQFont::OldEnglish) qt4fontstylehint = QFont::OldEnglish; + else if (qt3fontstylehint == TQFont::Decorative) qt4fontstylehint = QFont::Decorative; + else if (qt3fontstylehint == TQFont::System) qt4fontstylehint = QFont::System; + else if (qt3fontstylehint == TQFont::AnyStyle) qt4fontstylehint = QFont::AnyStyle; + + TQFont::StyleStrategy qt3fontstrategy = qt3font.styleStrategy(); + QFont::StyleStrategy qt4fontstrategy = (QFont::StyleStrategy)0; + if (qt3fontstrategy & TQFont::PreferDefault) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferDefault); + if (qt3fontstrategy & TQFont::PreferBitmap) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferBitmap); + if (qt3fontstrategy & TQFont::PreferDevice) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferDevice); + if (qt3fontstrategy & TQFont::PreferOutline) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferOutline); + if (qt3fontstrategy & TQFont::ForceOutline) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::ForceOutline); + if (qt3fontstrategy & TQFont::PreferMatch) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferMatch); + if (qt3fontstrategy & TQFont::PreferQuality) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferQuality); + if (qt3fontstrategy & TQFont::PreferAntialias) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::PreferAntialias); + if (qt3fontstrategy & TQFont::NoAntialias) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::NoAntialias); + if (qt3fontstrategy & TQFont::OpenGLCompatible) qt4fontstrategy = (QFont::StyleStrategy)(qt4fontstrategy | QFont::OpenGLCompatible); + + qt4font.setStyleHint (qt4fontstylehint, qt4fontstrategy); +// qt4font.setStyleStrategy ( StyleStrategy s ) + qt4font.setUnderline(qt3font.underline()); + qt4font.setWeight(qt3font.weight()); +// qt4font.setWordSpacing ( qreal spacing ) } if (c == PdcDrawPixmap) { qt4rect = QRect(p[0].rect->x(), p[0].rect->y(), p[0].rect->width(), p[0].rect->height()); @@ -527,22 +547,22 @@ bool TDEQt4PaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) m_qt4painter->drawLine( qt4point1, qt4point2 ); break; case PdcDrawRect: - m_qt4painter->drawRect( qt4rect ); + m_qt4painter->drawRect( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter) ); break; case PdcDrawRoundRect: - m_qt4painter->drawRoundedRect( qt4rect, p[1].ival, p[2].ival ); + m_qt4painter->drawRoundedRect( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival ); break; case PdcDrawEllipse: - m_qt4painter->drawEllipse( qt4rect ); + m_qt4painter->drawEllipse( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter) ); break; case PdcDrawArc: - m_qt4painter->drawArc( qt4rect, p[1].ival, p[2].ival ); + m_qt4painter->drawArc( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival ); break; case PdcDrawPie: - m_qt4painter->drawPie( qt4rect, p[1].ival, p[2].ival ); + m_qt4painter->drawPie( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival ); break; case PdcDrawChord: - m_qt4painter->drawChord( qt4rect, p[1].ival, p[2].ival ); + m_qt4painter->drawChord( qt4PainterAdjustedRectangle(qt4rect, m_qt4painter), p[1].ival, p[2].ival ); break; case PdcDrawLineSegments: index = 0; @@ -674,7 +694,7 @@ bool TDEQt4PaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) break; #endif case PdcSetWXform: - m_qt4painter->setWorldMatrixEnabled( p[0].ival ); + m_qt4painter->setWorldMatrixEnabled( (m_qt4OrigWorldTransformEnabled)?true:p[0].ival ); break; case PdcSetWMatrix: m_qt4painter->setWorldMatrix( qt4matrix, p[1].ival ); @@ -690,10 +710,10 @@ bool TDEQt4PaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) #endif #endif case PdcSetClip: - m_qt4painter->setClipping( p[0].ival ); + m_qt4painter->setClipping( (m_qt4OrigClipping)?true:p[0].ival ); break; case PdcSetClipRegion: - m_qt4painter->setClipRegion( qt4region, Qt::ReplaceClip ); + m_qt4painter->setClipRegion( qt4region.intersected(m_qt4OrigClipRegion), Qt::ReplaceClip ); break; default: #if defined(QT_CHECK_RANGE) |