karbon

vtransformdocker.cpp
1/* This file is part of the KDE project
2 Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqlabel.h>
22#include <tqlayout.h>
23#include <tqwidget.h>
24#include <tqwmatrix.h>
25#include <tqtooltip.h>
26
27#include <tdelocale.h>
28#include <KoMainWindow.h>
29#include <KoRect.h>
30#include <KoUnitWidgets.h>
31
32#include "karbon_part.h"
33#include "karbon_view.h"
34
35#include "vselection.h"
36#include "vtransformcmd.h"
37
38#include "vtransformdocker.h"
39
40VTransformDocker::VTransformDocker( KarbonPart* part, KarbonView* parent, const char* /*name*/ )
41 : TQWidget(), m_part ( part ), m_view( parent )
42{
43 setCaption( i18n( "Transform" ) );
44
45 TQGridLayout *mainLayout = new TQGridLayout( this, 5, 5 );
46
47 //X: (TODO: Set 5000 limit to real Karbon14 limit)
48 TQLabel* xLabel = new TQLabel( i18n ( "X:" ), this );
49 mainLayout->addWidget( xLabel, 0, 0 );
50 m_x = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
51 mainLayout->addWidget( m_x, 0, 1 );
52 TQToolTip::add( m_x, i18n("Set x-position of actual selection") );
53
54 //Y: (TODO: Set 5000 limit to real Karbon14 limit)
55 TQLabel* yLabel = new TQLabel( i18n ( "Y:" ), this );
56 mainLayout->addWidget( yLabel, 0, 2 );
57 m_y = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
58 mainLayout->addWidget( m_y, 0, 3 );
59 TQToolTip::add( m_y, i18n("Set y-position of actual selection") );
60
61 //Width: (TODO: Set 5000 limit to real Karbon14 limit)
62 TQLabel* wLabel = new TQLabel( i18n ( "W:" ), this );
63 mainLayout->addWidget( wLabel, 1, 0 );
64 m_width = new KoUnitDoubleSpinBox( this, 0.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
65 mainLayout->addWidget( m_width, 1, 1 );
66 TQToolTip::add( m_width, i18n("Set width of actual selection") );
67
68 //Height: (TODO: Set 5000 limit to real Karbon14 limit)
69 TQLabel* hLabel = new TQLabel( i18n ( "H:" ), this );
70 mainLayout->addWidget( hLabel, 1, 2 );
71 m_height = new KoUnitDoubleSpinBox( this, 0.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
72 mainLayout->addWidget( m_height, 1, 3 );
73 TQToolTip::add( m_height, i18n("Set height of actual selection") );
74
75 //TODO: Add Rotation, Shear
76 //ROTATE: (TODO: Set 5000 limit to real Karbon14 limit)
77 TQLabel* rLabel = new TQLabel( i18n ( "R:" ), this );
78 mainLayout->addWidget( rLabel, 3, 0 );
79 m_rotate = new KDoubleSpinBox( -360.0, 360.0, 1.0, 10.0, 1, this );
80 mainLayout->addWidget( m_rotate, 3, 1 );
81 TQToolTip::add( m_rotate, i18n("Rotate actual selection") );
82
83 //X-Shear: (TODO: Set 5000 limit to real Karbon14 limit)
84 TQLabel* sxLabel = new TQLabel( i18n ( "SX:" ), this );
85 mainLayout->addWidget( sxLabel, 2, 0 );
86 m_shearX = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
87 mainLayout->addWidget( m_shearX, 2, 1 );
88 TQToolTip::add( m_shearX, i18n("Shear actual selection in x-direction") );
89
90 //Y-Shear: (TODO: Set 5000 limit to real Karbon14 limit)
91 TQLabel* syLabel = new TQLabel( i18n ( "SY:" ), this );
92 mainLayout->addWidget( syLabel, 2, 2 );
93 m_shearY = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
94 mainLayout->addWidget( m_shearY, 2, 3 );
95 TQToolTip::add( m_shearY, i18n("Shear actual selection in y-direction") );
96
97 mainLayout->setRowStretch( 4, 1 );
98 mainLayout->setColStretch( 1, 1 );
99 mainLayout->setColStretch( 3, 1 );
100
101 update();
102}
103
104void
105VTransformDocker::enableSignals( bool enable )
106{
107 if( enable )
108 {
109 connect( m_x, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( translate() ) );
110 connect( m_y, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( translate() ) );
111 connect( m_width, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( scale() ) );
112 connect( m_height, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( scale() ) );
113 connect( m_shearX, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearX() ) );
114 connect( m_shearY, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearY() ) );
115 connect( m_rotate, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( rotate() ) );
116 }
117 else
118 {
119 disconnect( m_x, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( translate() ) );
120 disconnect( m_y, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( translate() ) );
121 disconnect( m_width, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( scale() ) );
122 disconnect( m_height, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( scale() ) );
123 disconnect( m_shearX, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearX() ) );
124 disconnect( m_shearY, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearY() ) );
125 disconnect( m_rotate, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( rotate() ) );
126 }
127}
128
129void
130VTransformDocker::update()
131{
132 enableSignals( false );
133
134 int objcount = m_view->part()->document().selection()->objects().count();
135 if ( objcount>0 )
136 {
137 setEnabled( true );
138 KoRect rect = m_view->part()->document().selection()->boundingBox();
139
140 m_x->changeValue( rect.x() );
141 m_y->changeValue( rect.y() );
142 m_width->changeValue( rect.width() );
143 m_height->changeValue( rect.height() );
144 }
145 else
146 {
147 m_x->changeValue(0.0);
148 m_y->changeValue(0.0);
149 m_width->changeValue(0.0);
150 m_height->changeValue(0.0);
151 setEnabled( false );
152 }
153
154 m_shearX->changeValue(0.0);
155 m_shearY->changeValue(0.0);
156 m_rotate->setValue(0.0);
157
158 enableSignals( true );
159}
160
161void
162VTransformDocker::translate()
163{
164 //FIXME: Needs an appropriate transform command which takes absolute values of object size
165 double newX = m_x->value();
166 double newY = m_y->value();
167
168 KoRect rect = m_view->part()->document().selection()->boundingBox();
169
170 if( rect.x() != newX || rect.y() != newY )
171 {
172 VTranslateCmd *cmd = new VTranslateCmd( &m_view->part()->document(), newX-rect.x(), newY-rect.y(), false );
173 m_view->part()->addCommand( cmd );
174 }
175 m_part->repaintAllViews( true );
176}
177
178void
179VTransformDocker::scale()
180{
181 //FIXME: Needs an appropriate transform command which takes absolute values of object size
182 double newW = m_width->value();
183 double newH = m_height->value();
184
185 KoRect rect = m_view->part()->document().selection()->boundingBox();
186
187 if( rect.width() != newW || rect.height() != newH )
188 {
189
190 VScaleCmd *cmd = new VScaleCmd( &m_view->part()->document(), rect.topLeft(), newW/rect.width(), newH/rect.height(), false );
191 m_view->part()->addCommand( cmd );
192 }
193 m_part->repaintAllViews( true );
194}
195
196void
197VTransformDocker::setUnit( KoUnit::Unit unit )
198{
199 enableSignals( false );
200
201 m_x->setUnit( unit );
202 m_y->setUnit( unit );
203 m_width->setUnit( unit );
204 m_height->setUnit( unit );
205 m_shearX->setUnit( unit );
206 m_shearY->setUnit( unit );
207
208 enableSignals( true );
209}
210
211void
212VTransformDocker::shearX()
213{
214 double shear = m_shearX->value();
215
216 if( shear != 0.0 )
217 {
218 KoRect rect = m_view->part()->document().selection()->boundingBox();
219 shear /= double(rect.width()*0.5);
220 VShearCmd *cmd = new VShearCmd( &m_view->part()->document(), rect.center(), shear, 0 );
221 m_view->part()->addCommand( cmd );
222 m_part->repaintAllViews( true );
223 disconnect( m_shearX, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearX() ) );
224 m_shearX->changeValue(0.0);
225 connect( m_shearX, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearX() ) );
226 }
227}
228
229void
230VTransformDocker::shearY()
231{
232 double shear = m_shearY->value();
233
234 if( shear != 0.0 )
235 {
236 KoRect rect = m_view->part()->document().selection()->boundingBox();
237 shear /= double(rect.height()*0.5);
238 VShearCmd *cmd = new VShearCmd( &m_view->part()->document(), rect.center(), 0, shear );
239 m_view->part()->addCommand( cmd );
240 m_part->repaintAllViews( true );
241 disconnect( m_shearY, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearY() ) );
242 m_shearY->changeValue(0.0);
243 connect( m_shearY, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( shearY() ) );
244 }
245}
246
247void
248VTransformDocker::rotate()
249{
250 double angle = m_rotate->value();
251
252 if( angle != 0.0 )
253 {
254 KoPoint center = m_view->part()->document().selection()->boundingBox().center();
255 VRotateCmd *cmd = new VRotateCmd( &m_view->part()->document(), center, angle );
256 m_view->part()->addCommand( cmd );
257 m_part->repaintAllViews( true );
258 disconnect( m_rotate, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( rotate() ) );
259 m_rotate->setValue(0.0);
260 connect( m_rotate, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( rotate() ) );
261 }
262}
263
264#include "vtransformdocker.moc"
265
Keeps track of visual per document properties.
Definition karbon_part.h:46