lib Library API Documentation

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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include <iostream> 00022 00023 #include <qpainter.h> 00024 00025 #include <kapplication.h> 00026 #include <kdebug.h> 00027 //#include <klocale.h> 00028 //#include <kstdaction.h> 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/*QWidget::PaletteBase*/); 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 // Always repaint the buffer. This is not so much more work 00073 // than it seems to be as each cursor movement requires a repaint. 00074 QPainter p( &buffer ); 00075 //p.translate( -fr.x(), -fr.y() ); 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 // Magic numbers just to see the cursor. 00129 resize(width + 5, height + 5); 00130 buffer.resize(width + 5, height + 5); 00131 // repaint is needed even if the size doesn't change. 00132 //update(); 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 // kdDebug( 40000 ) << "KFormulaWidget::slotCursorChanged " 00161 // << formulaView.getDirtyArea().x() << " " 00162 // << formulaView.getDirtyArea().y() << " " 00163 // << formulaView.getDirtyArea().width() << " " 00164 // << formulaView.getDirtyArea().height() << " " 00165 // << endl; 00166 // sadly this doesn't work 00167 //update(formulaView.getDirtyArea()); 00168 update(); 00169 } 00170 00171 #include "kformulawidget.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:03:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003