00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qwidget.h>
00024 #include <qwmatrix.h>
00025 #include <qtooltip.h>
00026
00027 #include <klocale.h>
00028 #include <KoMainWindow.h>
00029 #include <KoRect.h>
00030 #include <KoUnitWidgets.h>
00031
00032 #include "karbon_part.h"
00033 #include "karbon_view.h"
00034
00035 #include "vselection.h"
00036 #include "vtransformcmd.h"
00037
00038 #include "vtransformdocker.h"
00039
00040 VTransformDocker::VTransformDocker( KarbonPart* part, KarbonView* parent, const char* )
00041 : QWidget(), m_part ( part ), m_view( parent )
00042 {
00043 setCaption( i18n( "Transform" ) );
00044
00045 QGridLayout *mainLayout = new QGridLayout( this, 5, 5 );
00046
00047
00048 QLabel* xLabel = new QLabel( i18n ( "X:" ), this );
00049 mainLayout->addWidget( xLabel, 0, 0 );
00050 m_x = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00051 mainLayout->addWidget( m_x, 0, 1 );
00052 QToolTip::add( m_x, i18n("Set x-position of actual selection") );
00053
00054
00055 QLabel* yLabel = new QLabel( i18n ( "Y:" ), this );
00056 mainLayout->addWidget( yLabel, 0, 2 );
00057 m_y = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00058 mainLayout->addWidget( m_y, 0, 3 );
00059 QToolTip::add( m_y, i18n("Set y-position of actual selection") );
00060
00061
00062 QLabel* wLabel = new QLabel( i18n ( "W:" ), this );
00063 mainLayout->addWidget( wLabel, 1, 0 );
00064 m_width = new KoUnitDoubleSpinBox( this, 0.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00065 mainLayout->addWidget( m_width, 1, 1 );
00066 QToolTip::add( m_width, i18n("Set width of actual selection") );
00067
00068
00069 QLabel* hLabel = new QLabel( i18n ( "H:" ), this );
00070 mainLayout->addWidget( hLabel, 1, 2 );
00071 m_height = new KoUnitDoubleSpinBox( this, 0.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00072 mainLayout->addWidget( m_height, 1, 3 );
00073 QToolTip::add( m_height, i18n("Set height of actual selection") );
00074
00075
00076
00077 QLabel* rLabel = new QLabel( i18n ( "R:" ), this );
00078 mainLayout->addWidget( rLabel, 3, 0 );
00079 m_rotate = new KDoubleSpinBox( -360.0, 360.0, 1.0, 10.0, 1, this );
00080 mainLayout->addWidget( m_rotate, 3, 1 );
00081 QToolTip::add( m_rotate, i18n("Rotate actual selection") );
00082
00083
00084 QLabel* sxLabel = new QLabel( i18n ( "SX:" ), this );
00085 mainLayout->addWidget( sxLabel, 2, 0 );
00086 m_shearX = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00087 mainLayout->addWidget( m_shearX, 2, 1 );
00088 QToolTip::add( m_shearX, i18n("Shear actual selection in x-direction") );
00089
00090
00091 QLabel* syLabel = new QLabel( i18n ( "SY:" ), this );
00092 mainLayout->addWidget( syLabel, 2, 2 );
00093 m_shearY = new KoUnitDoubleSpinBox( this, -5000.0, 5000.0, 1.0, 10.0, m_part->unit(), 1 );
00094 mainLayout->addWidget( m_shearY, 2, 3 );
00095 QToolTip::add( m_shearY, i18n("Shear actual selection in y-direction") );
00096
00097 mainLayout->setRowStretch( 4, 1 );
00098 mainLayout->setColStretch( 1, 1 );
00099 mainLayout->setColStretch( 3, 1 );
00100
00101 update();
00102 }
00103
00104 void
00105 VTransformDocker::enableSignals( bool enable )
00106 {
00107 if( enable )
00108 {
00109 connect( m_x, SIGNAL( valueChanged( double ) ), this, SLOT( translate() ) );
00110 connect( m_y, SIGNAL( valueChanged( double ) ), this, SLOT( translate() ) );
00111 connect( m_width, SIGNAL( valueChanged( double ) ), this, SLOT( scale() ) );
00112 connect( m_height, SIGNAL( valueChanged( double ) ), this, SLOT( scale() ) );
00113 connect( m_shearX, SIGNAL( valueChanged( double ) ), this, SLOT( shearX() ) );
00114 connect( m_shearY, SIGNAL( valueChanged( double ) ), this, SLOT( shearY() ) );
00115 connect( m_rotate, SIGNAL( valueChanged( double ) ), this, SLOT( rotate() ) );
00116 }
00117 else
00118 {
00119 disconnect( m_x, SIGNAL( valueChanged( double ) ), this, SLOT( translate() ) );
00120 disconnect( m_y, SIGNAL( valueChanged( double ) ), this, SLOT( translate() ) );
00121 disconnect( m_width, SIGNAL( valueChanged( double ) ), this, SLOT( scale() ) );
00122 disconnect( m_height, SIGNAL( valueChanged( double ) ), this, SLOT( scale() ) );
00123 disconnect( m_shearX, SIGNAL( valueChanged( double ) ), this, SLOT( shearX() ) );
00124 disconnect( m_shearY, SIGNAL( valueChanged( double ) ), this, SLOT( shearY() ) );
00125 disconnect( m_rotate, SIGNAL( valueChanged( double ) ), this, SLOT( rotate() ) );
00126 }
00127 }
00128
00129 void
00130 VTransformDocker::update()
00131 {
00132 enableSignals( false );
00133
00134 int objcount = m_view->part()->document().selection()->objects().count();
00135 if ( objcount>0 )
00136 {
00137 setEnabled( true );
00138 KoRect rect = m_view->part()->document().selection()->boundingBox();
00139
00140 m_x->changeValue( rect.x() );
00141 m_y->changeValue( rect.y() );
00142 m_width->changeValue( rect.width() );
00143 m_height->changeValue( rect.height() );
00144 }
00145 else
00146 {
00147 m_x->changeValue(0.0);
00148 m_y->changeValue(0.0);
00149 m_width->changeValue(0.0);
00150 m_height->changeValue(0.0);
00151 setEnabled( false );
00152 }
00153
00154 m_shearX->changeValue(0.0);
00155 m_shearY->changeValue(0.0);
00156 m_rotate->setValue(0.0);
00157
00158 enableSignals( true );
00159 }
00160
00161 void
00162 VTransformDocker::translate()
00163 {
00164
00165 double newX = m_x->value();
00166 double newY = m_y->value();
00167
00168 KoRect rect = m_view->part()->document().selection()->boundingBox();
00169
00170 if( rect.x() != newX || rect.y() != newY )
00171 {
00172 VTranslateCmd *cmd = new VTranslateCmd( &m_view->part()->document(), newX-rect.x(), newY-rect.y(), false );
00173 m_view->part()->addCommand( cmd );
00174 }
00175 m_part->repaintAllViews( true );
00176 }
00177
00178 void
00179 VTransformDocker::scale()
00180 {
00181
00182 double newW = m_width->value();
00183 double newH = m_height->value();
00184
00185 KoRect rect = m_view->part()->document().selection()->boundingBox();
00186
00187 if( rect.width() != newW || rect.height() != newH )
00188 {
00189
00190 VScaleCmd *cmd = new VScaleCmd( &m_view->part()->document(), rect.topLeft(), newW/rect.width(), newH/rect.height(), false );
00191 m_view->part()->addCommand( cmd );
00192 }
00193 m_part->repaintAllViews( true );
00194 }
00195
00196 void
00197 VTransformDocker::setUnit( KoUnit::Unit unit )
00198 {
00199 enableSignals( false );
00200
00201 m_x->setUnit( unit );
00202 m_y->setUnit( unit );
00203 m_width->setUnit( unit );
00204 m_height->setUnit( unit );
00205 m_shearX->setUnit( unit );
00206 m_shearY->setUnit( unit );
00207
00208 enableSignals( true );
00209 }
00210
00211 void
00212 VTransformDocker::shearX()
00213 {
00214 double shear = m_shearX->value();
00215
00216 if( shear != 0.0 )
00217 {
00218 KoRect rect = m_view->part()->document().selection()->boundingBox();
00219 shear /= double(rect.width()*0.5);
00220 VShearCmd *cmd = new VShearCmd( &m_view->part()->document(), rect.center(), shear, 0 );
00221 m_view->part()->addCommand( cmd );
00222 m_part->repaintAllViews( true );
00223 disconnect( m_shearX, SIGNAL( valueChanged( double ) ), this, SLOT( shearX() ) );
00224 m_shearX->changeValue(0.0);
00225 connect( m_shearX, SIGNAL( valueChanged( double ) ), this, SLOT( shearX() ) );
00226 }
00227 }
00228
00229 void
00230 VTransformDocker::shearY()
00231 {
00232 double shear = m_shearY->value();
00233
00234 if( shear != 0.0 )
00235 {
00236 KoRect rect = m_view->part()->document().selection()->boundingBox();
00237 shear /= double(rect.height()*0.5);
00238 VShearCmd *cmd = new VShearCmd( &m_view->part()->document(), rect.center(), 0, shear );
00239 m_view->part()->addCommand( cmd );
00240 m_part->repaintAllViews( true );
00241 disconnect( m_shearY, SIGNAL( valueChanged( double ) ), this, SLOT( shearY() ) );
00242 m_shearY->changeValue(0.0);
00243 connect( m_shearY, SIGNAL( valueChanged( double ) ), this, SLOT( shearY() ) );
00244 }
00245 }
00246
00247 void
00248 VTransformDocker::rotate()
00249 {
00250 double angle = m_rotate->value();
00251
00252 if( angle != 0.0 )
00253 {
00254 KoPoint center = m_view->part()->document().selection()->boundingBox().center();
00255 VRotateCmd *cmd = new VRotateCmd( &m_view->part()->document(), center, angle );
00256 m_view->part()->addCommand( cmd );
00257 m_part->repaintAllViews( true );
00258 disconnect( m_rotate, SIGNAL( valueChanged( double ) ), this, SLOT( rotate() ) );
00259 m_rotate->setValue(0.0);
00260 connect( m_rotate, SIGNAL( valueChanged( double ) ), this, SLOT( rotate() ) );
00261 }
00262 }
00263
00264 #include "vtransformdocker.moc"
00265