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 KCHARTABSTRACTAREAWIDGET_H 21 #define KCHARTABSTRACTAREAWIDGET_H 22 23 #include <QWidget> 24 #include <QPaintEvent> 25 #include <QPainter> 26 #include <QRect> 27 28 #include "KChartAbstractAreaBase.h" 29 30 namespace KChart { 31 32 33 /** 34 * @class AbstractAreaWidget KChartAbstractArea.h 35 * @brief An area in the chart with a background, a frame, etc. 36 * 37 * AbstractAreaWidget is the base for all widget classes that have 38 * a set of background attributes and frame attributes, such as 39 * KChart::Chart and KChart::Legend. 40 */ 41 class KCHART_EXPORT AbstractAreaWidget : public QWidget, public AbstractAreaBase 42 { 43 Q_OBJECT 44 45 Q_DISABLE_COPY( AbstractAreaWidget ) 46 KCHART_DECLARE_PRIVATE_DERIVED_QWIDGET( AbstractAreaWidget ) 47 48 public: 49 explicit AbstractAreaWidget( QWidget* parent = nullptr ); 50 51 /** 52 * @brief Draws the background and frame, then calls paint(). 53 * 54 * In most cases there is no need to overwrite this method in a derived 55 * class, but you would overwrite paint() instead. 56 * @sa paint 57 */ 58 void paintEvent( QPaintEvent* event ) override; 59 60 /** 61 * @brief Draws the background and frame, then calls paint(). 62 * 63 * In most cases there is no need to overwrite this method in a derived 64 * class, but you would overwrite paint() instead. 65 */ 66 virtual void paintIntoRect( QPainter& painter, const QRect& rect ); 67 68 /** 69 * Overwrite this to paint the inner contents of your widget. 70 * 71 * @note When overriding this method, please let your widget draw 72 * itself at the top/left corner of the painter. You should call rect() 73 * (or width(), height(), resp.) to find the drawable area's size: 74 * While the paint() method is being executed the frame of the widget 75 * is outside of its rect(), so you can use all of rect() for 76 * your custom drawing! 77 * @sa paint, paintIntoRect 78 */ 79 virtual void paint( QPainter* painter ) = 0; 80 81 /** 82 * Call paintAll, if you want the background and the frame to be drawn 83 * before the normal paint() is invoked automatically. 84 */ 85 void paintAll( QPainter& painter ); 86 87 /** 88 * Call this to trigger an unconditional re-building of the widget's internals. 89 */ 90 virtual void forceRebuild(); 91 92 /** 93 * Call this to trigger an conditional re-building of the widget's internals. 94 * 95 * e.g. AbstractAreaWidget call this, before calling layout()->setGeometry() 96 */ 97 virtual void needSizeHint(); 98 virtual void resizeLayout( const QSize& ); 99 100 Q_SIGNALS: 101 void positionChanged( AbstractAreaWidget * ); 102 103 protected: 104 virtual ~AbstractAreaWidget() ; 105 QRect areaGeometry() const override; 106 void positionHasChanged() override; 107 }; 108 109 } 110 #endif // KCHARTABSTRACTAREAWIDGET_H 111