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.

kformulawidget.cc 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* This file is part of the KDE project
  2. Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
  3. Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
  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. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #include <iostream>
  18. #include <tqpainter.h>
  19. #include <tdeapplication.h>
  20. #include <kdebug.h>
  21. #include <basicelement.h>
  22. #include <formulacursor.h>
  23. #include <formulaelement.h>
  24. #include <kformulacontainer.h>
  25. #include <kformuladocument.h>
  26. #include "kformulawidget.h"
  27. KFormulaWidget::KFormulaWidget(KFormula::Container* doc,
  28. TQWidget* parent, const char* name, WFlags f)
  29. : TQWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
  30. formulaView(doc)
  31. {
  32. connect(doc, TQT_SIGNAL(formulaChanged(int, int)),
  33. this, TQT_SLOT(slotFormulaChanged(int, int)));
  34. connect(&formulaView, TQT_SIGNAL(cursorChanged(bool, bool)),
  35. this, TQT_SLOT(slotCursorChanged(bool, bool)));
  36. setFocusPolicy(TQ_StrongFocus);
  37. setBackgroundMode(NoBackground/*TQWidget::PaletteBase*/);
  38. TQRect rect = doc->boundingRect();
  39. slotFormulaChanged(rect.width(), rect.height());
  40. }
  41. KFormulaWidget::~KFormulaWidget()
  42. {
  43. }
  44. TQPoint KFormulaWidget::getCursorPoint() const
  45. {
  46. return formulaView.getCursorPoint();
  47. }
  48. void KFormulaWidget::setReadOnly(bool ro)
  49. {
  50. formulaView.setReadOnly(ro);
  51. }
  52. void KFormulaWidget::paintEvent(TQPaintEvent* event)
  53. {
  54. // Always repaint the buffer. This is not so much more work
  55. // than it seems to be as each cursor movement requires a repaint.
  56. TQPainter p( &buffer );
  57. //p.translate( -fr.x(), -fr.y() );
  58. formulaView.draw( p, event->rect(), colorGroup() );
  59. TQPainter painter;
  60. painter.begin(this);
  61. painter.drawPixmap( event->rect().x(), event->rect().y(),
  62. buffer, event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height() );
  63. painter.end();
  64. }
  65. void KFormulaWidget::keyPressEvent(TQKeyEvent* event)
  66. {
  67. formulaView.keyPressEvent(event);
  68. }
  69. void KFormulaWidget::focusInEvent(TQFocusEvent* event)
  70. {
  71. formulaView.focusInEvent(event);
  72. }
  73. void KFormulaWidget::focusOutEvent(TQFocusEvent* event)
  74. {
  75. formulaView.focusOutEvent(event);
  76. }
  77. void KFormulaWidget::mousePressEvent(TQMouseEvent* event)
  78. {
  79. formulaView.mousePressEvent(event);
  80. }
  81. void KFormulaWidget::mouseReleaseEvent(TQMouseEvent* event)
  82. {
  83. formulaView.mouseReleaseEvent(event);
  84. }
  85. void KFormulaWidget::mouseDoubleClickEvent(TQMouseEvent* event)
  86. {
  87. formulaView.mouseDoubleClickEvent(event);
  88. }
  89. void KFormulaWidget::mouseMoveEvent(TQMouseEvent* event)
  90. {
  91. formulaView.mouseMoveEvent(event);
  92. }
  93. void KFormulaWidget::slotFormulaChanged(int width, int height)
  94. {
  95. // Magic numbers just to see the cursor.
  96. resize(width + 5, height + 5);
  97. buffer.resize(width + 5, height + 5);
  98. update();
  99. //kdDebug( 40000 ) << "KFormulaWidget::slotFormulaChanged" << endl;
  100. }
  101. /**
  102. * The document we show.
  103. */
  104. KFormula::Container* KFormulaWidget::getDocument()
  105. {
  106. return formulaView.getDocument();
  107. }
  108. /**
  109. * Our cursor.
  110. */
  111. KFormula::FormulaCursor* KFormulaWidget::getCursor()
  112. {
  113. return formulaView.getCursor();
  114. }
  115. void KFormulaWidget::slotSelectAll()
  116. {
  117. formulaView.slotSelectAll();
  118. }
  119. void KFormulaWidget::slotCursorChanged(bool visible, bool selecting)
  120. {
  121. emit cursorChanged(visible, selecting);
  122. update();
  123. }
  124. #include "kformulawidget.moc"