karbon

vselecttoolbar.cc

00001 /* This file is part of the KDE project
00002    Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
00003    Copyright (C) 2002, The Karbon Developers
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 /* vselecttoolbar.cc */
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( "selection width", "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 
KDE Home | KDE Accessibility Home | Description of Access Keys