F:/KPlato/koffice/libs/flake/KoParameterShape.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     // function to do special stuff
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 

Généré le Wed Nov 22 23:40:59 2006 pour KPlato par  doxygen 1.5.1-p1