Commit b78e022b authored by Jan Hambrecht's avatar Jan Hambrecht

use handle radius from KoCanvasResourceProvider to draw

path point and parameter handles


svn path=/trunk/koffice/; revision=620923
parent 76ede626
......@@ -68,7 +68,7 @@ QPointF KoParameterShape::handlePosition( int handleId )
return m_handles[handleId];
}
void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter & converter )
void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter & converter, int handleRadius )
{
applyConversion( painter, converter );
......@@ -77,7 +77,7 @@ void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter &
QWMatrix matrix;
matrix.rotate( 45.0 );
QPolygonF poly( handleRect( QPointF( 0, 0 ) ) );
QPolygonF poly( handleRect( QPointF( 0, 0 ), handleRadius ) );
poly = matrix.map( poly );
QList<QPointF>::const_iterator it( m_handles.begin() );
......@@ -90,7 +90,7 @@ void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter &
}
}
void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId )
void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius )
{
applyConversion( painter, converter );
......@@ -99,7 +99,7 @@ void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter &
QWMatrix matrix;
matrix.rotate( 45.0 );
QPolygonF poly( handleRect( QPointF( 0, 0 ) ) );
QPolygonF poly( handleRect( QPointF( 0, 0 ), handleRadius ) );
poly = matrix.map( poly );
poly.translate( worldMatrix.map( m_handles[handleId] ) );
painter.drawPolygon( poly );
......
......@@ -78,8 +78,9 @@ public:
*
* @param painter the painter to paint the handles on
* @param converter the view converter for applying the actual zoom
* @param handleRadius the radius of the handles used for painting
*/
virtual void paintHandles( QPainter & painter, const KoViewConverter & converter );
virtual void paintHandles( QPainter & painter, const KoViewConverter & converter, int handleRadius );
/**
* @brief Paint the given handles
......@@ -87,8 +88,9 @@ public:
* @param painter the painter to paint the handles on
* @param converter the view converter for applying the actual zoom
* @param handleId of the handle which should be repainted
* @param handleRadius the radius of the handle used for painting
*/
virtual void paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId );
virtual void paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius );
virtual void resize( const QSizeF &newSize );
......
......@@ -416,13 +416,13 @@ QRectF KoPathShape::documentToShape( const QRectF &rect ) const
}
void KoPathShape::paintPoints( QPainter &painter, const KoViewConverter &converter )
void KoPathShape::paintPoints( QPainter &painter, const KoViewConverter &converter, int handleRadius )
{
applyConversion( painter, converter );
KoSubpathList::const_iterator pathIt( m_subpaths.begin() );
QRectF handle = converter.viewToDocument( handleRect( QPoint(0,0) ) );
QRectF handle = converter.viewToDocument( handleRect( QPoint(0,0), handleRadius ) );
for ( ; pathIt != m_subpaths.end(); ++pathIt )
{
......@@ -435,10 +435,9 @@ void KoPathShape::paintPoints( QPainter &painter, const KoViewConverter &convert
}
}
QRectF KoPathShape::handleRect( const QPointF &p ) const
QRectF KoPathShape::handleRect( const QPointF &p, double radius ) const
{
const qreal handleRadius = 3.0;
return QRectF( p.x()-handleRadius, p.y()-handleRadius, 2*handleRadius, 2*handleRadius );
return QRectF( p.x()-radius, p.y()-radius, 2*radius, 2*radius );
}
const QPainterPath KoPathShape::outline() const
......
......@@ -387,7 +387,7 @@ public:
virtual ~KoPathShape();
virtual void paint(QPainter &painter, const KoViewConverter &converter);
virtual void paintPoints( QPainter &painter, const KoViewConverter &converter );
virtual void paintPoints( QPainter &painter, const KoViewConverter &converter, int handleRadius );
virtual const QPainterPath outline() const;
virtual QRectF boundingRect() const;
virtual QSizeF size() const;
......@@ -806,7 +806,7 @@ private:
#endif
protected:
QRectF handleRect( const QPointF &p ) const;
QRectF handleRect( const QPointF &p, double radius ) const;
/**
* @brief add a arc.
*
......
......@@ -311,11 +311,11 @@ void KoPathTool::paint( QPainter &painter, KoViewConverter &converter) {
KoParameterShape * parameterShape = dynamic_cast<KoParameterShape*>( shape );
if ( parameterShape && parameterShape->isParametricShape() )
{
parameterShape->paintHandles( painter, converter );
parameterShape->paintHandles( painter, converter, m_handleRadius );
}
else
{
pathShape->paintPoints( painter, converter );
pathShape->paintPoints( painter, converter, m_handleRadius );
}
painter.restore();
......@@ -490,15 +490,15 @@ void KoPathTool::keyPressEvent(QKeyEvent *event) {
switch(event->key())
{
case Qt::Key_I:
{
int handleRadius = m_canvas->resourceProvider()->handleRadius();
if(event->modifiers() & Qt::ControlModifier)
{
if( m_handleRadius > 3 )
m_handleRadius--;
}
handleRadius--;
else
m_handleRadius++;
m_pointSelection.repaint();
handleRadius++;
m_canvas->resourceProvider()->setHandleRadius( handleRadius );
break;
}
case Qt::Key_Backspace:
removePoints();
break;
......@@ -563,6 +563,10 @@ void KoPathTool::keyReleaseEvent(QKeyEvent *event) {
void KoPathTool::activate (bool temporary) {
Q_UNUSED(temporary);
bool found = false;
// retrieve the actual global handle radius
m_handleRadius = m_canvas->resourceProvider()->handleRadius();
foreach(KoShape *shape, m_canvas->shapeManager()->selection()->selectedShapes())
{
KoPathShape *pathShape;
......@@ -589,6 +593,36 @@ void KoPathTool::deactivate() {
m_currentStrategy = 0;
}
void KoPathTool::resourceChanged( KoCanvasResource::EnumCanvasResource key, const QVariant & res )
{
switch( key )
{
case KoCanvasResource::HandleRadius:
{
QRectF repaintRect;
foreach(KoShape *shape, m_canvas->shapeManager()->selection()->selectedShapes() )
{
KoPathShape *pathShape = dynamic_cast<KoPathShape*>( shape );
if( pathShape )
{
if( repaintRect.isEmpty() )
repaintRect = pathShape->shapeToDocument( pathShape->outline().controlPointRect() );
else
repaintRect |= pathShape->shapeToDocument( pathShape->outline().controlPointRect() );
}
}
repaint( repaintRect );
m_pointSelection.repaint();
m_handleRadius = res.toUInt();
m_pointSelection.repaint();
repaint( repaintRect );
}
break;
default:
return;
}
}
void KoPathTool::selectPoints( const QRectF &rect, bool clearSelection )
{
if( clearSelection )
......@@ -716,8 +750,7 @@ void KoPathTool::ActiveParameterHandle::paint( QPainter &painter, KoViewConverte
painter.save();
painter.setMatrix( m_parameterShape->transformationMatrix(&converter) * painter.matrix() );
QRectF handle = converter.viewToDocument( m_tool->handleRect( QPoint(0,0) ) );
m_parameterShape->paintHandle( painter, converter, m_handleId );
m_parameterShape->paintHandle( painter, converter, m_handleId, m_tool->m_handleRadius );
painter.restore();
}
......
......@@ -85,6 +85,7 @@ private slots:
void joinPoints();
void breakAtPoint();
void breakAtSegment();
void resourceChanged( KoCanvasResource::EnumCanvasResource key, const QVariant & res );
private:
/// the different path point types
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment