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 VSegment* curr = jtr.current(); 00114 VSegment* next = curr->next(); 00115 VSegment* prev = curr->prev(); 00116 00117 // Draw control lines. 00118 if ( curr->pointIsSelected( curr->degree()-2 ) || curr->knotIsSelected() 00119 || ( next && next->isCurve() && next->pointIsSelected( 0 ) && curr->isSmooth() ) ) 00120 { 00121 m_painter->newPath(); 00122 m_painter->moveTo( curr->point( curr->degree()-2 ) ); 00123 m_painter->lineTo( curr->knot() ); 00124 m_painter->strokePath(); 00125 // Draw control node2: 00126 m_painter->newPath(); 00127 m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue ); 00128 m_painter->drawNode( curr->point( curr->degree()-2 ), m_nodeSize ); 00129 m_painter->strokePath(); 00130 } 00131 00132 if ( prev && ( ( prev->knotIsSelected() || curr->pointIsSelected( 0 ) ) 00133 || ( prev->isCurve() && prev->pointIsSelected( prev->degree()-2 ) && prev->isSmooth() ) ) ) 00134 { 00135 m_painter->newPath(); 00136 m_painter->moveTo( prev->knot() ); 00137 m_painter->lineTo( curr->point( 0 ) ); 00138 m_painter->strokePath(); 00139 // Draw control node1: 00140 m_painter->newPath(); 00141 m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue ); 00142 m_painter->drawNode( curr->point( 0 ), m_nodeSize ); 00143 m_painter->strokePath(); 00144 } 00145 } 00146 00147 // Draw knot. 00148 m_painter->setPen( editnodes ? Qt::yellow : Qt::blue ); 00149 00150 if( !m_nodeediting ) 00151 m_painter->setBrush( Qt::blue ); 00152 else if( jtr.current()->knotIsSelected() ) 00153 m_painter->setBrush( editnodes ? Qt::yellow : Qt::blue ); 00154 else 00155 m_painter->setBrush( Qt::white ); 00156 00157 m_painter->drawNode( jtr.current()->knot(), m_nodeSize ); 00158 } 00159 } 00160 } 00161 00162 // Draw center node. 00163 if( composite.drawCenterNode() && composite.state() == VObject::selected && !m_nodeediting ) 00164 { 00165 m_painter->setPen( Qt::NoPen ); 00166 m_painter->setBrush( Qt::blue.light() ); 00167 m_painter->drawNode( composite.boundingBox().center(), m_nodeSize ); 00168 } 00169 00170 m_painter->restore(); 00171 00172 setSuccess(); 00173 } 00174

