00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KoParameterShape.h"
00021
00022 #include <QDebug>
00023 #include <QPainter>
00024
00025 KoParameterShape::KoParameterShape()
00026 : m_modified( false )
00027 {
00028 }
00029
00030 KoParameterShape::~KoParameterShape()
00031 {
00032 }
00033
00034 void KoParameterShape::moveHandle( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers )
00035 {
00036 if ( handleId >= m_handles.size() )
00037 {
00038 qWarning() << "handleId out of bounds";
00039 return;
00040 }
00041
00042 repaint();
00043
00044 moveHandleAction( handleId, point, modifiers );
00045
00046 updatePath( size() );
00047 repaint();
00048 }
00049
00050
00051 int KoParameterShape::handleIdAt( const QRectF & rect ) const
00052 {
00053 int handle = -1;
00054
00055 for ( int i = 0; i < m_handles.size(); ++i )
00056 {
00057 if ( rect.contains( m_handles.at( i ) ) )
00058 {
00059 handle = i;
00060 break;
00061 }
00062 }
00063 return handle;
00064 }
00065
00066 QPointF KoParameterShape::handlePosition( int handleId )
00067 {
00068 return m_handles[handleId];
00069 }
00070
00071 void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter & converter )
00072 {
00073 applyConversion( painter, converter );
00074
00075 QMatrix worldMatrix = painter.worldMatrix();
00076 painter.setMatrix( QMatrix() );
00077
00078 QWMatrix matrix;
00079 matrix.rotate( 45.0 );
00080 QPolygonF poly( handleRect( QPointF( 0, 0 ) ) );
00081 poly = matrix.map( poly );
00082
00083 QList<QPointF>::const_iterator it( m_handles.begin() );
00084 for ( ; it != m_handles.end(); ++it )
00085 {
00086 QPointF moveVector = worldMatrix.map( *it );
00087 poly.translate( moveVector.x(), moveVector.y() );
00088 painter.drawPolygon( poly );
00089 poly.translate( -moveVector.x(), -moveVector.y() );
00090 }
00091 }
00092
00093 void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId )
00094 {
00095 applyConversion( painter, converter );
00096
00097 QMatrix worldMatrix = painter.worldMatrix();
00098 painter.setMatrix( QMatrix() );
00099
00100 QWMatrix matrix;
00101 matrix.rotate( 45.0 );
00102 QPolygonF poly( handleRect( QPointF( 0, 0 ) ) );
00103 poly = matrix.map( poly );
00104 poly.translate( worldMatrix.map( m_handles[handleId] ) );
00105 painter.drawPolygon( poly );
00106 }
00107
00108 void KoParameterShape::resize( const QSizeF &newSize )
00109 {
00110 QSizeF oldSize = size();
00111 QMatrix matrix( newSize.width() / oldSize.width(), 0, 0, newSize.height() / oldSize.height(), 0, 0 );
00112
00113 for( int i = 0; i < m_handles.size(); ++i )
00114 {
00115 m_handles[i] = matrix.map( m_handles[i] );
00116 }
00117
00118 KoPathShape::resize( newSize );
00119 }
00120
00121 QPointF KoParameterShape::normalize()
00122 {
00123 QPointF offset( KoPathShape::normalize() );
00124 QMatrix matrix;
00125 matrix.translate( -offset.x(), -offset.y() );
00126
00127 for( int i = 0; i < m_handles.size(); ++i )
00128 {
00129 m_handles[i] = matrix.map( m_handles[i] );
00130 }
00131
00132 return offset;
00133 }
00134