lib Library API Documentation

kformulaview.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 00028 #include "basicelement.h" 00029 #include "formulacursor.h" 00030 #include "formulaelement.h" 00031 #include "kformulacontainer.h" 00032 #include "kformuladocument.h" 00033 #include "kformulaview.h" 00034 00035 KFORMULA_NAMESPACE_BEGIN 00036 00037 struct View::View_Impl { 00038 00039 View_Impl(Container* doc, View* view) 00040 : smallCursor(false), cursorHasChanged(true), 00041 document(doc) 00042 { 00043 connect(document, SIGNAL(elementWillVanish(BasicElement*)), 00044 view, SLOT(slotElementWillVanish(BasicElement*))); 00045 connect(document, SIGNAL(formulaLoaded(FormulaElement*)), 00046 view, SLOT(slotFormulaLoaded(FormulaElement*))); 00047 connect(document, SIGNAL(cursorMoved(FormulaCursor*)), 00048 view, SLOT(slotCursorMoved(FormulaCursor*))); 00049 00050 cursor = document->createCursor(); 00051 } 00052 00053 ~View_Impl() 00054 { 00055 if ( document->activeCursor() == cursor ) { 00056 document->setActiveCursor( 0 ); 00057 } 00058 delete cursor; 00059 } 00060 00064 bool smallCursor; 00065 00070 bool cursorHasChanged; 00071 00075 Container* document; 00076 00080 FormulaCursor* cursor; 00081 }; 00082 00083 00084 FormulaCursor* View::cursor() const { return impl->cursor; } 00085 bool& View::cursorHasChanged() { return impl->cursorHasChanged; } 00086 bool& View::smallCursor() { return impl->smallCursor; } 00087 Container* View::container() const { return impl->document; } 00088 00089 00090 View::View(Container* doc) 00091 { 00092 impl = new View_Impl(doc, this); 00093 cursor()->calcCursorSize( contextStyle(), smallCursor() ); 00094 } 00095 00096 View::~View() 00097 { 00098 delete impl; 00099 } 00100 00101 00102 QPoint View::getCursorPoint() const 00103 { 00104 return contextStyle().layoutUnitToPixel( cursor()->getCursorPoint() ); 00105 } 00106 00107 void View::setReadOnly(bool ro) 00108 { 00109 cursor()->setReadOnly(ro); 00110 } 00111 00112 00113 void View::calcCursor() 00114 { 00115 cursor()->calcCursorSize( contextStyle(), smallCursor() ); 00116 } 00117 00118 00119 void View::draw(QPainter& painter, const QRect& rect, const QColorGroup& cg) 00120 { 00121 // kdDebug( DEBUGID ) << "View::draw: " << rect.x() << " " << rect.y() << " " 00122 // << rect.width() << " " << rect.height() << endl; 00123 container()->draw( painter, rect, cg, true ); 00124 if ( cursorVisible() ) { 00125 cursor()->draw( painter, contextStyle(), smallCursor() ); 00126 } 00127 } 00128 00129 void View::draw(QPainter& painter, const QRect& rect) 00130 { 00131 container()->draw( painter, rect, true ); 00132 if ( cursorVisible() ) { 00133 cursor()->draw( painter, contextStyle(), smallCursor() ); 00134 } 00135 } 00136 00137 void View::keyPressEvent( QKeyEvent* event ) 00138 { 00139 container()->input( event ); 00140 } 00141 00142 00143 void View::focusInEvent(QFocusEvent*) 00144 { 00145 //cursor()->calcCursorSize( contextStyle(), smallCursor() ); 00146 container()->setActiveCursor(cursor()); 00147 } 00148 00149 void View::focusOutEvent(QFocusEvent*) 00150 { 00151 //container()->setActiveCursor(0); 00152 } 00153 00154 void View::mousePressEvent( QMouseEvent* event ) 00155 { 00156 const ContextStyle& context = contextStyle(); 00157 mousePressEvent( event, context.pixelToLayoutUnit( event->pos() ) ); 00158 } 00159 00160 void View::mouseReleaseEvent( QMouseEvent* event ) 00161 { 00162 const ContextStyle& context = contextStyle(); 00163 mouseReleaseEvent( event, context.pixelToLayoutUnit( event->pos() ) ); 00164 } 00165 00166 void View::mouseDoubleClickEvent( QMouseEvent* event ) 00167 { 00168 const ContextStyle& context = contextStyle(); 00169 mouseDoubleClickEvent( event, context.pixelToLayoutUnit( event->pos() ) ); 00170 } 00171 00172 void View::mouseMoveEvent( QMouseEvent* event ) 00173 { 00174 const ContextStyle& context = contextStyle(); 00175 mouseMoveEvent( event, context.pixelToLayoutUnit( event->pos() ) ); 00176 } 00177 00178 void View::wheelEvent( QWheelEvent* event ) 00179 { 00180 const ContextStyle& context = contextStyle(); 00181 wheelEvent( event, context.pixelToLayoutUnit( event->pos() ) ); 00182 } 00183 00184 void View::mousePressEvent( QMouseEvent* event, const PtPoint& pos ) 00185 { 00186 const ContextStyle& context = contextStyle(); 00187 mousePressEvent( event, context.ptToLayoutUnitPix( pos ) ); 00188 } 00189 00190 void View::mouseReleaseEvent( QMouseEvent* event, const PtPoint& pos ) 00191 { 00192 const ContextStyle& context = contextStyle(); 00193 mouseReleaseEvent( event, context.ptToLayoutUnitPix( pos ) ); 00194 } 00195 00196 void View::mouseDoubleClickEvent( QMouseEvent* event, const PtPoint& pos ) 00197 { 00198 const ContextStyle& context = contextStyle(); 00199 mouseDoubleClickEvent( event, context.ptToLayoutUnitPix( pos ) ); 00200 } 00201 00202 void View::mouseMoveEvent( QMouseEvent* event, const PtPoint& pos ) 00203 { 00204 const ContextStyle& context = contextStyle(); 00205 mouseMoveEvent( event, context.ptToLayoutUnitPix( pos ) ); 00206 } 00207 00208 void View::wheelEvent( QWheelEvent* event, const PtPoint& pos ) 00209 { 00210 const ContextStyle& context = contextStyle(); 00211 wheelEvent( event, context.ptToLayoutUnitPix( pos ) ); 00212 } 00213 00214 00215 void View::mousePressEvent( QMouseEvent* event, const LuPixelPoint& pos ) 00216 { 00217 int flags = movementFlag( event->state() ); 00218 cursor()->mousePress( pos, flags ); 00219 emitCursorChanged(); 00220 } 00221 00222 void View::mouseReleaseEvent( QMouseEvent* event, const LuPixelPoint& pos ) 00223 { 00224 int flags = movementFlag( event->state() ); 00225 cursor()->mouseRelease( pos, flags ); 00226 emitCursorChanged(); 00227 } 00228 00229 void View::mouseDoubleClickEvent( QMouseEvent*, const LuPixelPoint& ) 00230 { 00231 cursor()->moveRight( WordMovement ); 00232 cursor()->moveLeft( SelectMovement | WordMovement ); 00233 emitCursorChanged(); 00234 } 00235 00236 void View::mouseMoveEvent( QMouseEvent* event, const LuPixelPoint& pos ) 00237 { 00238 int flags = movementFlag( event->state() ); 00239 cursor()->mouseMove( pos, flags ); 00240 emitCursorChanged(); 00241 } 00242 00243 void View::wheelEvent( QWheelEvent*, const LuPixelPoint& ) 00244 { 00245 } 00246 00247 00248 void View::slotCursorMoved(FormulaCursor* c) 00249 { 00250 if (c == cursor()) { 00251 cursorHasChanged() = true; 00252 emitCursorChanged(); 00253 } 00254 } 00255 00256 void View::slotFormulaLoaded(FormulaElement* formula) 00257 { 00258 cursor()->formulaLoaded(formula); 00259 } 00260 00261 void View::slotElementWillVanish(BasicElement* element) 00262 { 00263 cursor()->elementWillVanish(element); 00264 emitCursorChanged(); 00265 } 00266 00267 void View::slotSelectAll() 00268 { 00269 cursor()->moveHome(WordMovement); 00270 cursor()->moveEnd(SelectMovement | WordMovement); 00271 emitCursorChanged(); 00272 } 00273 00274 00275 void View::moveLeft( int flag ) 00276 { 00277 cursor()->moveLeft( flag ); 00278 emitCursorChanged(); 00279 } 00280 00281 void View::moveRight( int flag ) 00282 { 00283 cursor()->moveRight( flag ); 00284 emitCursorChanged(); 00285 } 00286 00287 void View::moveUp( int flag ) 00288 { 00289 cursor()->moveUp( flag ); 00290 emitCursorChanged(); 00291 } 00292 00293 void View::moveDown( int flag ) 00294 { 00295 cursor()->moveDown( flag ); 00296 emitCursorChanged(); 00297 } 00298 00299 00300 void View::moveHome( int flag ) 00301 { 00302 cursor()->moveHome( flag ); 00303 emitCursorChanged(); 00304 } 00305 00306 void View::moveEnd( int flag ) 00307 { 00308 cursor()->moveEnd( flag ); 00309 emitCursorChanged(); 00310 } 00311 00312 00313 void View::setSmallCursor(bool small) 00314 { 00315 smallCursor() = small; 00316 } 00317 00318 bool View::isHome() const 00319 { 00320 return cursor()->isHome(); 00321 } 00322 00323 bool View::isEnd() const 00324 { 00325 return cursor()->isEnd(); 00326 } 00327 00328 void View::eraseSelection( Direction direction ) 00329 { 00330 DirectedRemove r( req_remove, direction ); 00331 container()->performRequest( &r ); 00332 } 00333 00334 void View::addText( QString str ) 00335 { 00336 TextRequest r( str ); 00337 container()->performRequest( &r ); 00338 } 00339 00340 void View::emitCursorChanged() 00341 { 00342 if (cursor()->hasChanged() || cursorHasChanged()) { 00343 00344 cursor()->clearChangedFlag(); 00345 cursorHasChanged() = false; 00346 cursor()->calcCursorSize( contextStyle(), smallCursor() ); 00347 00348 emit cursorChanged(cursorVisible(), cursor()->isSelection()); 00349 } 00350 } 00351 00352 const ContextStyle& View::contextStyle() const 00353 { 00354 return container()->document()->getContextStyle(); 00355 } 00356 00357 bool View::cursorVisible() 00358 { 00359 //return !cursor()->isReadOnly() || cursor()->isSelection(); 00360 return true; 00361 } 00362 00363 KFORMULA_NAMESPACE_END 00364 00365 using namespace KFormula; 00366 #include "kformulaview.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