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

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 #include "KChartTextArea.h"
0021 #include "KChartTextArea_p.h"
0022 
0023 #include "KChartMath_p.h"
0024 
0025 #include <qglobal.h>
0026 
0027 #include <QPainter>
0028 #include <QRect>
0029 
0030 
0031 using namespace KChart;
0032 
0033 TextArea::Private::Private() :
0034     AbstractAreaBase::Private()
0035 {
0036     // this bloc left empty intentionally
0037 }
0038 
0039 
0040 TextArea::Private::~Private()
0041 {
0042     // this bloc left empty intentionally
0043 }
0044 
0045 
0046 TextArea::TextArea()
0047     : QObject()
0048     , KChart::AbstractAreaBase()
0049     , KChart::TextLayoutItem()
0050 {
0051     // this bloc left empty intentionally
0052 }
0053 
0054 TextArea::~TextArea()
0055 {
0056     // this bloc left empty intentionally
0057 }
0058 
0059 
0060 void TextArea::init()
0061 {
0062     // this bloc left empty intentionally
0063 }
0064 
0065 void TextArea::paintIntoRect( QPainter& painter, const QRect& rect )
0066 {
0067     const QRect oldGeometry( geometry() );
0068     if ( oldGeometry != rect )
0069         setGeometry( rect );
0070     painter.translate( rect.left(), rect.top() );
0071     paintAll( painter );
0072     painter.translate( -rect.left(), -rect.top() );
0073     if ( oldGeometry != rect )
0074         setGeometry( oldGeometry );
0075 }
0076 
0077 void TextArea::paintAll( QPainter& painter )
0078 {
0079     // Paint the background and frame
0080     paintBackground( painter, geometry() );
0081     paintFrame( painter, geometry() );
0082 
0083     // temporarily adjust the widget size, to be sure all content gets calculated
0084     // to fit into the inner rectangle
0085     const QRect oldGeometry( areaGeometry() );
0086     QRect inner( innerRect() );
0087     inner.moveTo(
0088         oldGeometry.left() + inner.left(),
0089         oldGeometry.top()  + inner.top() );
0090     const bool needAdjustGeometry = oldGeometry != inner;
0091     if ( needAdjustGeometry )
0092         setGeometry( inner );
0093     paint( &painter );
0094     if ( needAdjustGeometry )
0095         setGeometry( oldGeometry );
0096     //qDebug() << "TextAreaWidget::paintAll() done.";
0097 }
0098 
0099 QRect TextArea::areaGeometry() const
0100 {
0101     return geometry();
0102 }
0103 
0104 void TextArea::positionHasChanged()
0105 {
0106     Q_EMIT positionChanged( this );
0107 }
0108