karbon

vpolygontool.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 <tqlabel.h>
22#include <tqgroupbox.h>
23
24#include <kdialogbase.h>
25#include <tdelocale.h>
26#include <KoUnitWidgets.h>
27
28#include <karbon_view.h>
29#include <karbon_part.h>
30#include <shapes/vstar.h>
31#include "vpolygontool.h"
32
33VPolygonTool::VPolygonOptionsWidget::VPolygonOptionsWidget( KarbonView *view, TQWidget* parent, const char* name )
34 : KDialogBase( parent, name, true, i18n( "Insert Polygon" ), Ok | Cancel ), m_view(view)
35{
36 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
37
38 new TQLabel( i18n( "Radius:" ), group );
39 m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM );
40 refreshUnit();
41 new TQLabel( i18n( "Edges:" ), group );
42 m_edges = new KIntSpinBox( group );
43 m_edges->setMinValue( 3 );
44
45 group->setInsideMargin( 4 );
46 group->setInsideSpacing( 2 );
47
48 setMainWidget( group );
49 //setFixedSize( baseSize() );
50}
51
52double
53VPolygonTool::VPolygonOptionsWidget::radius() const
54{
55 return m_radius->value();
56}
57
58uint
59VPolygonTool::VPolygonOptionsWidget::edges() const
60{
61 return m_edges->value();
62}
63
64void
65VPolygonTool::VPolygonOptionsWidget::setRadius( double value )
66{
67 m_radius->changeValue( value );
68}
69
70void
71VPolygonTool::VPolygonOptionsWidget::setEdges( uint value )
72{
73 m_edges->setValue( value );
74}
75
76void
77VPolygonTool::VPolygonOptionsWidget::refreshUnit()
78{
79 m_radius->setUnit( m_view->part()->unit() );
80}
81
82VPolygonTool::VPolygonTool( KarbonView *view )
83 : VShapeTool( view, "tool_polygon", true )
84{
85 // create config dialog:
86 m_optionsWidget = new VPolygonOptionsWidget( view );
87 m_optionsWidget->setEdges( 5 );
88 registerTool( this );
89}
90
91VPolygonTool::~VPolygonTool()
92{
93 delete( m_optionsWidget );
94}
95
96void
97VPolygonTool::refreshUnit()
98{
99 m_optionsWidget->refreshUnit();
100}
101
102void
103VPolygonTool::arrowKeyReleased( TQt::Key key )
104{
105 int change = 0;
106 if( key == TQt::Key_Up )
107 change = 1;
108 else if( key == TQt::Key_Down )
109 change = -1;
110
111 if( change != 0 )
112 {
113 draw();
114
115 m_optionsWidget->setEdges( m_optionsWidget->edges() + change );
116
117 draw();
118 }
119}
120
121VPath*
122VPolygonTool::shape( bool interactive ) const
123{
124 if( interactive )
125 {
126 return
127 new VStar(
128 0L,
129 m_p,
130 m_optionsWidget->radius(),
131 m_optionsWidget->radius(),
132 m_optionsWidget->edges(), 0, 0, 0, VStar::polygon );
133 }
134 else
135 return
136 new VStar(
137 0L,
138 m_p,
139 m_d1, m_d1,
140 m_optionsWidget->edges(),
141 m_d2, 0, 0, VStar::polygon );
142}
143
144bool
145VPolygonTool::showDialog() const
146{
147 return m_optionsWidget->exec() == TQDialog::Accepted;
148}
149
150void
151VPolygonTool::setup( TDEActionCollection *collection )
152{
153 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
154
155 if( m_action == 0 )
156 {
157 TDEShortcut shortcut( TQt::Key_Plus );
158 shortcut.append(TDEShortcut( TQt::Key_F9 ) );
159 m_action = new TDERadioAction( i18n( "Polygon Tool" ), "14_polygon", shortcut, this, TQ_SLOT( activate() ), collection, name() );
160 m_action->setToolTip( i18n( "Polygon" ) );
161 m_action->setExclusiveGroup( "shapes" );
162 //m_ownAction = true;
163 }
164}
165
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