karbon

vsheartool.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 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 #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     // Draw new object:
00108     draw();
00109 }
00110 
00111 void
00112 VShearTool::mouseDrag( )
00113 {
00114     // Erase old object:
00115     draw();
00116 
00117     recalc();
00118 
00119     // Draw new object:
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     // Erase old object:
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     // Get center:
00182     m_center = view()->part()->document().selection()->boundingBox().center();
00183 
00184     VShearCmd cmd( 0L, m_center, m_s1, m_s2 );
00185 
00186     // Copy selected objects and transform:
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         //m_ownAction = true;
00217     }
00218 }
00219 
KDE Home | KDE Accessibility Home | Description of Access Keys