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 #include "KChartTextArea.h"
21 #include "KChartTextArea_p.h"
22 
23 #include "KChartMath_p.h"
24 
25 #include <qglobal.h>
26 
27 #include <QPainter>
28 #include <QRect>
29 
30 
31 using namespace KChart;
32 
Private()33 TextArea::Private::Private() :
34     AbstractAreaBase::Private()
35 {
36     // this bloc left empty intentionally
37 }
38 
39 
~Private()40 TextArea::Private::~Private()
41 {
42     // this bloc left empty intentionally
43 }
44 
45 
TextArea()46 TextArea::TextArea()
47     : QObject()
48     , KChart::AbstractAreaBase()
49     , KChart::TextLayoutItem()
50 {
51     // this bloc left empty intentionally
52 }
53 
~TextArea()54 TextArea::~TextArea()
55 {
56     // this bloc left empty intentionally
57 }
58 
59 
init()60 void TextArea::init()
61 {
62     // this bloc left empty intentionally
63 }
64 
paintIntoRect(QPainter & painter,const QRect & rect)65 void TextArea::paintIntoRect( QPainter& painter, const QRect& rect )
66 {
67     const QRect oldGeometry( geometry() );
68     if ( oldGeometry != rect )
69         setGeometry( rect );
70     painter.translate( rect.left(), rect.top() );
71     paintAll( painter );
72     painter.translate( -rect.left(), -rect.top() );
73     if ( oldGeometry != rect )
74         setGeometry( oldGeometry );
75 }
76 
paintAll(QPainter & painter)77 void TextArea::paintAll( QPainter& painter )
78 {
79     // Paint the background and frame
80     paintBackground( painter, geometry() );
81     paintFrame( painter, geometry() );
82 
83     // temporarily adjust the widget size, to be sure all content gets calculated
84     // to fit into the inner rectangle
85     const QRect oldGeometry( areaGeometry() );
86     QRect inner( innerRect() );
87     inner.moveTo(
88         oldGeometry.left() + inner.left(),
89         oldGeometry.top()  + inner.top() );
90     const bool needAdjustGeometry = oldGeometry != inner;
91     if ( needAdjustGeometry )
92         setGeometry( inner );
93     paint( &painter );
94     if ( needAdjustGeometry )
95         setGeometry( oldGeometry );
96     //qDebug() << "TextAreaWidget::paintAll() done.";
97 }
98 
areaGeometry() const99 QRect TextArea::areaGeometry() const
100 {
101     return geometry();
102 }
103 
positionHasChanged()104 void TextArea::positionHasChanged()
105 {
106     Q_EMIT positionChanged( this );
107 }
108 
109