karbon

vstartool.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 <knuminput.h>
25#include <kcombobox.h>
26
27#include <karbon_view.h>
28#include <karbon_part.h>
29#include <shapes/vstar.h>
30#include "vstartool.h"
31#include "KoUnitWidgets.h"
32
33
34VStarOptionsWidget::VStarOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name )
35 : KDialogBase( parent, name, true, i18n( "Insert Star" ), Ok | Cancel ), m_part( part )
36{
37 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
38 new TQLabel( i18n( "Type:" ), group );
39 m_type = new KComboBox( false, group );
40 m_type->insertItem( i18n( "Star Outline" ), VStar::star_outline );
41 m_type->insertItem( i18n( "Spoke" ), VStar::spoke );
42 m_type->insertItem( i18n( "Wheel" ), VStar::wheel );
43 m_type->insertItem( i18n( "Polygon" ), VStar::polygon );
44 m_type->insertItem( i18n( "Framed Star" ), VStar::framed_star);
45 m_type->insertItem( i18n( "Star" ), VStar::star );
46 m_type->insertItem( i18n( "Gear" ), VStar::gear );
47 connect( m_type, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( typeChanged( int ) ) );
48
49 // add width/height-input:
50 m_outerRLabel = new TQLabel( i18n( "Outer radius:" ), group );
51 m_outerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM );
52 connect( m_outerR, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( setOuterRadius( double ) ) );
53
54 m_innerRLabel = new TQLabel( i18n( "Inner radius:" ), group );
55 m_innerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 25.0, KoUnit::U_MM );
56
57 refreshUnit();
58
59 new TQLabel( i18n( "Edges:" ), group );
60 m_edges = new KIntSpinBox( group );
61 m_edges->setMinValue( 3 );
62 connect( m_edges, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( setEdges( int ) ) );
63
64 new TQLabel( i18n( "Inner angle:" ), group );
65 m_innerAngle = new KIntSpinBox( group );
66 m_innerAngle->setMinValue( 0 );
67 m_innerAngle->setMaxValue( 360 );
68
69 new TQLabel( i18n( "Roundness:" ), group );
70 m_roundness = new KDoubleNumInput( group );
71 m_roundness->setRange( 0.0, 1.0, 0.05 );
72
73 typeChanged( VStar::star_outline );
74
75 group->setInsideMargin( 4 );
76 group->setInsideSpacing( 2 );
77
78 setMainWidget( group );
79 setFixedSize( baseSize() );
80}
81
82void
83VStarOptionsWidget::refreshUnit()
84{
85 m_outerR->setUnit( m_part->unit() );
86 m_innerR->setUnit( m_part->unit() );
87}
88
89void
90VStarOptionsWidget::setEdges( int v )
91{
92 m_edges->setValue( v );
93
94 // set optimal inner radius
95 if( type() == VStar::star )
96 m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) );
97}
98
99void
100VStarOptionsWidget::setInnerRadius( double v )
101{
102 m_innerR->changeValue( v );
103}
104
105void
106VStarOptionsWidget::setOuterRadius( double v )
107{
108 m_outerR->setValue( v );
109
110 // set optimal inner radius
111 if( type() == VStar::star )
112 m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) );
113}
114
115double
116VStarOptionsWidget::roundness() const
117{
118 return m_roundness->value();
119}
120
121int
122VStarOptionsWidget::edges() const
123{
124 return m_edges->value();
125}
126
127double
128VStarOptionsWidget::innerRadius() const
129{
130 return m_innerR->value();
131}
132
133double
134VStarOptionsWidget::outerRadius() const
135{
136 return m_outerR->value();
137}
138
139uint
140VStarOptionsWidget::type() const
141{
142 return m_type->currentItem();
143}
144
145uint
146VStarOptionsWidget::innerAngle() const
147{
148 return m_innerAngle->value();
149}
150
151void
152VStarOptionsWidget::typeChanged( int type )
153{
154 m_innerR->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear );
155 m_innerAngle->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear );
156
157 // set optimal inner radius
158 if( type == VStar::star )
159 m_innerR->changeValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) );
160}
161
162VStarTool::VStarTool( KarbonView *view )
163 : VShapeTool( view, "tool_star", true )
164{
165 // create config dialog:
166 m_optionsWidget = new VStarOptionsWidget( view->part() );
167 m_optionsWidget->setEdges( 5 );
168 registerTool( this );
169}
170
171void VStarTool::refreshUnit()
172{
173 m_optionsWidget->refreshUnit();
174}
175
176VStarTool::~VStarTool()
177{
178 delete( m_optionsWidget );
179}
180
181void
182VStarTool::arrowKeyReleased( TQt::Key key )
183{
184 int change = 0;
185 if( key == TQt::Key_Up )
186 change = 1;
187 else if( key == TQt::Key_Down )
188 change = -1;
189
190 if( change != 0 )
191 {
192 draw();
193
194 m_optionsWidget->setEdges( m_optionsWidget->edges() + change );
195
196 draw();
197 }
198}
199
200VPath*
201VStarTool::shape( bool interactive ) const
202{
203 if( interactive )
204 {
205 return
206 new VStar(
207 0L,
208 m_p,
209 m_optionsWidget->outerRadius(),
210 m_optionsWidget->innerRadius(),
211 m_optionsWidget->edges(), 0.0, m_optionsWidget->innerAngle(),
212 m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() );
213 }
214 else
215 return
216 new VStar(
217 0L,
218 m_p,
219 m_d1,
220 m_optionsWidget->innerRadius() * m_d1 /
221 m_optionsWidget->outerRadius(),
222 m_optionsWidget->edges(),
223 m_d2, m_optionsWidget->innerAngle(),
224 m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() );
225}
226
227bool
228VStarTool::showDialog() const
229{
230 return m_optionsWidget->exec() == TQDialog::Accepted;
231}
232
233void
234VStarTool::setup( TDEActionCollection *collection )
235{
236 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
237
238 if( m_action == 0 )
239 {
240 TDEShortcut shortcut( TQt::Key_Plus );
241 shortcut.append(TDEShortcut( TQt::Key_F9 ) );
242 m_action = new TDERadioAction( i18n( "Star Tool" ), "14_star", shortcut, this, TQ_SLOT( activate() ), collection, name() );
243 m_action->setToolTip( i18n( "Draw a star" ) );
244 m_action->setExclusiveGroup( "shapes" );
245 //m_ownAction = true;
246 }
247}
248
249#include "vstartool.moc"
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
This shape offers star-like shapes with a lot of parameters :
Definition vstar.h:48