kformula/flake
FormulaRenderer.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "FormulaRenderer.h" 00021 #include "AttributeManager.h" 00022 #include "BasicElement.h" 00023 #include <kdebug.h> 00024 00025 FormulaRenderer::FormulaRenderer() 00026 { 00027 m_dirtyElement = 0; 00028 m_attributeManager = new AttributeManager(); 00029 } 00030 00031 FormulaRenderer::~FormulaRenderer() 00032 { 00033 delete m_attributeManager; 00034 } 00035 00036 void FormulaRenderer::paintElement( QPainter& p, BasicElement* element ) 00037 { 00038 p.save(); 00039 p.setRenderHint( QPainter::Antialiasing ); 00040 p.translate( element->origin() ); // setup painter 00041 element->paint( p, m_attributeManager ); // let element paint itself 00042 00043 // eventually paint all its children 00044 if( !element->childElements().isEmpty() && element->elementType() != Phantom ) 00045 foreach( BasicElement* tmpElement, element->childElements() ) 00046 paintElement( p, tmpElement ); 00047 00048 p.restore(); 00049 } 00050 00051 void FormulaRenderer::layoutElement( BasicElement* element ) 00052 { 00053 int i = 0; 00054 element->setDisplayStyle( m_attributeManager->boolOf("displaystyle", element)); 00055 foreach( BasicElement* tmp, element->childElements() ) { 00056 int scale = m_attributeManager->scriptLevel( element, i++ ); 00057 tmp->setScaleLevel( scale ); 00058 layoutElement( tmp ); // first layout all children 00059 } 00060 element->layout( m_attributeManager ); // actually layout the element 00061 element->stretch(); 00062 } 00063 00064 void FormulaRenderer::update( QPainter& p, BasicElement* element ) 00065 { 00066 updateElementLayout( element ); // relayout the changed element 00067 paintElement( p, m_dirtyElement ); // and then repaint as much as needed 00068 } 00069 00070 void FormulaRenderer::updateElementLayout( BasicElement* element ) 00071 { 00072 QRectF tmpBoundingRect; 00073 bool parentLayoutAffected = true; 00074 BasicElement* tmpElement = element; 00075 while( parentLayoutAffected ) 00076 { 00077 tmpBoundingRect = tmpElement->boundingRect(); // cache the former boundingRect 00078 tmpElement->layout( m_attributeManager ); // layout the element 00079 00080 // check whether the new layout affects the parent element's layout 00081 if( tmpBoundingRect == tmpElement->boundingRect() ) 00082 { 00083 parentLayoutAffected = false; // stop the layouting 00084 m_dirtyElement = tmpElement; 00085 } 00086 else 00087 tmpElement = tmpElement->parentElement(); // prepare layouting the parent 00088 } 00089 } 00090 00091 double FormulaRenderer::elementScaleFactor( BasicElement* element ) const 00092 { 00093 AttributeManager am; 00094 return -1; // FIXME! 00095 }
