1
/* This file is part of the KDE project
2
Copyright (C) 2001, 2002, 2003 The Karbon Developers
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.
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.
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., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
21
#include <qgroupbox.h>
25
#include "koUnitWidgets.h"
27
#include <kcombobox.h>
28
#include <knuminput.h>
30
#include <karbon_view.h>
31
#include <karbon_part.h>
32
#include <shapes/vellipse.h>
33
#include "vellipsetool.h"
37
VEllipseOptionsWidget::VEllipseOptionsWidget( KarbonPart *part, QWidget *parent, const char *name )
38
: KDialogBase( parent, name, true, i18n( "Insert Ellipse" ), Ok | Cancel ), m_part( part )
40
QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
41
new QLabel( 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, SIGNAL( activated( int ) ), this, SLOT( typeChanged( int ) ) );
49
// add width/height-input:
50
m_widthLabel = new QLabel( i18n( "Width:" ), group );
51
m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
52
m_heightLabel = new QLabel( i18n( "Height:" ), group );
53
m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
55
new QLabel( i18n( "Start angle:" ), group );
56
m_startAngle = new KIntSpinBox( group );
57
m_startAngle->setMinValue( 0 );
58
m_startAngle->setMaxValue( 360 );
60
new QLabel( i18n( "End angle:" ), group );
61
m_endAngle = new KIntSpinBox( group );
62
m_endAngle->setMinValue( 0 );
63
m_endAngle->setMaxValue( 360 );
65
typeChanged( VEllipse::full );
69
group->setInsideMargin( 4 );
70
group->setInsideSpacing( 2 );
72
setMainWidget( group );
73
setFixedSize( baseSize() );
77
VEllipseOptionsWidget::typeChanged( int type )
79
m_startAngle->setEnabled( type != VEllipse::full );
80
m_endAngle->setEnabled( type != VEllipse::full );
84
VEllipseOptionsWidget::type() const
86
return m_type->currentItem();
90
VEllipseOptionsWidget::startAngle() const
92
return m_startAngle->value();
96
VEllipseOptionsWidget::endAngle() const
98
return m_endAngle->value();
102
VEllipseOptionsWidget::width() const
104
return m_width->value();
108
VEllipseOptionsWidget::height() const
110
return m_height->value();
114
VEllipseOptionsWidget::setWidth( double value )
116
m_width->changeValue( value );
120
VEllipseOptionsWidget::setHeight( double value )
122
m_height->changeValue( value );
126
VEllipseOptionsWidget::refreshUnit ()
128
m_width->setUnit( m_part->unit() );
129
m_height->setUnit( m_part->unit() );
132
VEllipseTool::VEllipseTool( KarbonPart *part )
133
: VShapeTool( part, i18n( "Insert Ellipse" ) )
135
// create config dialog:
136
m_optionsWidget = new VEllipseOptionsWidget( part );
137
registerTool( this );
139
m_startAngle = m_endAngle = 0;
143
VEllipseTool::~VEllipseTool()
145
delete( m_optionsWidget );
149
VEllipseTool::refreshUnit()
151
m_optionsWidget->refreshUnit();
155
VEllipseTool::shape( bool interactive ) const
159
double d1 = KoUnit::ptFromUnit( m_optionsWidget->width(), view()->part()->unit() ) / 2.0;
160
double d2 = KoUnit::ptFromUnit( m_optionsWidget->height(), view()->part()->unit() ) / 2.0;
164
KoPoint( m_center.x() - d1, m_center.y() - d2 ),
166
(VEllipse::VEllipseType)m_optionsWidget->type(),
167
m_optionsWidget->startAngle(),
168
m_optionsWidget->endAngle() );
174
KoPoint( m_center.x() - m_d1, m_center.y() - m_d2 ),
177
(VEllipse::VEllipseType)m_optionsWidget->type(),
178
m_startAngle, m_endAngle );
182
VEllipseTool::mouseMove()
184
if( m_state == normal )
191
if( m_state == startangle )
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;
200
m_endAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() );
201
m_endAngle = ( m_endAngle / VGlobal::pi_2 ) * 90.0;
210
VEllipseTool::mouseDragRelease()
212
if( m_optionsWidget->type() == VEllipse::full )
213
VShapeTool::mouseDragRelease();
215
if( m_state == normal )
216
if( m_optionsWidget->type() != VEllipse::full )
217
m_state = startangle;
221
VEllipseTool::mouseButtonPress()
223
if( m_state == normal )
225
VShapeTool::mouseButtonPress();
231
VEllipseTool::mouseButtonRelease()
233
if( m_optionsWidget->type() == VEllipse::full || m_state == normal )
234
VShapeTool::mouseButtonRelease();
236
if( m_state == startangle )
238
else if( m_state == endangle )
240
VShapeTool::mouseDragRelease();
241
m_startAngle = m_endAngle = 0;
247
VEllipseTool::cancel()
250
VShapeTool::cancel();
254
m_startAngle = m_endAngle = 0;
259
VEllipseTool::showDialog() const
261
return m_optionsWidget->exec() == QDialog::Accepted;
264
#include "vellipsetool.moc"