~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to karbon/tools/vellipsetool.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
 
 
21
#include <qgroupbox.h>
 
22
#include <qlabel.h>
 
23
 
 
24
#include <klocale.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
 
 
37
VEllipseOptionsWidget::VEllipseOptionsWidget( KarbonPart *part, QWidget *parent, const char *name )
 
38
        : KDialogBase( parent, name, true, i18n( "Insert Ellipse" ), Ok | Cancel ), m_part( part )
 
39
{
 
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 ) ) );
 
48
 
 
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 );
 
54
 
 
55
        new QLabel( i18n( "Start angle:" ), group );
 
56
        m_startAngle = new KIntSpinBox( group );
 
57
        m_startAngle->setMinValue( 0 );
 
58
        m_startAngle->setMaxValue( 360 );
 
59
 
 
60
        new QLabel( 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
 
 
76
void
 
77
VEllipseOptionsWidget::typeChanged( int type )
 
78
{
 
79
        m_startAngle->setEnabled( type != VEllipse::full );
 
80
        m_endAngle->setEnabled( type != VEllipse::full );
 
81
}
 
82
 
 
83
uint
 
84
VEllipseOptionsWidget::type() const
 
85
{
 
86
        return m_type->currentItem();
 
87
}
 
88
 
 
89
uint
 
90
VEllipseOptionsWidget::startAngle() const
 
91
{
 
92
        return m_startAngle->value();
 
93
}
 
94
 
 
95
uint
 
96
VEllipseOptionsWidget::endAngle() const
 
97
{
 
98
        return m_endAngle->value();
 
99
}
 
100
 
 
101
double
 
102
VEllipseOptionsWidget::width() const
 
103
{
 
104
        return m_width->value();
 
105
}
 
106
 
 
107
double
 
108
VEllipseOptionsWidget::height() const
 
109
{
 
110
        return m_height->value();
 
111
}
 
112
 
 
113
void
 
114
VEllipseOptionsWidget::setWidth( double value )
 
115
{
 
116
        m_width->changeValue( value );
 
117
}
 
118
 
 
119
void
 
120
VEllipseOptionsWidget::setHeight( double value )
 
121
{
 
122
        m_height->changeValue( value );
 
123
}
 
124
 
 
125
void
 
126
VEllipseOptionsWidget::refreshUnit ()
 
127
{
 
128
        m_width->setUnit( m_part->unit() );
 
129
        m_height->setUnit( m_part->unit() );
 
130
}
 
131
 
 
132
VEllipseTool::VEllipseTool( KarbonPart *part )
 
133
        : VShapeTool( part, i18n( "Insert Ellipse" ) )
 
134
{
 
135
        // create config dialog:
 
136
        m_optionsWidget = new VEllipseOptionsWidget( part );
 
137
        registerTool( this );
 
138
 
 
139
        m_startAngle = m_endAngle = 0;
 
140
        m_state = normal;
 
141
}
 
142
 
 
143
VEllipseTool::~VEllipseTool()
 
144
{
 
145
        delete( m_optionsWidget );
 
146
}
 
147
 
 
148
void
 
149
VEllipseTool::refreshUnit()
 
150
{
 
151
    m_optionsWidget->refreshUnit();
 
152
}
 
153
 
 
154
VPath*
 
155
VEllipseTool::shape( bool interactive ) const
 
156
{
 
157
        if( interactive )
 
158
        {
 
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;
 
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
 
 
181
void
 
182
VEllipseTool::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
 
 
209
void
 
210
VEllipseTool::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
 
 
220
void
 
221
VEllipseTool::mouseButtonPress()
 
222
{
 
223
        if( m_state == normal )
 
224
        {
 
225
                VShapeTool::mouseButtonPress();
 
226
                m_center = first();
 
227
        }
 
228
}
 
229
 
 
230
void
 
231
VEllipseTool::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
 
 
246
void
 
247
VEllipseTool::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
 
 
258
bool
 
259
VEllipseTool::showDialog() const
 
260
{
 
261
        return m_optionsWidget->exec() == QDialog::Accepted;
 
262
}
 
263
 
 
264
#include "vellipsetool.moc"
 
265