karbon
vsheartool.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <math.h>
00021
00022 #include <qcursor.h>
00023 #include <qlabel.h>
00024
00025 #include <klocale.h>
00026 #include <KoRect.h>
00027
00028 #include <karbon_part.h>
00029 #include <karbon_view.h>
00030 #include <render/vpainter.h>
00031 #include <render/vpainterfactory.h>
00032 #include <vselection.h>
00033 #include "vsheartool.h"
00034 #include <commands/vtransformcmd.h>
00035
00036 VShearTool::VShearTool( KarbonView *view ) : VTool( view, "sheartool" )
00037 {
00038 setName( "tool_shear" );
00039 m_objects.setAutoDelete( true );
00040 registerTool( this );
00041 }
00042
00043 VShearTool::~VShearTool()
00044 {
00045 }
00046
00047 void
00048 VShearTool::activate()
00049 {
00050 view()->setCursor( QCursor( Qt::arrowCursor ) );
00051 view()->part()->document().selection()->showHandle( true );
00052 view()->part()->document().selection()->setState( VObject::selected );
00053 VTool::activate();
00054 }
00055
00056 QString
00057 VShearTool::statusText()
00058 {
00059 return i18n( "Shear" );
00060 }
00061
00062 void
00063 VShearTool::draw()
00064 {
00065 VPainter* painter = view()->painterFactory()->editpainter();
00066 painter->setRasterOp( Qt::NotROP );
00067
00068 VObjectListIterator itr = m_objects;
00069 for( ; itr.current(); ++itr )
00070 itr.current()->draw( painter, &itr.current()->boundingBox() );
00071 }
00072
00073 void
00074 VShearTool::setCursor() const
00075 {
00076 if( isDragging() ) return;
00077 switch( view()->part()->document().selection()->handleNode( last() ) )
00078 {
00079 case node_lt:
00080 case node_rb:
00081 view()->setCursor( QCursor( Qt::SizeFDiagCursor ) );
00082 break;
00083 case node_rt:
00084 case node_lb:
00085 view()->setCursor( QCursor( Qt::SizeBDiagCursor ) );
00086 break;
00087 case node_lm:
00088 case node_rm:
00089 view()->setCursor( QCursor( Qt::SizeHorCursor ) );
00090 break;
00091 case node_mt:
00092 case node_mb:
00093 view()->setCursor( QCursor( Qt::SizeVerCursor ) );
00094 break;
00095 default:
00096 view()->setCursor( QCursor( Qt::arrowCursor ) );
00097 }
00098 }
00099
00100 void
00101 VShearTool::mouseButtonPress()
00102 {
00103 view()->painterFactory()->painter()->end();
00104 m_activeNode = view()->part()->document().selection()->handleNode( first() );
00105 recalc();
00106
00107
00108 draw();
00109 }
00110
00111 void
00112 VShearTool::mouseDrag( )
00113 {
00114
00115 draw();
00116
00117 recalc();
00118
00119
00120 draw();
00121 }
00122
00123
00124 void
00125 VShearTool::mouseDragRelease()
00126 {
00127 view()->part()->addCommand(
00128 new VShearCmd( &view()->part()->document(), m_center, m_s1, m_s2, altPressed() ),
00129 true );
00130 }
00131
00132 void
00133 VShearTool::cancel()
00134 {
00135
00136 if ( isDragging() )
00137 {
00138 draw();
00139 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
00140 }
00141 }
00142
00143 void
00144 VShearTool::recalc()
00145 {
00146 KoRect rect = view()->part()->document().selection()->boundingBox();
00147
00148 if( m_activeNode == node_lt )
00149 {
00150 }
00151 else if( m_activeNode == node_mt )
00152 {
00153 m_s1 = 0;
00154 m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) );
00155 }
00156 else if( m_activeNode == node_rt )
00157 {
00158 }
00159 else if( m_activeNode == node_rm)
00160 {
00161 m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) );
00162 m_s2 = 0;
00163 }
00164 else if( m_activeNode == node_rb )
00165 {
00166 }
00167 else if( m_activeNode == node_mb )
00168 {
00169 m_s1 = 0;
00170 m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) );
00171 }
00172 else if( m_activeNode == node_lb )
00173 {
00174 }
00175 else if( m_activeNode == node_lm )
00176 {
00177 m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) );
00178 m_s2 = 0;
00179 }
00180
00181
00182 m_center = view()->part()->document().selection()->boundingBox().center();
00183
00184 VShearCmd cmd( 0L, m_center, m_s1, m_s2 );
00185
00186
00187 m_objects.clear();
00188 VObject* copy;
00189
00190 VObjectListIterator itr = view()->part()->document().selection()->objects();
00191 for ( ; itr.current() ; ++itr )
00192 {
00193 if( itr.current()->state() != VObject::deleted )
00194 {
00195 copy = itr.current()->clone();
00196
00197 cmd.visit( *copy );
00198
00199 copy->setState( VObject::edit );
00200
00201 m_objects.append( copy );
00202 }
00203 }
00204 }
00205
00206 void
00207 VShearTool::setup( KActionCollection *collection )
00208 {
00209 m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00210
00211 if( m_action == 0 )
00212 {
00213 m_action = new KRadioAction( i18n( "Shear Tool" ), "14_shear", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00214 m_action->setToolTip( i18n( "Shear" ) );
00215 m_action->setExclusiveGroup( "manipulation" );
00216
00217 }
00218 }
00219
|