kformula
kformulawidget.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <iostream>
00022
00023 #include <qpainter.h>
00024
00025 #include <kapplication.h>
00026 #include <kdebug.h>
00027
00028 #include <basicelement.h>
00029 #include <formulacursor.h>
00030 #include <formulaelement.h>
00031 #include <kformulacontainer.h>
00032 #include <kformuladocument.h>
00033 #include "kformulawidget.h"
00034
00035
00036 KFormulaWidget::KFormulaWidget(KFormula::Container* doc,
00037 QWidget* parent, const char* name, WFlags f)
00038 : QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
00039 formulaView(doc)
00040 {
00041 connect(doc, SIGNAL(formulaChanged(int, int)),
00042 this, SLOT(slotFormulaChanged(int, int)));
00043 connect(&formulaView, SIGNAL(cursorChanged(bool, bool)),
00044 this, SLOT(slotCursorChanged(bool, bool)));
00045
00046 setFocusPolicy(QWidget::StrongFocus);
00047 setBackgroundMode(NoBackground);
00048
00049 QRect rect = doc->boundingRect();
00050 slotFormulaChanged(rect.width(), rect.height());
00051 }
00052
00053 KFormulaWidget::~KFormulaWidget()
00054 {
00055 }
00056
00057
00058 QPoint KFormulaWidget::getCursorPoint() const
00059 {
00060 return formulaView.getCursorPoint();
00061 }
00062
00063 void KFormulaWidget::setReadOnly(bool ro)
00064 {
00065 formulaView.setReadOnly(ro);
00066 }
00067
00068
00069 void KFormulaWidget::paintEvent(QPaintEvent* event)
00070 {
00071
00072
00073 QPainter p( &buffer );
00074
00075 formulaView.draw( p, event->rect(), colorGroup() );
00076
00077 QPainter painter;
00078 painter.begin(this);
00079 painter.drawPixmap( event->rect().x(), event->rect().y(),
00080 buffer, event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height() );
00081 painter.end();
00082 }
00083
00084 void KFormulaWidget::keyPressEvent(QKeyEvent* event)
00085 {
00086 formulaView.keyPressEvent(event);
00087 }
00088
00089
00090 void KFormulaWidget::focusInEvent(QFocusEvent* event)
00091 {
00092 formulaView.focusInEvent(event);
00093 }
00094
00095 void KFormulaWidget::focusOutEvent(QFocusEvent* event)
00096 {
00097 formulaView.focusOutEvent(event);
00098 }
00099
00100 void KFormulaWidget::mousePressEvent(QMouseEvent* event)
00101 {
00102 formulaView.mousePressEvent(event);
00103 }
00104
00105 void KFormulaWidget::mouseReleaseEvent(QMouseEvent* event)
00106 {
00107 formulaView.mouseReleaseEvent(event);
00108 }
00109
00110 void KFormulaWidget::mouseDoubleClickEvent(QMouseEvent* event)
00111 {
00112 formulaView.mouseDoubleClickEvent(event);
00113 }
00114
00115 void KFormulaWidget::mouseMoveEvent(QMouseEvent* event)
00116 {
00117 formulaView.mouseMoveEvent(event);
00118 }
00119
00120 void KFormulaWidget::slotFormulaChanged(int width, int height)
00121 {
00122
00123 resize(width + 5, height + 5);
00124 buffer.resize(width + 5, height + 5);
00125 update();
00126
00127 }
00128
00132 KFormula::Container* KFormulaWidget::getDocument()
00133 {
00134 return formulaView.getDocument();
00135 }
00136
00140 KFormula::FormulaCursor* KFormulaWidget::getCursor()
00141 {
00142 return formulaView.getCursor();
00143 }
00144
00145
00146 void KFormulaWidget::slotSelectAll()
00147 {
00148 formulaView.slotSelectAll();
00149 }
00150
00151 void KFormulaWidget::slotCursorChanged(bool visible, bool selecting)
00152 {
00153 emit cursorChanged(visible, selecting);
00154 update();
00155 }
00156
00157 #include "kformulawidget.moc"
|