1 /* 2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 3 * 4 * This file is part of the KD Chart library. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef KCHARTABSTRACTAREA_H 21 #define KCHARTABSTRACTAREA_H 22 23 #include <QObject> 24 25 #include "KChartGlobal.h" 26 #include "KChartAbstractAreaBase.h" 27 #include "KChartLayoutItems.h" 28 29 namespace KChart { 30 31 32 /** 33 * @class AbstractArea KChartAbstractArea.h 34 * @brief An area in the chart with a background, a frame, etc. 35 * 36 * AbstractArea is the base class for all non-widget chart elements that have 37 * a set of background attributes and frame attributes, such as 38 * coordinate planes or axes. 39 * 40 * @note This class inherits from AbstractAreaBase, AbstractLayoutItem, QObject. 41 * The reason for this triple inheritance is that neither AbstractAreaBase nor 42 * AbstractLayoutItem are QObject. 43 */ 44 class KCHART_EXPORT AbstractArea : public QObject, 45 public AbstractAreaBase, 46 public AbstractLayoutItem 47 { 48 Q_OBJECT 49 50 Q_DISABLE_COPY( AbstractArea ) 51 KCHART_DECLARE_PRIVATE_DERIVED( AbstractArea ) 52 53 public: 54 virtual ~AbstractArea() ; 55 56 /** 57 * @brief Draws the background and frame, then calls paint(). 58 * 59 * In most cases there is no need to overwrite this method in a derived 60 * class, but you would overwrite AbstractLayoutItem::paint() instead. 61 */ 62 virtual void paintIntoRect( QPainter& painter, const QRect& rect ); 63 64 /** 65 * Call paintAll, if you want the background and the frame to be drawn 66 * before the normal paint() is invoked automatically. 67 */ 68 void paintAll( QPainter& painter ) override; 69 70 /** 71 * This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint(). 72 * 73 * The method triggers AbstractArea::sizeHint() to find out the 74 * amount of overlap at the left edge of the area. 75 * 76 * \note The default implementation is not using any caching, 77 * it might make sense to implement a more sophisticated solution 78 * for derived classes that have complex work to do in sizeHint(). 79 * All we have here is a primitive flag to be set by the caller 80 * if it is sure that no sizeHint() needs to be called. 81 */ 82 virtual int leftOverlap( bool doNotRecalculate=false ) const; 83 /** 84 * This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint(). 85 * 86 * The method triggers AbstractArea::sizeHint() to find out the 87 * amount of overlap at the right edge of the area. 88 * 89 * \note The default implementation is not using any caching, 90 * it might make sense to implement a more sophisticated solution 91 * for derived classes that have complex work to do in sizeHint(). 92 * All we have here is a primitive flag to be set by the caller 93 * if it is sure that no sizeHint() needs to be called. 94 */ 95 virtual int rightOverlap( bool doNotRecalculate=false ) const; 96 /** 97 * This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint(). 98 * 99 * The method triggers AbstractArea::sizeHint() to find out the 100 * amount of overlap at the top edge of the area. 101 * 102 * \note The default implementation is not using any caching, 103 * it might make sense to implement a more sophisticated solution 104 * for derived classes that have complex work to do in sizeHint(). 105 * All we have here is a primitive flag to be set by the caller 106 * if it is sure that no sizeHint() needs to be called. 107 */ 108 virtual int topOverlap( bool doNotRecalculate=false ) const; 109 /** 110 * This is called at layout time by KChart:AutoSpacerLayoutItem::sizeHint(). 111 * 112 * The method triggers AbstractArea::sizeHint() to find out the 113 * amount of overlap at the bottom edge of the area. 114 * 115 * \note The default implementation is not using any caching, 116 * it might make sense to implement a more sophisticated solution 117 * for derived classes that have complex work to do in sizeHint(). 118 * All we have here is a primitive flag to be set by the caller 119 * if it is sure that no sizeHint() needs to be called. 120 */ 121 virtual int bottomOverlap( bool doNotRecalculate=false ) const; 122 123 protected: 124 AbstractArea(); 125 QRect areaGeometry() const override; 126 void positionHasChanged() override; 127 128 Q_SIGNALS: 129 void positionChanged( AbstractArea * ); 130 }; // End of class AbstractArea 131 132 } 133 #endif // KCHARTABSTRACTAREA_H 134