karbon

vsinustool.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#include <tqlayout.h>
24
25#include <tdelocale.h>
26#include <knuminput.h>
27
28#include <karbon_view.h>
29#include <karbon_part.h>
30#include <shapes/vsinus.h>
31#include "vsinustool.h"
32#include "KoUnitWidgets.h"
33
34
35VSinusTool::VSinusOptionsWidget::VSinusOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name )
36 : KDialogBase( parent, name, true, i18n( "Insert Sinus" ), Ok | Cancel ), m_part( part )
37{
38 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
39
40 // add width/height-input:
41 m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group );
42 m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
43 m_heightLabel = new TQLabel( i18n( "Height:" ), group );
44 m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
45
46 refreshUnit();
47
48 new TQLabel( i18n( "Periods:" ), group );
49 m_periods = new KIntSpinBox( group );
50 m_periods->setMinValue( 1 );
51
52 group->setInsideMargin( 4 );
53 group->setInsideSpacing( 2 );
54
55 setMainWidget( group );
56 setFixedSize( baseSize() );
57}
58
59double
60VSinusTool::VSinusOptionsWidget::width() const
61{
62 return m_width->value();
63}
64
65double
66VSinusTool::VSinusOptionsWidget::height() const
67{
68 return m_height->value();
69}
70
71uint
72VSinusTool::VSinusOptionsWidget::periods() const
73{
74 return m_periods->value();
75}
76
77void
78VSinusTool::VSinusOptionsWidget::setWidth( double value )
79{
80 m_width->changeValue( value );
81}
82
83void
84VSinusTool::VSinusOptionsWidget::setHeight( double value )
85{
86 m_height->changeValue( value );
87}
88
89void
90VSinusTool::VSinusOptionsWidget::setPeriods( uint value )
91{
92 m_periods->setValue( value );
93}
94
95void
96VSinusTool::VSinusOptionsWidget::refreshUnit ()
97{
98 m_width->setUnit( m_part->unit() );
99 m_height->setUnit( m_part->unit() );
100}
101
102VSinusTool::VSinusTool( KarbonView *view )
103 : VShapeTool( view, "tool_sinus" )
104{
105 // create config widget:
106 m_optionsWidget = new VSinusOptionsWidget( view->part() );
107 m_optionsWidget->setPeriods( 1 );
108 registerTool( this );
109}
110
111VSinusTool::~VSinusTool()
112{
113 delete( m_optionsWidget );
114}
115
116void
118{
119 m_optionsWidget->refreshUnit();
120}
121
122VPath*
123VSinusTool::shape( bool interactive ) const
124{
125 if( interactive )
126 return
127 new VSinus(
128 0L,
129 m_p,
130 m_optionsWidget->width(),
131 m_optionsWidget->height(),
132 m_optionsWidget->periods() );
133 else
134 return
135 new VSinus(
136 0L,
137 m_p,
138 m_d1,
139 m_d2,
140 m_optionsWidget->periods() );
141}
142
143bool
145{
146 return m_optionsWidget->exec() == TQDialog::Accepted;
147}
148
149void
150VSinusTool::setup( TDEActionCollection *collection )
151{
152 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
153
154 if( m_action == 0 )
155 {
156 m_action = new TDERadioAction( i18n( "Sinus Tool" ), "14_sinus", TQt::SHIFT+TQt::Key_S, this, TQ_SLOT( activate() ), collection, name() );
157 m_action->setToolTip( i18n( "Sinus" ) );
158 m_action->setExclusiveGroup( "shapes" );
159 //m_ownAction = true;
160 }
161}
162
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