00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qlabel.h>
00024
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027
00028 #include "KoUnitWidgets.h"
00029 #include "vselecttoolbar.h"
00030 #include "karbon_view.h"
00031 #include "karbon_part.h"
00032 #include "vselection.h"
00033 #include "vtransformcmd.h"
00034 #include <KoRect.h>
00035
00036 VSelectToolBar::VSelectToolBar( KarbonView *view, const char* name ) : KToolBar( view, name ), m_view( view )
00037 {
00038 setCaption( i18n( "Object Properties" ) );
00039 QLabel *x_label = new QLabel( i18n( "X:" ), this, "kde toolbar widget" );
00040 insertWidget( 0, x_label->width(), x_label );
00041 m_x = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
00042 connect( m_x, SIGNAL( valueChanged( double ) ), this, SLOT( slotXChanged( double ) ) );
00043 insertWidget( 1, m_x->width(), m_x );
00044 QLabel *y_label = new QLabel( i18n( "Y:" ), this, "kde toolbar widget" );
00045 insertWidget( 2, y_label->width(), y_label );
00046 m_y = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
00047 connect( m_y, SIGNAL( valueChanged( double ) ), this, SLOT( slotYChanged( double ) ) );
00048 insertWidget( 3, m_y->width(), m_y );
00049
00050 insertSeparator( 4 );
00051 QLabel *w_label = new QLabel( i18n( "Width:" ), this, "kde toolbar widget" );
00052 insertWidget( 5, w_label->width(), w_label );
00053 m_width = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
00054 connect( m_width, SIGNAL( valueChanged( double ) ), this, SLOT( slotWidthChanged( double ) ) );
00055 insertWidget( 6, m_width->width(), m_width );
00056 QLabel *h_label = new QLabel( i18n( "Height:" ), this, "kde toolbar widget" );
00057 insertWidget( 7, h_label->width(), h_label );
00058 m_height = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
00059 connect( m_height, SIGNAL( valueChanged( double ) ), this, SLOT( slotHeightChanged( double ) ) );
00060 insertWidget( 8, m_height->width(), m_height );
00061
00062 connect( m_view, SIGNAL( selectionChange() ), this, SLOT( slotSelectionChanged() ) );
00063 }
00064
00065 VSelectToolBar::~VSelectToolBar()
00066 {
00067 }
00068
00069 void
00070 VSelectToolBar::slotXChanged( double newval )
00071 {
00072 double dx = newval - m_view->part()->document().selection()->boundingBox().topLeft().x();
00073 m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), dx, 0.0 ), true );
00074 }
00075
00076 void
00077 VSelectToolBar::slotYChanged( double newval )
00078 {
00079 double dy = newval - m_view->part()->document().selection()->boundingBox().topLeft().y();
00080 m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), 0.0, dy ), true );
00081 }
00082
00083 void
00084 VSelectToolBar::slotWidthChanged( double newval )
00085 {
00086 if( newval != 0.0 )
00087 {
00088 double sx = newval / m_view->part()->document().selection()->boundingBox().width();
00089 KoPoint sp = m_view->part()->document().selection()->boundingBox().topLeft();
00090 m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, sx, 1.0 ), true );
00091 }
00092 }
00093
00094 void
00095 VSelectToolBar::slotHeightChanged( double newval )
00096 {
00097 if( newval != 0.0 )
00098 {
00099 double sy = newval / m_view->part()->document().selection()->boundingBox().height();
00100 KoPoint sp = m_view->part()->document().selection()->boundingBox().bottomLeft();
00101 m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, 1.0, sy ), true );
00102 }
00103 }
00104
00105 void
00106 VSelectToolBar::slotSelectionChanged()
00107 {
00108 m_x->blockSignals( true );
00109 m_y->blockSignals( true );
00110 m_width->blockSignals( true );
00111 m_height->blockSignals( true );
00112 KoRect rect = m_view->part()->document().selection()->boundingBox();
00113 m_x->setValue( rect.topLeft().x() );
00114 m_y->setValue( rect.topLeft().y() );
00115 m_width->setValue( rect.width() );
00116 m_height->setValue( rect.height() );
00117 m_x->blockSignals( false );
00118 m_y->blockSignals( false );
00119 m_width->blockSignals( false );
00120 m_height->blockSignals( false );
00121 }
00122
00123 #include "vselecttoolbar.moc"
00124