You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
285 lines
6.3 KiB
285 lines
6.3 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001, The Karbon Developers
|
||
|
Copyright (C) 2002, The Karbon Developers
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
// qpainter wrapper
|
||
|
|
||
|
#include "vqpainter.h"
|
||
|
#include "vstroke.h"
|
||
|
#include "vcolor.h"
|
||
|
#include "vfill.h"
|
||
|
|
||
14 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqpaintdevice.h>
|
||
|
#include <tqpen.h>
|
||
15 years ago
|
|
||
|
#include <KoPoint.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
14 years ago
|
VTQPainter::VTQPainter( TQPaintDevice *target, unsigned int w, unsigned int h ) : VPainter( target, w, h ), m_painter( 0L ), m_target( target ), m_width( w ), m_height( h )
|
||
15 years ago
|
{
|
||
|
m_zoomFactor = 1;
|
||
|
m_index = 0;
|
||
14 years ago
|
m_painter = new TQPainter( target );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
VTQPainter::~VTQPainter()
|
||
15 years ago
|
{
|
||
|
delete m_painter;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::resize( unsigned int w, unsigned int h )
|
||
15 years ago
|
{
|
||
|
m_width = w;
|
||
|
m_height = h;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::blit( const KoRect & )
|
||
15 years ago
|
{
|
||
|
end();
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::clear( const TQColor &c )
|
||
15 years ago
|
{
|
||
|
m_painter->setBackgroundColor( c );
|
||
|
m_painter->eraseRect( 0, 0, m_width, m_height );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::begin()
|
||
15 years ago
|
{
|
||
|
if( !m_painter->isActive() )
|
||
|
{
|
||
|
m_painter->begin( m_target );
|
||
|
m_painter->eraseRect( 0, 0, m_width, m_height );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::end()
|
||
15 years ago
|
{
|
||
|
m_painter->end();
|
||
|
}
|
||
|
|
||
14 years ago
|
const TQWMatrix
|
||
13 years ago
|
VTQPainter::worldMatrix()
|
||
15 years ago
|
{
|
||
13 years ago
|
return m_painter->worldMatrix();
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setWorldMatrix( const TQWMatrix& mat )
|
||
15 years ago
|
{
|
||
|
m_painter->setWorldMatrix( mat );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setZoomFactor( double zoomFactor )
|
||
15 years ago
|
{
|
||
|
m_zoomFactor = zoomFactor;
|
||
14 years ago
|
/*TQWMatrix mat;
|
||
15 years ago
|
mat.scale( zoomFactor, zoomFactor );
|
||
|
m_painter->setWorldMatrix( mat );*/
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::moveTo( const KoPoint &p )
|
||
15 years ago
|
{
|
||
|
//m_index = 0;
|
||
|
if( m_pa.size() <= m_index )
|
||
|
m_pa.resize( m_index + 10 );
|
||
|
|
||
|
m_pa.setPoint( m_index, static_cast<int>(p.x() * m_zoomFactor), static_cast<int>(p.y() * m_zoomFactor) );
|
||
|
|
||
|
m_index++;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::lineTo( const KoPoint &p )
|
||
15 years ago
|
{
|
||
|
if( m_pa.size() <= m_index )
|
||
|
m_pa.resize( m_index + 10 );
|
||
|
|
||
|
m_pa.setPoint( m_index, static_cast<int>(p.x() * m_zoomFactor), static_cast<int>(p.y() * m_zoomFactor) );
|
||
|
|
||
|
m_index++;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::curveTo( const KoPoint &p1, const KoPoint &p2, const KoPoint &p3 )
|
||
15 years ago
|
{
|
||
14 years ago
|
// calculate cubic bezier using a temp TQPointArray
|
||
|
TQPointArray pa( 4 );
|
||
15 years ago
|
pa.setPoint( 0, m_pa.point( m_index - 1 ).x(), m_pa.point( m_index - 1 ).y() );
|
||
|
pa.setPoint( 1, static_cast<int>(p1.x() * m_zoomFactor), static_cast<int>(p1.y() * m_zoomFactor) );
|
||
|
pa.setPoint( 2, static_cast<int>(p2.x() * m_zoomFactor), static_cast<int>(p2.y() * m_zoomFactor) );
|
||
|
pa.setPoint( 3, static_cast<int>(p3.x() * m_zoomFactor), static_cast<int>(p3.y() * m_zoomFactor) );
|
||
|
|
||
14 years ago
|
TQPointArray pa2( pa.cubicBezier() );
|
||
15 years ago
|
|
||
|
m_pa.resize( m_index + pa2.size() );
|
||
|
m_pa.putPoints( m_index, pa2.size(), pa2 );
|
||
|
|
||
|
m_index += pa2.size();
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::newPath()
|
||
15 years ago
|
{
|
||
|
m_index = 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::fillPath()
|
||
15 years ago
|
{
|
||
|
// we probably dont need filling for qpainter
|
||
|
//m_index = 0;
|
||
13 years ago
|
m_painter->drawPolygon( m_pa, FALSE, 0, m_index );
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::strokePath()
|
||
15 years ago
|
{
|
||
13 years ago
|
m_painter->drawPolyline( m_pa, 0, m_index );
|
||
15 years ago
|
m_index = 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setPen( const VStroke &stroke )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQPen pen;
|
||
15 years ago
|
|
||
|
// color + linewidth
|
||
|
pen.setColor( stroke.color() );
|
||
|
pen.setWidth( static_cast<int>(stroke.lineWidth()) );
|
||
|
|
||
|
// caps
|
||
|
if( stroke.lineCap() == VStroke::capButt )
|
||
|
pen.setCapStyle( Qt::FlatCap );
|
||
|
else if( stroke.lineCap() == VStroke::capRound )
|
||
|
pen.setCapStyle( Qt::RoundCap );
|
||
|
else if( stroke.lineCap() == VStroke::capSquare )
|
||
|
pen.setCapStyle( Qt::SquareCap );
|
||
|
|
||
|
m_painter->setPen( pen );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setBrush( const VFill &fill )
|
||
15 years ago
|
{
|
||
|
switch( fill.type() )
|
||
|
{
|
||
|
case VFill::none:
|
||
14 years ago
|
m_painter->setBrush( TQt::NoBrush );
|
||
15 years ago
|
break;
|
||
|
case VFill::solid:
|
||
14 years ago
|
m_painter->setBrush( TQBrush( fill.color(), TQt::SolidPattern ) );
|
||
15 years ago
|
break;
|
||
|
case VFill::grad:
|
||
|
// gradients are nor supported by qpainter
|
||
14 years ago
|
m_painter->setBrush( TQt::NoBrush );
|
||
15 years ago
|
break;
|
||
|
case VFill::patt:
|
||
|
// pixmap brushes not supported for printing
|
||
14 years ago
|
m_painter->setBrush( TQBrush( fill.color(), fill.pattern().pixmap() ) );
|
||
15 years ago
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setPen( const TQColor &c )
|
||
15 years ago
|
{
|
||
|
m_painter->setPen( c );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setPen( Qt::PenStyle style )
|
||
15 years ago
|
{
|
||
|
m_painter->setPen( style );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setBrush( const TQColor &c )
|
||
15 years ago
|
{
|
||
|
m_painter->setBrush( c );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setBrush( TQt::BrushStyle style )
|
||
15 years ago
|
{
|
||
|
m_painter->setBrush( style );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::save()
|
||
15 years ago
|
{
|
||
|
m_painter->save();
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::restore()
|
||
15 years ago
|
{
|
||
|
m_painter->restore();
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::setRasterOp( TQt::RasterOp r )
|
||
15 years ago
|
{
|
||
|
m_painter->setRasterOp( r );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::drawNode( const KoPoint &p, int width )
|
||
15 years ago
|
{
|
||
14 years ago
|
m_painter->drawRect( TQRect( int( p.x() * m_zoomFactor ) - width, int( p.y() * m_zoomFactor ) - width,
|
||
15 years ago
|
2 * width + 1, 2 * width + 1 ) );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::drawRect( const KoRect &rect )
|
||
15 years ago
|
{
|
||
14 years ago
|
m_painter->drawRect( TQRect( int( rect.x() ), int( rect.y() ), int( rect.width() ), int( rect.height() ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VTQPainter::drawImage( const TQImage &image, const TQWMatrix &affine )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQWMatrix matrix = m_painter->worldMatrix();
|
||
15 years ago
|
|
||
|
double m11 = affine.m11() * matrix.m11() * m_zoomFactor + affine.m12() * matrix.m21();
|
||
|
double m12 = (affine.m11() * matrix.m12() + affine.m12() * matrix.m22() ) * m_zoomFactor;
|
||
|
double m21 = (affine.m21() * matrix.m11() + affine.m22() * matrix.m21() ) * m_zoomFactor;
|
||
|
double m22 = affine.m22() * matrix.m22() * m_zoomFactor + affine.m21() * matrix.m12();
|
||
|
double dx = matrix.dx() + affine.dx() * m_zoomFactor;
|
||
|
double dy = matrix.dy() - affine.dy() * m_zoomFactor;
|
||
|
|
||
14 years ago
|
TQWMatrix world( m11, m12, m21, m22, dx, dy );
|
||
15 years ago
|
|
||
|
m_painter->setWorldMatrix( world );
|
||
|
|
||
14 years ago
|
m_painter->drawImage( TQPoint( 0, 0 ), image );
|
||
15 years ago
|
// restore old world matrix
|
||
|
m_painter->setWorldMatrix( matrix );
|
||
|
}
|