karbon

vroundrecttool.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 <knuminput.h>
25
26#include <karbon_view.h>
27#include <karbon_part.h>
28#include <shapes/vrectangle.h>
29#include "vroundrecttool.h"
30#include "KoUnitWidgets.h"
31
32#include <kgenericfactory.h>
33
34VRoundRectTool::VRoundRectOptionsWidget::VRoundRectOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name )
35 : KDialogBase( parent, name, true, i18n( "Insert Round Rect" ), Ok | Cancel ), m_part( part )
36{
37 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
38 new TQLabel( i18n( "object width", "Width:" ), group );
39
40 KoUnit::Unit unit = KoUnit::U_CM;
41 m_width = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit );
42
43 new TQLabel( i18n( "Height (%1):" ).arg(KoUnit::unitName( m_part->unit() )), group );
44 m_height = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit );
45
46 new TQLabel( i18n( "Edge radius X:" ), group );
47 m_roundx = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit );
48
49 new TQLabel( i18n( "Edge radius Y:" ), group );
50 m_roundy = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit );
51
52 group->setInsideMargin( 4 );
53 group->setInsideSpacing( 2 );
54
55 setMainWidget( group );
56 setFixedSize( baseSize() );
57}
58
59double
60VRoundRectTool::VRoundRectOptionsWidget::width() const
61{
62 return m_width->value();
63}
64
65double
66VRoundRectTool::VRoundRectOptionsWidget::height() const
67{
68 return m_height->value();
69}
70
71double
72VRoundRectTool::VRoundRectOptionsWidget::roundx() const
73{
74 return m_roundx->value();
75}
76
77double
78VRoundRectTool::VRoundRectOptionsWidget::roundy() const
79{
80 return m_roundy->value();
81}
82
83void
84VRoundRectTool::VRoundRectOptionsWidget::setWidth( double value )
85{
86 m_width->changeValue( value );
87}
88
89void
90VRoundRectTool::VRoundRectOptionsWidget::setHeight( double value )
91{
92 m_height->changeValue( value );
93}
94
95void
96VRoundRectTool::VRoundRectOptionsWidget::setRoundX( double value )
97{
98 m_roundx->changeValue( value );
99}
100
101void
102VRoundRectTool::VRoundRectOptionsWidget::setRoundY( double value )
103{
104 m_roundy->changeValue( value );
105}
106
107void
108VRoundRectTool::VRoundRectOptionsWidget::refreshUnit ()
109{
110 m_width->setUnit( m_part->unit() );
111 m_height->setUnit( m_part->unit() );
112 m_roundx->setUnit( m_part->unit() );
113 m_roundy->setUnit( m_part->unit() );
114}
115
116VRoundRectTool::VRoundRectTool( KarbonView *view )
117 : VShapeTool( view, "tool_round_rectangle" )
118{
119 // Create config dialog:
120 m_optionsWidget = new VRoundRectOptionsWidget( view->part() );
121 registerTool( this );
122}
123
124VRoundRectTool::~VRoundRectTool()
125{
126 delete( m_optionsWidget );
127}
128
130{
131 m_optionsWidget->refreshUnit();
132}
133
134VPath*
135VRoundRectTool::shape( bool interactive ) const
136{
137 if( interactive )
138 {
139 return
140 new VRectangle(
141 0L,
142 m_p,
143 m_optionsWidget->width(),
144 m_optionsWidget->height(),
145 m_optionsWidget->roundx(),
146 m_optionsWidget->roundy() );
147 }
148 else {
149 return
150 new VRectangle(
151 0L,
152 m_p,
153 m_d1,
154 m_d2,
155 m_optionsWidget->roundx(),
156 m_optionsWidget->roundy() );
157 }
158}
159
160bool
162{
163 return m_optionsWidget->exec() == TQDialog::Accepted;
164}
165
166void
167VRoundRectTool::setup( TDEActionCollection *collection )
168{
169 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
170
171 if( m_action == 0 )
172 {
173 m_action = new TDERadioAction( i18n( "Round Rectangle Tool" ), "14_roundrect", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
174 m_action->setToolTip( i18n( "Round Rectangle" ) );
175 m_action->setExclusiveGroup( "shapes" );
176 //m_ownAction = true;
177 }
178}
179
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