kspread

kspread_toolbox.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kspread_toolbox.h"
21#include "KoDocumentChild.h"
22
23#include <twin.h>
24
25#include <tqlayout.h>
26#include <tqspinbox.h>
27#include <tqobjectlist.h>
28
29using namespace KSpread;
30
31ToolBox::ToolBox( TQWidget* parent, const char* name )
32 : TQFrame( parent, name, WType_TopLevel | WStyle_Tool )
33{
34 KWin::setType( winId(), NET::Tool );
35
36 setFrameShape( Panel );
37 setFrameShadow( Raised );
38
39 m_layout = new TQVBoxLayout( this, 2, 2 );
40 // m_layout->addSpacing( 12 );
41}
42
43void ToolBox::setEnabled( bool enable )
44{
45 if ( enable )
46 {
47 TQObjectList clo = childrenListObject();
48 if ( !clo.isEmpty() )
49 {
50 TQObjectListIt it( clo );
51 TQWidget *w;
52 while( (w=(TQWidget *)it.current()) != 0 )
53 {
54 ++it;
55 if ( w->isWidgetType() )
56 w->setEnabled( true );
57 }
58 }
59 }
60 else
61 {
62 if ( focusWidget() == this )
63 focusNextPrevChild( true );
64 TQObjectList clo = childrenListObject();
65 if ( !clo.isEmpty() )
66 {
67 TQObjectListIt it( clo );
68 TQWidget *w;
69 while( (w=(TQWidget *)it.current()) != 0 )
70 {
71 ++it;
72 if ( w->isWidgetType() )
73 {
74 w->setEnabled( false );
75 // w->clearWState( WState_ForceDisabled );
76 }
77 }
78 }
79 }
80}
81
82/*
83void ToolBox::paintEvent( TQPaintEvent* ev )
84{
85 TQPainter painter;
86 painter.begin( this );
87
88 painter.fillRect( 0, 0, width(), 12, darkBlue );
89
90 painter.end();
91
92 TQFrame::paintEvent( ev );
93}
94*/
95
96void ToolBox::childEvent( TQChildEvent* ev )
97{
98 if ( ev->inserted() && ev->child()->isWidgetType() )
99 m_layout->addWidget( (TQWidget*)ev->child() );
100 resize( sizeHint() );
101}
102
103void ToolBox::mousePressEvent( TQMouseEvent* ev )
104{
105 m_startPos = geometry().topLeft();
106 m_mousePos = ev->globalPos();
107}
108
109void ToolBox::mouseMoveEvent( TQMouseEvent* ev )
110{
111 setGeometry( m_startPos.x() - m_mousePos.x() + ev->globalPos().x(),
112 m_startPos.y() - m_mousePos.y() + ev->globalPos().y(),
113 width(), height() );
114}
115
116// ---------------------------------------------
117
118KoTransformToolBox::KoTransformToolBox( KoDocumentChild* ch, TQWidget* parent, const char* name )
119 : ToolBox( parent, name )
120{
121 m_child = 0;
122
123 m_rotation = new TQSpinBox( 0, 360, 5, this );
124 m_rotation->setSuffix( " deg" );
125 m_scale = new TQSpinBox( 10, 400, 10, this );
126 m_scale->setSuffix( "%" );
127 m_shearX = new TQSpinBox( -100, 100, 1, this );
128 m_shearX->setSuffix( " px" );
129 m_shearY = new TQSpinBox( -100, 100, 1, this );
130 m_shearY->setSuffix( " px" );
131
132 setDocumentChild( ch );
133
134 connect( m_rotation, TQ_SIGNAL( valueChanged( int ) ),
135 this, TQ_SLOT( slotRotationChanged( int ) ) );
136 connect( m_scale, TQ_SIGNAL( valueChanged( int ) ),
137 this, TQ_SLOT( slotScalingChanged( int ) ) );
138 connect( m_shearX, TQ_SIGNAL( valueChanged( int ) ),
139 this, TQ_SLOT( slotXShearingChanged( int ) ) );
140 connect( m_shearY, TQ_SIGNAL( valueChanged( int ) ),
141 this, TQ_SLOT( slotYShearingChanged( int ) ) );
142}
143
144void KoTransformToolBox::setDocumentChild( KoDocumentChild* ch )
145{
146 if ( m_child == ch )
147 return;
148
149 m_child = ch;
150
151 if ( m_child )
152 {
153 setRotation( m_child->rotation() );
154 setScaling( m_child->xScaling() );
155 setXShearing( m_child->xShearing() );
156 setYShearing( m_child->yShearing() );
157 }
158}
159
160double KoTransformToolBox::rotation() const
161{
162 return m_rotation->text().toDouble();
163}
164
165double KoTransformToolBox::scaling() const
166{
167 return m_scale->text().toDouble() / 100.0;
168}
169
170double KoTransformToolBox::xShearing() const
171{
172 return m_shearX->text().toDouble() / 10.0;
173}
174
175double KoTransformToolBox::yShearing() const
176{
177 return m_shearY->text().toDouble() / 10.0;
178}
179
180void KoTransformToolBox::slotRotationChanged( int v )
181{
182 if ( m_child )
183 m_child->setRotation( double( v ) );
184
185 emit rotationChanged( double( v ) );
186}
187
188void KoTransformToolBox::slotScalingChanged( int v )
189{
190 if ( m_child )
191 m_child->setScaling( double( v ) / 100.0, double( v ) / 100.0 );
192
193 emit scalingChanged( double( v ) / 100.0 );
194}
195
196void KoTransformToolBox::slotXShearingChanged( int v )
197{
198 if ( m_child )
199 m_child->setShearing( double( v ) / 10.0, m_child->yShearing() );
200
201 emit xShearingChanged( double( v ) / 10.0 );
202}
203
204void KoTransformToolBox::slotYShearingChanged( int v )
205{
206 if ( m_child )
207 m_child->setShearing( m_child->xShearing(), double( v ) / 10.0 );
208
209 emit yShearingChanged( double( v ) / 10.0 );
210}
211
212void KoTransformToolBox::setRotation( double v )
213{
214 m_rotation->setValue( int( v ) );
215}
216
217void KoTransformToolBox::setScaling( double v )
218{
219 m_scale->setValue( int( v * 100.0 ) );
220}
221
222void KoTransformToolBox::setXShearing( double v )
223{
224 m_shearX->setValue( int( v * 10.0 ) );
225}
226
227void KoTransformToolBox::setYShearing( double v )
228{
229 m_shearY->setValue( int( v * 10.0 ) );
230}
231
232#include "kspread_toolbox.moc"
The KSpread namespace.
Definition commands.h:39