File indexing completed on 2024-05-12 16:34:02
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "FormulaRenderer.h" 0021 0022 #include "AttributeManager.h" 0023 #include "BasicElement.h" 0024 #include "FormulaDebug.h" 0025 0026 FormulaRenderer::FormulaRenderer() 0027 { 0028 m_dirtyElement = 0; 0029 m_attributeManager = new AttributeManager(); 0030 } 0031 0032 FormulaRenderer::~FormulaRenderer() 0033 { 0034 delete m_attributeManager; 0035 } 0036 0037 void FormulaRenderer::paintElement( QPainter& p, BasicElement* element, bool hints ) 0038 { 0039 p.save(); 0040 p.setRenderHint( QPainter::Antialiasing ); 0041 p.translate( element->origin() ); // setup painter 0042 if (!hints) { 0043 element->paint( p, m_attributeManager ); // let element paint itself 0044 } else { 0045 element->paintEditingHints( p, m_attributeManager ); 0046 } 0047 0048 // eventually paint all its children 0049 if( !element->childElements().isEmpty() && element->elementType() != Phantom ) { 0050 foreach( BasicElement* tmpElement, element->childElements() ) { 0051 paintElement( p, tmpElement, hints ); 0052 } 0053 } 0054 0055 p.restore(); 0056 } 0057 0058 0059 void FormulaRenderer::layoutElement( BasicElement* element ) 0060 { 0061 int i = 0; 0062 element->setDisplayStyle( m_attributeManager->boolOf("displaystyle", element)); 0063 foreach( BasicElement* tmp, element->childElements() ) { 0064 int scale = m_attributeManager->scriptLevel( element, i++ ); 0065 tmp->setScaleLevel( scale ); 0066 layoutElement( tmp ); // first layout all children 0067 } 0068 element->layout( m_attributeManager ); // actually layout the element 0069 element->stretch(); 0070 } 0071 0072 void FormulaRenderer::update( QPainter& p, BasicElement* element ) 0073 { 0074 updateElementLayout( element ); // relayout the changed element 0075 paintElement( p, m_dirtyElement ); // and then repaint as much as needed 0076 } 0077 0078 void FormulaRenderer::updateElementLayout( BasicElement* element ) 0079 { 0080 QRectF tmpBoundingRect; 0081 bool parentLayoutAffected = true; 0082 BasicElement* tmpElement = element; 0083 while( parentLayoutAffected ) 0084 { 0085 tmpBoundingRect = tmpElement->boundingRect(); // cache the former boundingRect 0086 tmpElement->layout( m_attributeManager ); // layout the element 0087 0088 // check whether the new layout affects the parent element's layout 0089 if( tmpBoundingRect == tmpElement->boundingRect() ) 0090 { 0091 parentLayoutAffected = false; // stop the layouting 0092 m_dirtyElement = tmpElement; 0093 } 0094 else 0095 tmpElement = tmpElement->parentElement(); // prepare layouting the parent 0096 } 0097 } 0098 0099 qreal FormulaRenderer::elementScaleFactor( BasicElement* element ) const 0100 { 0101 Q_UNUSED(element) 0102 AttributeManager am; 0103 return -1; // FIXME! 0104 }