KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
5.5KB

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