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.

195 lines
4.3KB

  1. //
  2. // TODO: insert copyright header
  3. //
  4. #include <tqpainter.h>
  5. #include "kspread_view.h"
  6. #include "kspread_handler.h"
  7. #define KS_MIN_RECTSIZE 3
  8. using namespace KSpread;
  9. InsertHandler::InsertHandler( View* view, TQWidget* widget )
  10. : KoEventHandler( TQT_TQOBJECT(widget) )
  11. {
  12. m_view = view;
  13. m_started = false;
  14. m_clicked = false;
  15. widget->setCursor( crossCursor );
  16. }
  17. InsertHandler::~InsertHandler()
  18. {
  19. ((TQWidget*)target())->setCursor( arrowCursor );
  20. m_view->resetInsertHandle();
  21. }
  22. bool InsertHandler::eventFilter( TQObject*, TQEvent* ev )
  23. {
  24. if ( ev->type() == TQEvent::MouseButtonPress )
  25. {
  26. TQMouseEvent* e = (TQMouseEvent*)ev;
  27. m_geometryStart = e->pos();
  28. m_geometryEnd = e->pos();
  29. m_started = false;
  30. m_clicked = true;
  31. return true;
  32. }
  33. else if ( ev->type() == TQEvent::MouseMove )
  34. {
  35. if ( !m_clicked )
  36. return true;
  37. TQMouseEvent* e = (TQMouseEvent*)ev;
  38. TQPainter painter;
  39. painter.begin( (TQWidget*)target() );
  40. painter.setRasterOp( NotROP );
  41. TQPen pen;
  42. pen.setStyle( Qt::DashLine );
  43. painter.setPen( pen );
  44. if ( m_started )
  45. {
  46. int x = m_geometryStart.x();
  47. int y = m_geometryStart.y();
  48. if ( x > m_geometryEnd.x() )
  49. x = m_geometryEnd.x();
  50. if ( y > m_geometryEnd.y() )
  51. y = m_geometryEnd.y();
  52. int w = m_geometryEnd.x() - m_geometryStart.x();
  53. if ( w < 0 ) w *= -1;
  54. int h = m_geometryEnd.y() - m_geometryStart.y();
  55. if ( h < 0 ) h *= -1;
  56. if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
  57. if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
  58. painter.drawRect( x, y, w, h );
  59. }
  60. else
  61. m_started = true;
  62. m_geometryEnd = e->pos();
  63. int x = m_geometryStart.x();
  64. int y = m_geometryStart.y();
  65. if ( x > m_geometryEnd.x() )
  66. x = m_geometryEnd.x();
  67. if ( y > m_geometryEnd.y() )
  68. y = m_geometryEnd.y();
  69. int w = m_geometryEnd.x() - m_geometryStart.x();
  70. if ( w < 0 ) w *= -1;
  71. int h = m_geometryEnd.y() - m_geometryStart.y();
  72. if ( h < 0 ) h *= -1;
  73. if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
  74. if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
  75. painter.drawRect( x, y, w, h );
  76. painter.end();
  77. return true;
  78. }
  79. else if ( ev->type() == TQEvent::MouseButtonRelease )
  80. {
  81. TQMouseEvent* e = (TQMouseEvent*)ev;
  82. if ( !m_started )
  83. {
  84. delete this;
  85. return true;
  86. }
  87. m_geometryEnd = e->pos();
  88. int x = m_geometryStart.x();
  89. int y = m_geometryStart.y();
  90. if ( x > m_geometryEnd.x() )
  91. x = m_geometryEnd.x();
  92. if ( y > m_geometryEnd.y() )
  93. y = m_geometryEnd.y();
  94. int w = m_geometryEnd.x() - m_geometryStart.x();
  95. if ( w < 0 ) w *= -1;
  96. int h = m_geometryEnd.y() - m_geometryStart.y();
  97. if ( h < 0 ) h *= -1;
  98. if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
  99. if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
  100. TQPainter painter;
  101. painter.begin( (TQWidget*)target() );
  102. TQPen pen;
  103. pen.setStyle( Qt::DashLine );
  104. painter.setPen( pen );
  105. painter.setRasterOp( NotROP );
  106. painter.drawRect( x, y, w, h );
  107. painter.end();
  108. insertObject( TQRect( x, y, w, h) );
  109. delete this;
  110. return true;
  111. }
  112. else if ( ev->type() == TQEvent::KeyPress )
  113. {
  114. TQKeyEvent* e = (TQKeyEvent*)ev;
  115. if ( e->key() != Key_Escape )
  116. return false;
  117. delete this;
  118. return true;
  119. }
  120. return false;
  121. }
  122. InsertPartHandler::InsertPartHandler( View* view, TQWidget* widget, const KoDocumentEntry& entry )
  123. : InsertHandler( view, widget ), m_entry( entry )
  124. {
  125. }
  126. InsertPartHandler::~InsertPartHandler()
  127. {
  128. }
  129. void InsertPartHandler::insertObject( TQRect r)
  130. {
  131. m_view->insertChild( r, m_entry );
  132. }
  133. InsertChartHandler::InsertChartHandler( View* view, TQWidget* widget, const KoDocumentEntry& entry )
  134. : InsertHandler( view, widget ), m_entry( entry )
  135. {
  136. }
  137. InsertChartHandler::~InsertChartHandler()
  138. {
  139. }
  140. void InsertChartHandler::insertObject( TQRect r)
  141. {
  142. m_view->insertChart( r, m_entry );
  143. }
  144. InsertPictureHandler::InsertPictureHandler( View* view, TQWidget* widget, const KURL &file )
  145. : InsertHandler( view, widget )
  146. {
  147. m_file = file;
  148. }
  149. InsertPictureHandler::~InsertPictureHandler()
  150. {
  151. }
  152. void InsertPictureHandler::insertObject( TQRect r)
  153. {
  154. //m_view->insertPicture(/* r,*/ m_file );
  155. }
  156. #include "kspread_handler.moc"