karbon

vdrawselection.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
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 
00021 #include "vdrawselection.h"
00022 #include "vcomposite.h"
00023 #include "vsegment.h"
00024 #include "vcolor.h"
00025 #include "vstroke.h"
00026 #include "vpainter.h"
00027 #include "vpath.h"
00028 
00029 void
00030 VDrawSelection::visitVPath( VPath &composite )
00031 {
00032     if(
00033         composite.state() == VObject::deleted ||
00034         composite.state() == VObject::hidden ||
00035         composite.state() == VObject::hidden_locked )
00036     {
00037         return;
00038     }
00039 
00040 
00041     m_painter->save();
00042     m_painter->setPen( Qt::SolidLine );
00043 
00044     const bool editnodes = composite.state() == VObject::edit && m_nodeediting;
00045 
00046     VSubpathListIterator itr( composite.paths() );
00047 
00048     if(
00049         composite.state() == VObject::selected ||
00050         editnodes )
00051     {
00052         // paint fill:
00053         m_painter->newPath();
00054 
00055         if( editnodes )
00056             m_painter->setRasterOp( Qt::XorROP );
00057 
00058         m_painter->setPen( editnodes ? Qt::yellow : Qt::blue );
00059         m_painter->setBrush( Qt::NoBrush );
00060 
00061         for( itr.toFirst(); itr.current(); ++itr )
00062         {
00063             VSubpathIterator jtr( *( itr.current() ) );
00064 
00065             for( ; jtr.current(); ++jtr )
00066             {
00067                 jtr.current()->draw( m_painter );
00068             }
00069 
00070             m_painter->strokePath();
00071         }
00072     }
00073 
00074     // Draw nodes and control lines.
00075     if(
00076         composite.state() == VObject::selected ||
00077         editnodes )
00078     {
00079         itr.toFirst();
00080         //++itr;        // Skip "begin".
00081 
00082         for( ; itr.current(); ++itr )
00083         {
00084             if( (*itr)->isEmpty() )
00085                 continue;
00086             VSubpathIterator jtr( *( itr.current() ) );
00087             //++jtr;
00088 
00089             for( ; jtr.current(); ++jtr )
00090             {
00091                 if( editnodes )
00092                     m_painter->setRasterOp( Qt::XorROP );
00093 
00094                 VColor color;
00095                 color.set( 0.5, 0.5, 1.0 );
00096 
00097                 VStroke stroke( color );
00098                 stroke.setLineWidth( 1.0 );
00099 
00100                 if( !editnodes )
00101                 {
00102                     m_painter->setPen( stroke );
00103                     m_painter->setPen( Qt::blue );
00104                 }
00105                 else
00106                     m_painter->setPen( Qt::yellow );
00107 
00108                 m_painter->setBrush( Qt::NoBrush );
00109 
00110                 if( ( editnodes || composite.state() == VObject::selected && m_nodeediting ) &&
00111                         jtr.current()->isCurve() )
00112                 {
00113                     // Draw control lines.
00114                     if(
00115                         jtr.current()->pointIsSelected( 1 ) ||
00116                         jtr.current()->knotIsSelected() ||
00117                         ( jtr.current()->next() &&
00118                           jtr.current()->next()->pointIsSelected( 0 ) &&
00119                           jtr.current()->isSmooth() ) )
00120                     {
00121                         m_painter->newPath();
00122                         m_painter->moveTo(
00123                             jtr.current()->point( 1 ) );
00124                         m_painter->lineTo(
00125                             jtr.current()->knot() );
00126 
00127                         m_painter->strokePath();
00128                         // Draw control node2:
00129                         m_painter->newPath();
00130                         m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue );
00131                         m_painter->drawNode( jtr.current()->point( 1 ), m_nodeSize );
00132                         m_painter->strokePath();
00133                     }
00134 
00135                     if(
00136                         jtr.current()->prev() &&
00137                         ( ( jtr.current()->prev()->knotIsSelected() ||
00138                           jtr.current()->pointIsSelected( 0 ) ) ||
00139                         ( jtr.current()->prev()->pointIsSelected( 1 ) &&
00140                           jtr.current()->prev()->isSmooth() ) ) )
00141                     {
00142                         m_painter->newPath();
00143                         m_painter->moveTo(
00144                             jtr.current()->prev()->knot() );
00145                         m_painter->lineTo(
00146                             jtr.current()->point( 0 ) );
00147 
00148                         m_painter->strokePath();
00149                         // Draw control node1:
00150                         m_painter->newPath();
00151                         m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue );
00152                         m_painter->drawNode( jtr.current()->point( 0 ), m_nodeSize );
00153                         m_painter->strokePath();
00154                     }
00155                 }
00156 
00157                 // Draw knot.
00158                 m_painter->setPen( editnodes ? Qt::yellow : Qt::blue );
00159 
00160                 if( !m_nodeediting )
00161                     m_painter->setBrush( Qt::blue );
00162                 else if( jtr.current()->knotIsSelected() )
00163                     m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue );
00164                 else
00165                     m_painter->setBrush( Qt::white );
00166 
00167                 m_painter->drawNode( jtr.current()->knot(), m_nodeSize );
00168             }
00169         }
00170     }
00171 
00172     // Draw center node.
00173     if( composite.drawCenterNode() && composite.state() == VObject::selected && !m_nodeediting )
00174     {
00175         m_painter->setPen( Qt::NoPen );
00176         m_painter->setBrush( Qt::blue.light() );
00177         m_painter->drawNode( composite.boundingBox().center(), m_nodeSize );
00178     }
00179 
00180     m_painter->restore();
00181 
00182     setSuccess();
00183 }
00184 
KDE Home | KDE Accessibility Home | Description of Access Keys