28#include <KoMainWindow.h>
30#include <KoUnitWidgets.h>
32#include "karbon_part.h"
33#include "karbon_view.h"
35#include "vselection.h"
36#include "vtransformcmd.h"
38#include "vtransformdocker.h"
40VTransformDocker::VTransformDocker(
KarbonPart* part, KarbonView* parent,
const char* )
41 : TQWidget(), m_part ( part ), m_view( parent )
43 setCaption( i18n(
"Transform" ) );
45 TQGridLayout *mainLayout =
new TQGridLayout(
this, 5, 5 );
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") );
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") );
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") );
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") );
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") );
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") );
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") );
97 mainLayout->setRowStretch( 4, 1 );
98 mainLayout->setColStretch( 1, 1 );
99 mainLayout->setColStretch( 3, 1 );
105VTransformDocker::enableSignals(
bool enable )
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() ) );
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() ) );
130VTransformDocker::update()
132 enableSignals(
false );
134 int objcount = m_view->part()->document().selection()->objects().count();
138 KoRect rect = m_view->part()->document().selection()->boundingBox();
140 m_x->changeValue( rect.x() );
141 m_y->changeValue( rect.y() );
142 m_width->changeValue( rect.width() );
143 m_height->changeValue( rect.height() );
147 m_x->changeValue(0.0);
148 m_y->changeValue(0.0);
149 m_width->changeValue(0.0);
150 m_height->changeValue(0.0);
154 m_shearX->changeValue(0.0);
155 m_shearY->changeValue(0.0);
156 m_rotate->setValue(0.0);
158 enableSignals(
true );
162VTransformDocker::translate()
165 double newX = m_x->value();
166 double newY = m_y->value();
168 KoRect rect = m_view->part()->document().selection()->boundingBox();
170 if( rect.x() != newX || rect.y() != newY )
172 VTranslateCmd *cmd =
new VTranslateCmd( &m_view->part()->document(), newX-rect.x(), newY-rect.y(),
false );
173 m_view->part()->addCommand( cmd );
175 m_part->repaintAllViews(
true );
179VTransformDocker::scale()
182 double newW = m_width->value();
183 double newH = m_height->value();
185 KoRect rect = m_view->part()->document().selection()->boundingBox();
187 if( rect.width() != newW || rect.height() != newH )
190 VScaleCmd *cmd =
new VScaleCmd( &m_view->part()->document(), rect.topLeft(), newW/rect.width(), newH/rect.height(),
false );
191 m_view->part()->addCommand( cmd );
193 m_part->repaintAllViews(
true );
197VTransformDocker::setUnit( KoUnit::Unit unit )
199 enableSignals(
false );
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 );
208 enableSignals(
true );
212VTransformDocker::shearX()
214 double shear = m_shearX->value();
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() ) );
230VTransformDocker::shearY()
232 double shear = m_shearY->value();
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() ) );
248VTransformDocker::rotate()
250 double angle = m_rotate->value();
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() ) );
264#include "vtransformdocker.moc"
Keeps track of visual per document properties.