kformula

kformulawidget.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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/*QWidget::PaletteBase*/);
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     // Always repaint the buffer. This is not so much more work
00072     // than it seems to be as each cursor movement requires a repaint.
00073     QPainter p( &buffer );
00074     //p.translate( -fr.x(), -fr.y() );
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     // Magic numbers just to see the cursor.
00123     resize(width + 5, height + 5);
00124     buffer.resize(width + 5, height + 5);
00125     update();
00126     //kdDebug( 40000 ) << "KFormulaWidget::slotFormulaChanged" << endl;
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"
KDE Home | KDE Accessibility Home | Description of Access Keys