karbon
vimagetool.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qcursor.h>
00022 #include <klocale.h>
00023 #include <kfiledialog.h>
00024 #include <kdebug.h>
00025
00026 #include "vimagetool.h"
00027 #include <karbon_part.h>
00028 #include <karbon_view.h>
00029 #include <core/vimage.h>
00030 #include <core/vselection.h>
00031 #include <core/vcursor.h>
00032
00033 VImageTool::VImageTool( KarbonView *view ) : VTool( view, "tool_image_plugin" )
00034 {
00035 registerTool( this );
00036 m_cursor = new QCursor( VCursor::createCursor( VCursor::CrossHair ) );
00037 }
00038
00039 VImageTool::~VImageTool()
00040 {
00041 delete m_cursor;
00042 }
00043
00044 QString
00045 VImageTool::contextHelp()
00046 {
00047 QString s = i18n( "<qt><b>Image tool:</b><br>" );
00048 return s;
00049 }
00050
00051 void
00052 VImageTool::activate()
00053 {
00054 view()->setCursor( *m_cursor );
00055 VTool::activate();
00056 }
00057
00058 QString
00059 VImageTool::statusText()
00060 {
00061 return i18n( "Image Tool" );
00062 }
00063
00064 void
00065 VImageTool::deactivate()
00066 {
00067 }
00068
00069 void
00070 VImageTool::mouseButtonRelease()
00071 {
00072 QString fname = KFileDialog::getOpenFileName( QString::null, "*.jpg *.gif *.png", view(), i18n( "Choose Image to Add" ) );
00073 if( !fname.isEmpty() )
00074 {
00075 VImage *image = new VImage( 0L, fname );
00076 VInsertImageCmd *cmd = new VInsertImageCmd( &view()->part()->document(), i18n( "Insert Image" ), image, first() );
00077
00078 view()->part()->addCommand( cmd, true );
00079 }
00080 }
00081
00082 VImageTool::VInsertImageCmd::VInsertImageCmd( VDocument* doc, const QString& name, VImage *image, KoPoint pos )
00083 : VCommand( doc, name, "frame_image" ), m_image( image ), m_pos( pos )
00084 {
00085 }
00086
00087 void
00088 VImageTool::VInsertImageCmd::execute()
00089 {
00090 if( !m_image )
00091 return;
00092
00093 if( m_image->state() == VObject::deleted )
00094 m_image->setState( VObject::normal );
00095 else
00096 {
00097 m_image->setState( VObject::normal );
00098 m_image->transform( QWMatrix().translate( m_pos.x(), m_pos.y() ) );
00099 document()->append( m_image );
00100 document()->selection()->clear();
00101 document()->selection()->append( m_image );
00102 }
00103
00104 setSuccess( true );
00105 }
00106
00107 void
00108 VImageTool::VInsertImageCmd::unexecute()
00109 {
00110 if( !m_image )
00111 return;
00112
00113 document()->selection()->take( *m_image );
00114 m_image->setState( VObject::deleted );
00115
00116 setSuccess( false );
00117 }
00118
00119 void
00120 VImageTool::setup( KActionCollection *collection )
00121 {
00122 m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00123
00124 if( m_action == 0 )
00125 {
00126 m_action = new KRadioAction( i18n( "Image Tool" ), "14_image", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00127 m_action->setToolTip( i18n( "Image" ) );
00128 m_action->setExclusiveGroup( "misc" );
00129
00130 }
00131 }
00132
|