karbon
vrotatetool.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 <core/vglobal.h>
00031 #include "vrotatetool.h"
00032 #include <render/vpainter.h>
00033 #include <render/vpainterfactory.h>
00034 #include <commands/vtransformcmd.h>
00035
00036 #include <kdebug.h>
00037
00038 VRotateTool::VRotateTool( KarbonView *view )
00039 : VTool( view, "tool_rotate" )
00040 {
00041 m_objects.setAutoDelete( true );
00042 registerTool( this );
00043 }
00044
00045 VRotateTool::~VRotateTool()
00046 {
00047 m_objects.clear();
00048 }
00049
00050 void
00051 VRotateTool::activate()
00052 {
00053 view()->setCursor( QCursor( Qt::arrowCursor ) );
00054 view()->part()->document().selection()->setState( VObject::selected );
00055 view()->part()->document().selection()->showHandle( false );
00056 VTool::activate();
00057 }
00058
00059 QString
00060 VRotateTool::statusText()
00061 {
00062 return i18n( "Rotate" );
00063 }
00064
00065 void
00066 VRotateTool::draw()
00067 {
00068 VPainter* painter = view()->painterFactory()->editpainter();
00069
00070 painter->setRasterOp( Qt::NotROP );
00071
00072 VObjectListIterator itr = m_objects;
00073 for( ; itr.current(); ++itr )
00074 {
00075 itr.current()->draw( painter, &itr.current()->boundingBox() );
00076 }
00077 }
00078
00079 void
00080 VRotateTool::mouseButtonPress()
00081 {
00082
00083
00084 recalc();
00085
00086
00087 draw();
00088 }
00089
00090 void
00091 VRotateTool::mouseDrag()
00092 {
00093
00094 draw();
00095
00096 recalc();
00097
00098
00099 draw();
00100 }
00101
00102 void
00103 VRotateTool::mouseDragRelease()
00104 {
00105 view()->part()->addCommand(
00106 new VRotateCmd(
00107 &view()->part()->document(),
00108 m_center,
00109 m_angle, altPressed() ),
00110 true );
00111 }
00112
00113 void
00114 VRotateTool::cancel()
00115 {
00116
00117 if ( isDragging() )
00118 {
00119 draw();
00120 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
00121 }
00122 }
00123
00124 void
00125 VRotateTool::recalc()
00126 {
00127
00128 m_center = view()->part()->document().selection()->boundingBox().center();
00129
00130
00131 m_angle = VGlobal::one_pi_180 * (
00132 atan2(
00133 last().y() - m_center.y(),
00134 last().x() - m_center.x() )
00135 -
00136 atan2(
00137 first().y() - m_center.y(),
00138 first().x() - m_center.x() ) );
00139
00140 VRotateCmd cmd( 0L, m_center, m_angle );
00141
00142
00143 m_objects.clear();
00144 VObject* copy;
00145
00146 VObjectListIterator itr = view()->part()->document().selection()->objects();
00147 for ( ; itr.current() ; ++itr )
00148 {
00149 if( itr.current()->state() != VObject::deleted )
00150 {
00151 copy = itr.current()->clone();
00152
00153 cmd.visit( *copy );
00154
00155 copy->setState( VObject::edit );
00156
00157 m_objects.append( copy );
00158 }
00159 }
00160 }
00161
00162 void
00163 VRotateTool::setup( KActionCollection *collection )
00164 {
00165 m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00166
00167 if( m_action == 0 )
00168 {
00169 m_action = new KRadioAction( i18n( "Rotate Tool" ), "14_rotate", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00170 m_action->setToolTip( i18n( "Rotate" ) );
00171 m_action->setExclusiveGroup( "manipulation" );
00172
00173 }
00174 }
00175
|