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 KCHARTABSTRACTAREABASE_H 21 #define KCHARTABSTRACTAREABASE_H 22 23 #include <QPointF> 24 #include <QSizeF> 25 #include <QRectF> 26 27 #include "KChartGlobal.h" 28 #include "KChartLayoutItems.h" 29 #include "KChartRelativePosition.h" 30 #include "KChartAbstractAreaBase.h" 31 32 33 QT_BEGIN_NAMESPACE 34 class QPainter; 35 class QString; 36 QT_END_NAMESPACE 37 38 namespace KChart { 39 class TextAttributes; 40 class BackgroundAttributes; 41 class FrameAttributes; 42 class PaintContext; 43 44 45 /** 46 * @class AbstractAreaBase KChartAbstractAreaBase.h 47 * @brief Base class for AbstractArea and AbstractAreaWidget: An area 48 * in the chart with a background, a frame, etc. 49 * 50 * AbstractAreaBase is the base class for all chart elements that have 51 * a set of background attributes and frame attributes, such as 52 * legends or axes. 53 * 54 * @note Normally you should not use AbstractAreaBase directly, but 55 * derive your classes from AbstractArea or AbstractAreaWidget. 56 * 57 * @note This classis not a QObject, so it is easier to inherit from 58 * it, if your are inheriting from a QObject too like AbstractAreaWidget does it. 59 * 60 * @sa AbstractArea, AbstractAreaWidget 61 */ 62 class KCHART_EXPORT AbstractAreaBase 63 { 64 Q_DISABLE_COPY( AbstractAreaBase ) 65 KCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractAreaBase ) 66 67 protected: 68 AbstractAreaBase(); 69 virtual ~AbstractAreaBase() ; 70 71 public: 72 /** 73 * Returns true if both areas have the same settings. 74 */ 75 bool compare( const AbstractAreaBase* other ) const; 76 77 void alignToReferencePoint( const RelativePosition& position ); 78 79 void setFrameAttributes( const FrameAttributes &a ); 80 FrameAttributes frameAttributes() const; 81 82 void setBackgroundAttributes( const BackgroundAttributes &a ); 83 BackgroundAttributes backgroundAttributes() const; 84 85 virtual void paintBackground( QPainter& painter, const QRect& rectangle ); 86 virtual void paintFrame( QPainter& painter, const QRect& rectangle ); 87 88 static void paintBackgroundAttributes( QPainter& painter, const QRect& rectangle, 89 const KChart::BackgroundAttributes& attributes ); 90 static void paintFrameAttributes( QPainter& painter, const QRect& rectangle, 91 const KChart::FrameAttributes& attributes ); 92 93 /** \internal 94 * \note Normally you should not call this method, but derive your classes 95 * from AbstractArea or AbstractAreaWidget. 96 * \sa AbstractArea, AbstractAreaWidget 97 */ 98 void getFrameLeadings(int& left, int& top, int& right, int& bottom ) const; 99 100 101 protected: 102 /** \internal 103 * \note Normally you should not call this method, but derive your classes 104 * from AbstractArea or AbstractAreaWidget. 105 * \sa AbstractArea, AbstractAreaWidget 106 */ 107 QRect innerRect() const; 108 109 /** \internal 110 * This internal method is used by AbstractArea and AbstractAreaWidget 111 * to find out the real widget size. 112 * \sa AbstractArea, AbstractAreaWidget 113 */ 114 virtual QRect areaGeometry() const = 0; 115 116 /** \internal 117 * This internal method can be overwritten by derived classes, 118 * if they want to emit a signal (or perform other actions, resp.) 119 * when the Position of the area has been changed. 120 * The default implementation does nothing. 121 */ 122 virtual void positionHasChanged(); 123 124 }; // End of class AbstractAreaBase 125 126 } 127 #endif // KCHARTABSTRACTAREABASE_H 128