00001
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
00029
00030
#include "basicelement.h"
00031
#include "formulacursor.h"
00032
#include "formulaelement.h"
00033
#include "kformulacontainer.h"
00034
#include "kformuladocument.h"
00035
#include "kformulawidget.h"
00036
00037
00038 KFormulaWidget::KFormulaWidget(
Container* doc,
QWidget* parent,
const char* name, WFlags f)
00039 :
QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
00040 formulaView(doc)
00041 {
00042 connect(doc, SIGNAL(formulaChanged(
int,
int)),
00043
this, SLOT(slotFormulaChanged(
int,
int)));
00044 connect(&formulaView, SIGNAL(
cursorChanged(
bool,
bool)),
00045
this, SLOT(slotCursorChanged(
bool,
bool)));
00046
00047 setFocusPolicy(QWidget::StrongFocus);
00048 setBackgroundMode(NoBackground);
00049
00050
QRect rect = doc->
boundingRect();
00051 slotFormulaChanged(rect.width(), rect.height());
00052 }
00053
00054 KFormulaWidget::~KFormulaWidget()
00055 {
00056 }
00057
00058
00059 QPoint KFormulaWidget::getCursorPoint()
const
00060
{
00061
return formulaView.
getCursorPoint();
00062 }
00063
00064 void KFormulaWidget::setReadOnly(
bool ro)
00065 {
00066 formulaView.
setReadOnly(ro);
00067 }
00068
00069
00070
void KFormulaWidget::paintEvent(
QPaintEvent* event)
00071 {
00072
00073
00074
QPainter p( &buffer );
00075
00076 formulaView.
draw( p, event->rect(), colorGroup() );
00077
00078
QPainter painter;
00079 painter.begin(
this);
00080 painter.drawPixmap( event->rect().x(), event->rect().y(),
00081 buffer, event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height() );
00082 painter.end();
00083 }
00084
00085
void KFormulaWidget::keyPressEvent(
QKeyEvent* event)
00086 {
00087 formulaView.
keyPressEvent(event);
00088 }
00089
00090
00091
void KFormulaWidget::focusInEvent(
QFocusEvent* event)
00092 {
00093 formulaView.
focusInEvent(event);
00094 }
00095
00096
void KFormulaWidget::focusOutEvent(
QFocusEvent* event)
00097 {
00098 formulaView.
focusOutEvent(event);
00099 }
00100
00101
void KFormulaWidget::mousePressEvent(
QMouseEvent* event)
00102 {
00103 formulaView.
mousePressEvent(event);
00104 }
00105
00106
void KFormulaWidget::mouseReleaseEvent(
QMouseEvent* event)
00107 {
00108 formulaView.
mouseReleaseEvent(event);
00109 }
00110
00111
void KFormulaWidget::mouseDoubleClickEvent(
QMouseEvent* event)
00112 {
00113 formulaView.
mouseDoubleClickEvent(event);
00114 }
00115
00116
void KFormulaWidget::mouseMoveEvent(
QMouseEvent* event)
00117 {
00118 formulaView.
mouseMoveEvent(event);
00119 }
00120
00121
void KFormulaWidget::wheelEvent(
QWheelEvent* event)
00122 {
00123 formulaView.
wheelEvent(event);
00124 }
00125
00126 void KFormulaWidget::slotFormulaChanged(
int width,
int height)
00127 {
00128
00129 resize(width + 5, height + 5);
00130 buffer.resize(width + 5, height + 5);
00131
00132
00133 }
00134
00138 Container*
KFormulaWidget::getDocument()
00139 {
00140
return formulaView.
getDocument();
00141 }
00142
00146 FormulaCursor*
KFormulaWidget::getCursor()
00147 {
00148
return formulaView.
getCursor();
00149 }
00150
00151
00152
void KFormulaWidget::slotSelectAll()
00153 {
00154 formulaView.
slotSelectAll();
00155 }
00156
00157
void KFormulaWidget::slotCursorChanged(
bool visible,
bool selecting)
00158 {
00159 emit
cursorChanged(visible, selecting);
00160
00161
00162
00163
00164
00165
00166
00167
00168 update();
00169 }
00170
00171
#include "kformulawidget.moc"