vimagetool.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18
19*/
20
21#include <tqcursor.h>
22#include <tdelocale.h>
23#include <tdefiledialog.h>
24#include <kdebug.h>
25
26#include "vimagetool.h"
27#include <karbon_part.h>
28#include <karbon_view.h>
29#include <core/vimage.h>
30#include <core/vselection.h>
31#include <core/vcursor.h>
32
33VImageTool::VImageTool( KarbonView *view ) : VTool( view, "tool_image_plugin" )
34{
35 registerTool( this );
36 m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) );
37}
38
39VImageTool::~VImageTool()
40{
41 delete m_cursor;
42}
43
44TQString
45VImageTool::contextHelp()
46{
47 TQString s = i18n( "<qt><b>Image tool:</b><br>" );
48 return s;
49}
50
51void
52VImageTool::activate()
53{
54 view()->setCursor( *m_cursor );
56}
57
58TQString
59VImageTool::statusText()
60{
61 return i18n( "Image Tool" );
62}
63
64void
65VImageTool::deactivate()
66{
67}
68
69void
70VImageTool::mouseButtonRelease()
71{
72 TQString fname = KFileDialog::getOpenFileName( TQString(), "*.jpg *.gif *.png", view(), i18n( "Choose Image to Add" ) );
73 if( !fname.isEmpty() )
74 {
75 VImage *image = new VImage( 0L, fname );
76 VInsertImageCmd *cmd = new VInsertImageCmd( &view()->part()->document(), i18n( "Insert Image" ), image, first() );
77
78 view()->part()->addCommand( cmd, true );
79 }
80}
81
82VImageTool::VInsertImageCmd::VInsertImageCmd( VDocument* doc, const TQString& name, VImage *image, KoPoint pos )
83 : VCommand( doc, name, "frame_image" ), m_image( image ), m_pos( pos )
84{
85}
86
87void
88VImageTool::VInsertImageCmd::execute()
89{
90 if( !m_image )
91 return;
92
93 if( m_image->state() == VObject::deleted )
94 m_image->setState( VObject::normal );
95 else
96 {
97 m_image->setState( VObject::normal );
98 m_image->transform( TQWMatrix().translate( m_pos.x(), m_pos.y() ) );
99 document()->append( m_image );
100 document()->selection()->clear();
101 document()->selection()->append( m_image );
102 }
103
104 setSuccess( true );
105}
106
107void
108VImageTool::VInsertImageCmd::unexecute()
109{
110 if( !m_image )
111 return;
112
113 document()->selection()->take( *m_image );
114 m_image->setState( VObject::deleted );
115
116 setSuccess( false );
117}
118
119void
120VImageTool::setup( TDEActionCollection *collection )
121{
122 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
123
124 if( m_action == 0 )
125 {
126 m_action = new TDERadioAction( i18n( "Image Tool" ), "14_image", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
127 m_action->setToolTip( i18n( "Image" ) );
128 m_action->setExclusiveGroup( "misc" );
129 //m_ownAction = true;
130 }
131}
132
The base class for all karbon commands.
Definition vcommand.h:42
@ CrossHair
unthemed crosshair cursor
Definition vcursor.h:38
static TQCursor createCursor(CursorType type)
Creates a predefined cursor of the specified type.
Definition vcursor.cpp:75
All non-visual, static doc info is in here.
Definition vdocument.h:53
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
The base class for all karbon tools.
Definition vtool.h:52
virtual void activate()
Called during the tool activation.
Definition vtool.cpp:252