karbon

vrectangletool.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#include <tqlabel.h>
21#include <tqgroupbox.h>
22
23#include <tdelocale.h>
24#include <knuminput.h>
25
26#include <karbon_view.h>
27#include <karbon_part.h>
28#include <shapes/vrectangle.h>
29#include "vrectangletool.h"
30#include <KoUnitWidgets.h>
31
32
33VRectangleTool::VRectangleOptionsWidget::VRectangleOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name )
34 : KDialogBase( parent, name, true, i18n( "Insert Rectangle" ), Ok | Cancel ), m_part( part )
35{
36 TQGroupBox *group = new TQGroupBox( 2, TQt::Horizontal, i18n( "Properties" ), this );
37 // add width/height-input:
38 m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group );
39 m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
40
41 m_heightLabel = new TQLabel( i18n( "Height:" ), group );
42 m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
43
44 refreshUnit();
45
46 group->setInsideMargin( 4 );
47 group->setInsideSpacing( 2 );
48
49 setMainWidget( group );
50 //setFixedSize( baseSize() );
51}
52
53double
54VRectangleTool::VRectangleOptionsWidget::width() const
55{
56 return m_width->value();
57}
58
59double
60VRectangleTool::VRectangleOptionsWidget::height() const
61{
62 return m_height->value();
63}
64
65void
66VRectangleTool::VRectangleOptionsWidget::setWidth( double value )
67{
68 m_width->setValue( value );
69}
70
71void
72VRectangleTool::VRectangleOptionsWidget::setHeight( double value )
73{
74 m_height->setValue( value );
75}
76
77void
78VRectangleTool::VRectangleOptionsWidget::refreshUnit()
79{
80 m_width->setUnit( m_part->unit() );
81 m_height->setUnit( m_part->unit() );
82}
83
84VRectangleTool::VRectangleTool( KarbonView *view )
85 : VShapeTool( view, "tool_rectangle" )
86{
87 // Create config dialog:
88 m_optionWidget = new VRectangleOptionsWidget( view->part() );
89 registerTool( this );
90}
91
92VRectangleTool::~VRectangleTool()
93{
94 delete( m_optionWidget );
95}
96
97void
99{
100 m_optionWidget->refreshUnit();
101}
102
103VPath *
104VRectangleTool::shape( bool interactive ) const
105{
106 if( interactive )
107 {
108 return
109 new VRectangle(
110 0L,
111 m_p,
112 m_optionWidget->width(),
113 m_optionWidget->height() );
114 }
115 else
116 return
117 new VRectangle(
118 0L,
119 m_p,
120 m_d1,
121 m_d2 );
122}
123
124bool
126{
127 return m_optionWidget->exec() == TQDialog::Accepted;
128}
129
130void
131VRectangleTool::setup( TDEActionCollection *collection )
132{
133 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
134
135 if( m_action == 0 )
136 {
137 m_action = new TDERadioAction( i18n( "Rectangle Tool" ), "14_rectangle", TQt::Key_Plus+TQt::Key_F9, this, TQ_SLOT( activate() ), collection, name() );
138 m_action->setToolTip( i18n( "Rectangle" ) );
139 m_action->setExclusiveGroup( "shapes" );
140 //m_ownAction = true;
141 }
142}
143
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