karbon

vellipsetool.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
21#include <tqgroupbox.h>
22#include <tqlabel.h>
23
24#include <tdelocale.h>
25#include "KoUnitWidgets.h"
26#include <KoUnit.h>
27#include <kcombobox.h>
28#include <knuminput.h>
29
30#include <karbon_view.h>
31#include <karbon_part.h>
32#include <shapes/vellipse.h>
33#include "vellipsetool.h"
34#include "vglobal.h"
35
36
37VEllipseOptionsWidget::VEllipseOptionsWidget( KarbonPart *part, TQWidget *parent, const char *name )
38 : KDialogBase( parent, name, true, i18n( "Insert Ellipse" ), Ok | Cancel ), m_part( part )
39{
40 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
41 new TQLabel( i18n( "Type:" ), group );
42 m_type = new KComboBox( false, group );
43 m_type->insertItem( i18n( "Full" ), VEllipse::full );
44 m_type->insertItem( i18n( "Section" ), VEllipse::section );
45 m_type->insertItem( i18n( "Pie" ), VEllipse::cut );
46 m_type->insertItem( i18n( "Arc" ), VEllipse::arc );
47 connect( m_type, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( typeChanged( int ) ) );
48
49 // add width/height-input:
50 m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group );
51 m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
52 m_heightLabel = new TQLabel( i18n( "Height:" ), group );
53 m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
54
55 new TQLabel( i18n( "Start angle:" ), group );
56 m_startAngle = new KIntSpinBox( group );
57 m_startAngle->setMinValue( 0 );
58 m_startAngle->setMaxValue( 360 );
59
60 new TQLabel( i18n( "End angle:" ), group );
61 m_endAngle = new KIntSpinBox( group );
62 m_endAngle->setMinValue( 0 );
63 m_endAngle->setMaxValue( 360 );
64
65 typeChanged( VEllipse::full );
66
67 refreshUnit();
68
69 group->setInsideMargin( 4 );
70 group->setInsideSpacing( 2 );
71
72 setMainWidget( group );
73 setFixedSize( baseSize() );
74}
75
76void
77VEllipseOptionsWidget::typeChanged( int type )
78{
79 m_startAngle->setEnabled( type != VEllipse::full );
80 m_endAngle->setEnabled( type != VEllipse::full );
81}
82
83uint
84VEllipseOptionsWidget::type() const
85{
86 return m_type->currentItem();
87}
88
89uint
90VEllipseOptionsWidget::startAngle() const
91{
92 return m_startAngle->value();
93}
94
95uint
96VEllipseOptionsWidget::endAngle() const
97{
98 return m_endAngle->value();
99}
100
101double
102VEllipseOptionsWidget::width() const
103{
104 return m_width->value();
105}
106
107double
108VEllipseOptionsWidget::height() const
109{
110 return m_height->value();
111}
112
113void
114VEllipseOptionsWidget::setWidth( double value )
115{
116 m_width->changeValue( value );
117}
118
119void
120VEllipseOptionsWidget::setHeight( double value )
121{
122 m_height->changeValue( value );
123}
124
125void
126VEllipseOptionsWidget::refreshUnit ()
127{
128 m_width->setUnit( m_part->unit() );
129 m_height->setUnit( m_part->unit() );
130}
131
132VEllipseTool::VEllipseTool( KarbonView *view )
133 : VShapeTool( view, "tool_ellipse" )
134{
135 // create config dialog:
136 m_optionsWidget = new VEllipseOptionsWidget( view->part() );
137 registerTool( this );
138
139 m_startAngle = m_endAngle = 0;
140 m_state = normal;
141}
142
143VEllipseTool::~VEllipseTool()
144{
145 delete( m_optionsWidget );
146}
147
148void
149VEllipseTool::refreshUnit()
150{
151 m_optionsWidget->refreshUnit();
152}
153
154VPath*
155VEllipseTool::shape( bool interactive ) const
156{
157 if( interactive )
158 {
159 double d1 = m_optionsWidget->width() / 2.0;
160 double d2 = m_optionsWidget->height() / 2.0;
161 return
162 new VEllipse(
163 0L,
164 KoPoint( m_center.x() - d1, m_center.y() - d2 ),
165 d1 * 2.0, d2 * 2.0,
166 (VEllipse::VEllipseType)m_optionsWidget->type(),
167 m_optionsWidget->startAngle(),
168 m_optionsWidget->endAngle() );
169 }
170 else
171 return
172 new VEllipse(
173 0L,
174 KoPoint( m_center.x() - m_d1, m_center.y() - m_d2 ),
175 m_d1 * 2.0,
176 m_d2 * 2.0,
177 (VEllipse::VEllipseType)m_optionsWidget->type(),
178 m_startAngle, m_endAngle );
179}
180
181void
182VEllipseTool::mouseMove()
183{
184 if( m_state == normal )
185 return;
186
187 draw();
188
189 //recalc();
190
191 if( m_state == startangle )
192 {
193 m_startAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() );
194 m_startAngle = ( m_startAngle / VGlobal::pi_2 ) * 90.0;
195 if( m_startAngle < 0 )
196 m_startAngle += 360.0;
197 }
198 else
199 {
200 m_endAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() );
201 m_endAngle = ( m_endAngle / VGlobal::pi_2 ) * 90.0;
202 if( m_endAngle < 0 )
203 m_endAngle += 360.0;
204 }
205
206 draw();
207}
208
209void
210VEllipseTool::mouseDragRelease()
211{
212 if( m_optionsWidget->type() == VEllipse::full )
213 VShapeTool::mouseDragRelease();
214
215 if( m_state == normal )
216 if( m_optionsWidget->type() != VEllipse::full )
217 m_state = startangle;
218}
219
220void
221VEllipseTool::mouseButtonPress()
222{
223 if( m_state == normal )
224 {
225 VShapeTool::mouseButtonPress();
226 m_center = first();
227 }
228}
229
230void
231VEllipseTool::mouseButtonRelease()
232{
233 if( m_optionsWidget->type() == VEllipse::full || m_state == normal )
234 VShapeTool::mouseButtonRelease();
235
236 if( m_state == startangle )
237 m_state = endangle;
238 else if( m_state == endangle )
239 {
240 VShapeTool::mouseDragRelease();
241 m_startAngle = m_endAngle = 0;
242 m_state = normal;
243 }
244}
245
246void
247VEllipseTool::cancel()
248{
249 if( isDragging() )
250 VShapeTool::cancel();
251 else
252 draw();
253
254 m_startAngle = m_endAngle = 0;
255 m_state = normal;
256}
257
258bool
259VEllipseTool::showDialog() const
260{
261 return m_optionsWidget->exec() == TQDialog::Accepted;
262}
263
264void
265VEllipseTool::setup( TDEActionCollection *collection )
266{
267 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
268
269 if( m_action == 0 )
270 {
271 m_action = new TDERadioAction( i18n( "Ellipse Tool" ), "14_ellipse", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
272 m_action->setToolTip( i18n( "Ellipse" ) );
273 m_action->setExclusiveGroup( "shapes" );
274 //m_ownAction = true;
275 }
276}
277
278#include "vellipsetool.moc"
279
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