00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kspread_toolbox.h"
00021 #include "KoDocumentChild.h"
00022
00023 #include <kwin.h>
00024
00025 #include <qlayout.h>
00026 #include <qspinbox.h>
00027 #include <qobjectlist.h>
00028
00029 using namespace KSpread;
00030
00031 ToolBox::ToolBox( QWidget* parent, const char* name )
00032 : QFrame( parent, name, WType_TopLevel | WStyle_Tool )
00033 {
00034 KWin::setType( winId(), NET::Tool );
00035
00036 setFrameShape( Panel );
00037 setFrameShadow( Raised );
00038
00039 m_layout = new QVBoxLayout( this, 2, 2 );
00040
00041 }
00042
00043 void ToolBox::setEnabled( bool enable )
00044 {
00045 if ( enable )
00046 {
00047 if ( children() )
00048 {
00049 QObjectListIt it( *children() );
00050 QWidget *w;
00051 while( (w=(QWidget *)it.current()) != 0 )
00052 {
00053 ++it;
00054 if ( w->isWidgetType() )
00055 w->setEnabled( TRUE );
00056 }
00057 }
00058 }
00059 else
00060 {
00061 if ( focusWidget() == this )
00062 focusNextPrevChild( TRUE );
00063 if ( children() )
00064 {
00065 QObjectListIt it( *children() );
00066 QWidget *w;
00067 while( (w=(QWidget *)it.current()) != 0 )
00068 {
00069 ++it;
00070 if ( w->isWidgetType() )
00071 {
00072 w->setEnabled( FALSE );
00073
00074 }
00075 }
00076 }
00077 }
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 void ToolBox::childEvent( QChildEvent* ev )
00095 {
00096 if ( ev->inserted() && ev->child()->isWidgetType() )
00097 m_layout->addWidget( (QWidget*)ev->child() );
00098 resize( sizeHint() );
00099 }
00100
00101 void ToolBox::mousePressEvent( QMouseEvent* ev )
00102 {
00103 m_startPos = geometry().topLeft();
00104 m_mousePos = ev->globalPos();
00105 }
00106
00107 void ToolBox::mouseMoveEvent( QMouseEvent* ev )
00108 {
00109 setGeometry( m_startPos.x() - m_mousePos.x() + ev->globalPos().x(),
00110 m_startPos.y() - m_mousePos.y() + ev->globalPos().y(),
00111 width(), height() );
00112 }
00113
00114
00115
00116 KoTransformToolBox::KoTransformToolBox( KoDocumentChild* ch, QWidget* parent, const char* name )
00117 : ToolBox( parent, name )
00118 {
00119 m_child = 0;
00120
00121 m_rotation = new QSpinBox( 0, 360, 5, this );
00122 m_rotation->setSuffix( " deg" );
00123 m_scale = new QSpinBox( 10, 400, 10, this );
00124 m_scale->setSuffix( "%" );
00125 m_shearX = new QSpinBox( -100, 100, 1, this );
00126 m_shearX->setSuffix( " px" );
00127 m_shearY = new QSpinBox( -100, 100, 1, this );
00128 m_shearY->setSuffix( " px" );
00129
00130 setDocumentChild( ch );
00131
00132 connect( m_rotation, SIGNAL( valueChanged( int ) ),
00133 this, SLOT( slotRotationChanged( int ) ) );
00134 connect( m_scale, SIGNAL( valueChanged( int ) ),
00135 this, SLOT( slotScalingChanged( int ) ) );
00136 connect( m_shearX, SIGNAL( valueChanged( int ) ),
00137 this, SLOT( slotXShearingChanged( int ) ) );
00138 connect( m_shearY, SIGNAL( valueChanged( int ) ),
00139 this, SLOT( slotYShearingChanged( int ) ) );
00140 }
00141
00142 void KoTransformToolBox::setDocumentChild( KoDocumentChild* ch )
00143 {
00144 if ( m_child == ch )
00145 return;
00146
00147 m_child = ch;
00148
00149 if ( m_child )
00150 {
00151 setRotation( m_child->rotation() );
00152 setScaling( m_child->xScaling() );
00153 setXShearing( m_child->xShearing() );
00154 setYShearing( m_child->yShearing() );
00155 }
00156 }
00157
00158 double KoTransformToolBox::rotation() const
00159 {
00160 return m_rotation->text().toDouble();
00161 }
00162
00163 double KoTransformToolBox::scaling() const
00164 {
00165 return m_scale->text().toDouble() / 100.0;
00166 }
00167
00168 double KoTransformToolBox::xShearing() const
00169 {
00170 return m_shearX->text().toDouble() / 10.0;
00171 }
00172
00173 double KoTransformToolBox::yShearing() const
00174 {
00175 return m_shearY->text().toDouble() / 10.0;
00176 }
00177
00178 void KoTransformToolBox::slotRotationChanged( int v )
00179 {
00180 if ( m_child )
00181 m_child->setRotation( double( v ) );
00182
00183 emit rotationChanged( double( v ) );
00184 }
00185
00186 void KoTransformToolBox::slotScalingChanged( int v )
00187 {
00188 if ( m_child )
00189 m_child->setScaling( double( v ) / 100.0, double( v ) / 100.0 );
00190
00191 emit scalingChanged( double( v ) / 100.0 );
00192 }
00193
00194 void KoTransformToolBox::slotXShearingChanged( int v )
00195 {
00196 if ( m_child )
00197 m_child->setShearing( double( v ) / 10.0, m_child->yShearing() );
00198
00199 emit xShearingChanged( double( v ) / 10.0 );
00200 }
00201
00202 void KoTransformToolBox::slotYShearingChanged( int v )
00203 {
00204 if ( m_child )
00205 m_child->setShearing( m_child->xShearing(), double( v ) / 10.0 );
00206
00207 emit yShearingChanged( double( v ) / 10.0 );
00208 }
00209
00210 void KoTransformToolBox::setRotation( double v )
00211 {
00212 m_rotation->setValue( int( v ) );
00213 }
00214
00215 void KoTransformToolBox::setScaling( double v )
00216 {
00217 m_scale->setValue( int( v * 100.0 ) );
00218 }
00219
00220 void KoTransformToolBox::setXShearing( double v )
00221 {
00222 m_shearX->setValue( int( v * 10.0 ) );
00223 }
00224
00225 void KoTransformToolBox::setYShearing( double v )
00226 {
00227 m_shearY->setValue( int( v * 10.0 ) );
00228 }
00229
00230 #include "kspread_toolbox.moc"