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 #ifndef FORMULARENDERER_H 0021 #define FORMULARENDERER_H 0022 0023 #include <QPainter> 0024 #include "koformula_export.h" 0025 0026 class AttributeManager; 0027 class BasicElement; 0028 0029 /** 0030 * @short FormulaRenderer takes care of painting and layouting the elements 0031 * 0032 * FormulaRenderer follows the visitor pattern. It iterates through the element 0033 * tree and calls layout() or paint() methods to let the single elements layout 0034 * or paint itsselves. This more generic approach allows more efficient repainting 0035 * and relayouting. 0036 * The update() method is the most interesting of the class as it is used to update 0037 * the visuals when the formula tree has changed somehow. The method calls 0038 * layoutElement() and then paintElement(). The former is made to be efficient so it 0039 * layouts only as many parental elements as needed. 0040 * Using a central class for painting parts or the whole tree structure that makes 0041 * up a formula has several advantages. First it reduces a lot of code duplication. 0042 * Second it takes care of painting and layouting in the right order so that there 0043 * no need anymore for the single element classes to do so. Third we can control 0044 * instance AttributeManager and destroying and constructing it often is not needed 0045 * anymore. 0046 * 0047 * @author Martin Pfeiffer <hubipete@gmx.net> 0048 */ 0049 class KOFORMULA_EXPORT FormulaRenderer { 0050 public: 0051 /// The constructor 0052 FormulaRenderer(); 0053 0054 /// The destructor 0055 ~FormulaRenderer(); 0056 0057 /** 0058 * Paint an element and all its children 0059 * @param p The QPainter that should be used to paint the element 0060 * @param element The element to be painted 0061 * @param hints Whether to show the hints 0062 */ 0063 void paintElement( QPainter& p, BasicElement* element, bool hints=false ); 0064 0065 /** 0066 * Layout an element and all its children 0067 * @param element The element to be layouted 0068 */ 0069 void layoutElement( BasicElement* element ); 0070 0071 /** 0072 * Update an element after it has changed 0073 * @param p The QPainter that should be used to paint the element 0074 * @param element The element that has changed 0075 */ 0076 void update( QPainter& p, BasicElement* element ); 0077 0078 /// Just for updating one elements layout after a change 0079 void updateElementLayout( BasicElement* element ); 0080 0081 private: 0082 qreal elementScaleFactor( BasicElement* element ) const; 0083 0084 /// The attribute manager used for rendering and layouting 0085 AttributeManager* m_attributeManager; 0086 0087 /// Used by update() to store the highest element in the tree that needs repaint 0088 BasicElement* m_dirtyElement; 0089 }; 0090 0091 #endif // FORMULARENDERER_H