karbon

vselecttoolbar.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/* vselecttoolbar.cpp */
22
23#include <tqlabel.h>
24
25#include <tdelocale.h>
26#include <kdebug.h>
27
28#include "KoUnitWidgets.h"
29#include "vselecttoolbar.h"
30#include "karbon_view.h"
31#include "karbon_part.h"
32#include "vselection.h"
33#include "vtransformcmd.h"
34#include <KoRect.h>
35
36VSelectToolBar::VSelectToolBar( KarbonView *view, const char* name ) : TDEToolBar( view, name ), m_view( view )
37{
38 setCaption( i18n( "Object Properties" ) );
39 TQLabel *x_label = new TQLabel( i18n( "X:" ), this, "tde toolbar widget" );
40 insertWidget( 0, x_label->width(), x_label );
41 m_x = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
42 connect( m_x, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotXChanged( double ) ) );
43 insertWidget( 1, m_x->width(), m_x );
44 TQLabel *y_label = new TQLabel( i18n( "Y:" ), this, "tde toolbar widget" );
45 insertWidget( 2, y_label->width(), y_label );
46 m_y = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
47 connect( m_y, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotYChanged( double ) ) );
48 insertWidget( 3, m_y->width(), m_y );
49
50 insertSeparator( 4 );
51 TQLabel *w_label = new TQLabel( i18n( "selection width", "Width:" ), this, "tde toolbar widget" );
52 insertWidget( 5, w_label->width(), w_label );
53 m_width = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
54 connect( m_width, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotWidthChanged( double ) ) );
55 insertWidget( 6, m_width->width(), m_width );
56 TQLabel *h_label = new TQLabel( i18n( "Height:" ), this, "tde toolbar widget" );
57 insertWidget( 7, h_label->width(), h_label );
58 m_height = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 );
59 connect( m_height, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( slotHeightChanged( double ) ) );
60 insertWidget( 8, m_height->width(), m_height );
61
62 connect( m_view, TQ_SIGNAL( selectionChange() ), this, TQ_SLOT( slotSelectionChanged() ) );
63}
64
65VSelectToolBar::~VSelectToolBar()
66{
67}
68
69void
70VSelectToolBar::slotXChanged( double newval )
71{
72 double dx = newval - m_view->part()->document().selection()->boundingBox().topLeft().x();
73 m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), dx, 0.0 ), true );
74}
75
76void
77VSelectToolBar::slotYChanged( double newval )
78{
79 double dy = newval - m_view->part()->document().selection()->boundingBox().topLeft().y();
80 m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), 0.0, dy ), true );
81}
82
83void
84VSelectToolBar::slotWidthChanged( double newval )
85{
86 if( newval != 0.0 )
87 {
88 double sx = newval / m_view->part()->document().selection()->boundingBox().width();
89 KoPoint sp = m_view->part()->document().selection()->boundingBox().topLeft();
90 m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, sx, 1.0 ), true );
91 }
92}
93
94void
95VSelectToolBar::slotHeightChanged( double newval )
96{
97 if( newval != 0.0 )
98 {
99 double sy = newval / m_view->part()->document().selection()->boundingBox().height();
100 KoPoint sp = m_view->part()->document().selection()->boundingBox().bottomLeft();
101 m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, 1.0, sy ), true );
102 }
103}
104
105void
106VSelectToolBar::slotSelectionChanged()
107{
108 m_x->blockSignals( true );
109 m_y->blockSignals( true );
110 m_width->blockSignals( true );
111 m_height->blockSignals( true );
112 KoRect rect = m_view->part()->document().selection()->boundingBox();
113 m_x->setValue( rect.topLeft().x() );
114 m_y->setValue( rect.topLeft().y() );
115 m_width->setValue( rect.width() );
116 m_height->setValue( rect.height() );
117 m_x->blockSignals( false );
118 m_y->blockSignals( false );
119 m_width->blockSignals( false );
120 m_height->blockSignals( false );
121}
122
123#include "vselecttoolbar.moc"
124