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 KCHARTABSTRACTAREAWIDGET_H 0021 #define KCHARTABSTRACTAREAWIDGET_H 0022 0023 #include <QWidget> 0024 #include <QPaintEvent> 0025 #include <QPainter> 0026 #include <QRect> 0027 0028 #include "KChartAbstractAreaBase.h" 0029 0030 namespace KChart { 0031 0032 0033 /** 0034 * @class AbstractAreaWidget KChartAbstractArea.h 0035 * @brief An area in the chart with a background, a frame, etc. 0036 * 0037 * AbstractAreaWidget is the base for all widget classes that have 0038 * a set of background attributes and frame attributes, such as 0039 * KChart::Chart and KChart::Legend. 0040 */ 0041 class KCHART_EXPORT AbstractAreaWidget : public QWidget, public AbstractAreaBase 0042 { 0043 Q_OBJECT 0044 0045 Q_DISABLE_COPY( AbstractAreaWidget ) 0046 KCHART_DECLARE_PRIVATE_DERIVED_QWIDGET( AbstractAreaWidget ) 0047 0048 public: 0049 explicit AbstractAreaWidget( QWidget* parent = nullptr ); 0050 0051 /** 0052 * @brief Draws the background and frame, then calls paint(). 0053 * 0054 * In most cases there is no need to overwrite this method in a derived 0055 * class, but you would overwrite paint() instead. 0056 * @sa paint 0057 */ 0058 void paintEvent( QPaintEvent* event ) override; 0059 0060 /** 0061 * @brief Draws the background and frame, then calls paint(). 0062 * 0063 * In most cases there is no need to overwrite this method in a derived 0064 * class, but you would overwrite paint() instead. 0065 */ 0066 virtual void paintIntoRect( QPainter& painter, const QRect& rect ); 0067 0068 /** 0069 * Overwrite this to paint the inner contents of your widget. 0070 * 0071 * @note When overriding this method, please let your widget draw 0072 * itself at the top/left corner of the painter. You should call rect() 0073 * (or width(), height(), resp.) to find the drawable area's size: 0074 * While the paint() method is being executed the frame of the widget 0075 * is outside of its rect(), so you can use all of rect() for 0076 * your custom drawing! 0077 * @sa paint, paintIntoRect 0078 */ 0079 virtual void paint( QPainter* painter ) = 0; 0080 0081 /** 0082 * Call paintAll, if you want the background and the frame to be drawn 0083 * before the normal paint() is invoked automatically. 0084 */ 0085 void paintAll( QPainter& painter ); 0086 0087 /** 0088 * Call this to trigger an unconditional re-building of the widget's internals. 0089 */ 0090 virtual void forceRebuild(); 0091 0092 /** 0093 * Call this to trigger an conditional re-building of the widget's internals. 0094 * 0095 * e.g. AbstractAreaWidget call this, before calling layout()->setGeometry() 0096 */ 0097 virtual void needSizeHint(); 0098 virtual void resizeLayout( const QSize& ); 0099 0100 Q_SIGNALS: 0101 void positionChanged( AbstractAreaWidget * ); 0102 0103 protected: 0104 virtual ~AbstractAreaWidget() ; 0105 QRect areaGeometry() const override; 0106 void positionHasChanged() override; 0107 }; 0108 0109 } 0110 #endif // KCHARTABSTRACTAREAWIDGET_H