karbon

vspiraltool.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 <tqlabel.h>
21#include <tqgroupbox.h>
22
23#include <tdelocale.h>
24#include <kcombobox.h>
25#include <knuminput.h>
26
27#include <karbon_view.h>
28#include <karbon_part.h>
29#include <shapes/vspiral.h>
30#include "vspiraltool.h"
31#include "KoUnitWidgets.h"
32
33
34VSpiralTool::VSpiralOptionsWidget::VSpiralOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name )
35 : KDialogBase( parent, name, true, i18n( "Insert Spiral" ), Ok | Cancel ), m_part( part )
36{
37 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
38
39 new TQLabel( i18n( "Type:" ), group );
40 m_type = new KComboBox( false, group );
41 m_type->insertItem( i18n( "Round" ), 0 );
42 m_type->insertItem( i18n( "Rectangular" ), 1 );
43
44 new TQLabel( i18n( "Radius:" ), group );
45 m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM );
46 refreshUnit();
47 new TQLabel( i18n( "Segments:" ), group );
48 m_segments = new KIntSpinBox( group );
49 m_segments->setMinValue( 1 );
50 new TQLabel( i18n( "Fade:" ), group );
51 m_fade = new KDoubleNumInput( group );
52 m_fade->setRange( 0.0, 1.0, 0.05 );
53
54 new TQLabel( i18n( "Orientation:" ), group );
55 m_clockwise = new KComboBox( false, group );
56 m_clockwise->insertItem( i18n( "Clockwise" ), 0 );
57 m_clockwise->insertItem( i18n( "Counter Clockwise" ), 1 );
58
59 group->setInsideMargin( 4 );
60 group->setInsideSpacing( 2 );
61
62 setMainWidget( group );
63 //setFixedSize( baseSize() );
64}
65
66double
67VSpiralTool::VSpiralOptionsWidget::radius() const
68{
69 return m_radius->value();
70}
71
72uint
73VSpiralTool::VSpiralOptionsWidget::segments() const
74{
75 return m_segments->value();
76}
77
78double
79VSpiralTool::VSpiralOptionsWidget::fade() const
80{
81 return m_fade->value();
82}
83
84bool
85VSpiralTool::VSpiralOptionsWidget::clockwise() const
86{
87 return m_clockwise->currentItem() == 0;
88}
89
90uint
91VSpiralTool::VSpiralOptionsWidget::type() const
92{
93 return m_type->currentItem();
94}
95
96void
97VSpiralTool::VSpiralOptionsWidget::setRadius( double value )
98{
99 m_radius->changeValue( value );
100}
101
102void
103VSpiralTool::VSpiralOptionsWidget::setSegments( uint value )
104{
105 m_segments->setValue( value );
106}
107
108void
109VSpiralTool::VSpiralOptionsWidget::setFade( double value )
110{
111 m_fade->setValue( value );
112}
113
114void
115VSpiralTool::VSpiralOptionsWidget::setClockwise( bool value )
116{
117 m_clockwise->setCurrentItem( value ? 0 : 1 );
118}
119
120void
121VSpiralTool::VSpiralOptionsWidget::refreshUnit()
122{
123 m_radius->setUnit( m_part->unit() );
124}
125
126VSpiralTool::VSpiralTool( KarbonView *view )
127 : VShapeTool( view, "tool_spiral", true )
128{
129 // create config dialog:
130 m_optionsWidget = new VSpiralOptionsWidget( view->part() );
131 m_optionsWidget->setSegments( 8 );
132 m_optionsWidget->setFade( 0.8 );
133 m_optionsWidget->setClockwise( true );
134 registerTool( this );
135}
136
137void
138VSpiralTool::arrowKeyReleased( TQt::Key key )
139{
140 int change = 0;
141 if( key == TQt::Key_Up )
142 change = 1;
143 else if( key == TQt::Key_Down )
144 change = -1;
145
146 if( change != 0 )
147 {
148 draw();
149
150 m_optionsWidget->setSegments( m_optionsWidget->segments() + change );
151
152 draw();
153 }
154}
155
156VSpiralTool::~VSpiralTool()
157{
158 delete( m_optionsWidget );
159}
160
161void
163{
164 m_optionsWidget->refreshUnit();
165}
166
167VPath*
168VSpiralTool::shape( bool interactive ) const
169{
170 if( interactive )
171 {
172 return
173 new VSpiral(
174 0L,
175 m_p,
176 m_optionsWidget->radius(),
177 m_optionsWidget->segments(),
178 m_optionsWidget->fade(),
179 m_optionsWidget->clockwise(),
180 m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() );
181 }
182 else
183 return
184 new VSpiral(
185 0L,
186 m_p,
187 m_d1,
188 m_optionsWidget->segments(),
189 m_optionsWidget->fade(),
190 m_optionsWidget->clockwise(),
191 m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() );
192}
193
194bool
196{
197 return m_optionsWidget->exec() == TQDialog::Accepted;
198}
199
200void
201VSpiralTool::setup( TDEActionCollection *collection )
202{
203 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
204
205 if( m_action == 0 )
206 {
207 m_action = new TDERadioAction( i18n( "Spiral Tool" ), "14_spiral", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
208 m_action->setToolTip( i18n( "Spiral" ) );
209 m_action->setExclusiveGroup( "shapes" );
210 //m_ownAction = true;
211 }
212}
213
Keeps track of visual per document properties.
Definition karbon_part.h:46
A composite path consists of one or many subpaths.
Definition vcomposite.h:48
TDERadioAction * action() const
Returns the tool's associated action object.
Definition vtool.h:151
virtual void activate()
Called during the tool activation.
Definition vtool.cpp:252
TDERadioAction * m_action
The tool's action object.
Definition vtool.h:309
virtual void refreshUnit()
This function is called when the documents unit setting were changed.
Definition vtool.h:138
KarbonView * view() const
Returns the connected karbon part.
Definition vtool.cpp:66
virtual bool showDialog() const
Shows the tools option dialog.
Definition vtool.h:88