karbon

vtoolcontroller.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 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#include "karbon_tool_registry.h"
21#include "karbon_part.h"
22#include <vselection.h>
23#include "vtoolcontroller.h"
24#include "vtool.h"
25#include "vtoolbox.h"
26
27VToolController::VToolController( KarbonView *view ) : m_view( view ), m_currentTool( 0L ), m_setup( false )
28{
29 m_tools.setAutoDelete( true );
30}
31
32void
33VToolController::init()
34{
35}
36
37VToolController::~VToolController()
38{
39}
40
41void
42VToolController::setCurrentTool( VTool *tool )
43{
44 if( m_currentTool )
45 {
46 m_currentTool->action()->setChecked( false );
47 m_currentTool->deactivate();
48 }
49
50 if( m_currentTool && m_currentTool == tool )
51 m_currentTool->showDialog();
52 else
53 {
54 m_currentTool = tool;
55
56 if( ! tool )
57 return;
58
59 m_currentTool->action()->setChecked( true );
60 m_currentTool->action()->activate();
61 }
62 m_toolBox->slotSetTool( tool->name() );
63}
64
65void
66VToolController::registerTool( VTool *tool )
67{
68 if( !m_tools.find( tool->name() ) )
69 m_tools.insert( tool->name(), tool );
70 //kdDebug(38000) << "active tool : " << m_currentTool->name() << endl;
71}
72
73void
74VToolController::unregisterTool( VTool *tool )
75{
76 // tool->name() is not valid in VTool destructor
77 TQDictIterator<VTool> it( m_tools );
78 for( ; it.current(); ++it )
79 if (it.current() == tool)
80 {
81 m_tools.remove(it.currentKey());
82 return;
83 }
84}
85
86bool
87VToolController::mouseEvent( TQMouseEvent* event, const KoPoint &p )
88{
89 if( !m_currentTool ) {
90 return false;
91 }
92
93 return m_currentTool->mouseEvent( event, p );
94}
95
96bool
97VToolController::keyEvent( TQEvent* event )
98{
99 if( !m_currentTool ) {
100 return false;
101 }
102
103 return m_currentTool->keyEvent( event );
104}
105
106void
107VToolController::setUp( TDEActionCollection *ac, VToolBox * toolbox )
108{
109 if( m_setup )
110 {
111 resetToolBox( toolbox);
112 return;
113 }
114
115 KarbonToolRegistry::instance()->createTools( ac, m_view );
116
117 m_toolBox = toolbox;
118
119 TQDictIterator<VTool> it( m_tools );
120 for( ; it.current(); ++it )
121 toolbox->registerTool( it.current() );
122
123 toolbox->setupTools();
124
125 VTool *t = findTool( "tool_select" );
126 setCurrentTool(t);
127
128 m_setup = true;
129}
130
131void
132VToolController::resetToolBox( VToolBox * toolbox )
133{
134 m_toolBox = toolbox;
135
136 TQDictIterator<VTool> it( m_tools );
137 for( ; it.current(); ++it )
138 toolbox->registerTool( it.current() );
139
140 toolbox->setupTools();
141
142 if( m_currentTool )
143 {
144 // restore the old current tool
145 setCurrentTool( m_currentTool );
146 m_currentTool = 0;
147 }
148}
149
150VTool *
151VToolController::findTool( const TQString &toolName ) const
152{
153 VTool *tool = 0;
154 TQDictIterator<VTool> it( m_tools );
155 for( ; it.current(); ++it )
156 if( it.current()->name() == toolName )
157 return it.current();
158 return tool;
159}
160
161void
162VToolController::youAintGotNoToolBox()
163{
164 m_toolBox = 0;
165 //m_currentTool = currentTool();
166}
167
This class...
Definition vtoolbox.h:29
The base class for all karbon tools.
Definition vtool.h:52
TDERadioAction * action() const
Returns the tool's associated action object.
Definition vtool.h:151