File indexing completed on 2024-05-12 15:54:10

0001 /*
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef KCHARTABSTRACTAREABASE_H
0021 #define KCHARTABSTRACTAREABASE_H
0022 
0023 #include <QPointF>
0024 #include <QSizeF>
0025 #include <QRectF>
0026 
0027 #include "KChartGlobal.h"
0028 #include "KChartLayoutItems.h"
0029 #include "KChartRelativePosition.h"
0030 #include "KChartAbstractAreaBase.h"
0031 
0032 
0033 QT_BEGIN_NAMESPACE
0034 class QPainter;
0035 class QString;
0036 QT_END_NAMESPACE
0037 
0038 namespace KChart {
0039     class TextAttributes;
0040     class BackgroundAttributes;
0041     class FrameAttributes;
0042     class PaintContext;
0043 
0044 
0045 /**
0046   * @class AbstractAreaBase KChartAbstractAreaBase.h
0047   * @brief Base class for AbstractArea and AbstractAreaWidget: An area
0048   * in the chart with a background, a frame, etc.
0049   *
0050   * AbstractAreaBase is the base class for all chart elements that have
0051   * a set of background attributes and frame attributes, such as
0052   * legends or axes.
0053   *
0054   * @note Normally you should not use AbstractAreaBase directly, but
0055   * derive your classes from AbstractArea or AbstractAreaWidget.
0056   *
0057   * @note This classis not a QObject, so it is easier to inherit from
0058   * it, if your are inheriting from a QObject too like AbstractAreaWidget does it.
0059   *
0060   * @sa AbstractArea, AbstractAreaWidget
0061   */
0062 class KCHART_EXPORT AbstractAreaBase
0063 {
0064     Q_DISABLE_COPY( AbstractAreaBase )
0065     KCHART_DECLARE_PRIVATE_BASE_POLYMORPHIC( AbstractAreaBase )
0066 
0067 protected:
0068     AbstractAreaBase();
0069     virtual ~AbstractAreaBase() ;
0070 
0071 public:
0072    /**
0073      * Returns true if both areas have the same settings.
0074      */
0075     bool compare( const AbstractAreaBase* other ) const;
0076 
0077     void alignToReferencePoint( const RelativePosition& position );
0078 
0079     void setFrameAttributes( const FrameAttributes &a );
0080     FrameAttributes frameAttributes() const;
0081 
0082     void setBackgroundAttributes( const BackgroundAttributes &a );
0083     BackgroundAttributes backgroundAttributes() const;
0084 
0085     virtual void paintBackground( QPainter& painter, const QRect& rectangle );
0086     virtual void paintFrame( QPainter& painter, const QRect& rectangle );
0087 
0088     static void paintBackgroundAttributes( QPainter& painter, const QRect& rectangle,
0089         const KChart::BackgroundAttributes& attributes );
0090     static void paintFrameAttributes( QPainter& painter, const QRect& rectangle,
0091         const KChart::FrameAttributes& attributes );
0092 
0093     /** \internal
0094       * \note Normally you should not call this method, but derive your classes
0095       * from AbstractArea or AbstractAreaWidget.
0096       * \sa AbstractArea, AbstractAreaWidget
0097       */
0098     void getFrameLeadings(int& left, int& top, int& right, int& bottom ) const;
0099 
0100 
0101 protected:
0102     /** \internal
0103       * \note Normally you should not call this method, but derive your classes
0104       * from AbstractArea or AbstractAreaWidget.
0105       * \sa AbstractArea, AbstractAreaWidget
0106       */
0107     QRect innerRect() const;
0108 
0109     /** \internal
0110       * This internal method is used by AbstractArea and AbstractAreaWidget
0111       * to find out the real widget size.
0112       * \sa AbstractArea, AbstractAreaWidget
0113       */
0114     virtual QRect areaGeometry() const = 0;
0115 
0116     /** \internal
0117       * This internal method can be overwritten by derived classes,
0118       * if they want to emit a signal (or perform other actions, resp.)
0119       * when the Position of the area has been changed.
0120       * The default implementation does nothing.
0121       */
0122     virtual void positionHasChanged();
0123 
0124 }; // End of class AbstractAreaBase
0125 
0126 }
0127 #endif // KCHARTABSTRACTAREABASE_H