KChart

KChartTextArea.cpp
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 
33 TextArea::Private::Private() :
34  AbstractAreaBase::Private()
35 {
36  // this bloc left empty intentionally
37 }
38 
39 
40 TextArea::Private::~Private()
41 {
42  // this bloc left empty intentionally
43 }
44 
45 
46 TextArea::TextArea()
47  : QObject()
50 {
51  // this bloc left empty intentionally
52 }
53 
54 TextArea::~TextArea()
55 {
56  // this bloc left empty intentionally
57 }
58 
59 
60 void TextArea::init()
61 {
62  // this bloc left empty intentionally
63 }
64 
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 
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 
100 {
101  return geometry();
102 }
103 
105 {
106  emit positionChanged( this );
107 }
108 
QRect areaGeometry() const override
const QRect & geometry() const const
void moveTo(int x, int y)
void paintAll(QPainter &painter) override
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
int top() const const
Class only listed here to document inheritance of some KChart classes.
int left() const const
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background, a frame, etc.
void positionHasChanged() override
QRect rect() const const
Layout item showing a text.
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
void translate(const QPointF &offset)
Global namespace.
void setGeometry(int x, int y, int w, int h)
void paint(PaintContext *paintContext) override
Draw the diagram contents to the rectangle and painter, that are passed in as part of the paint conte...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Sep 19 2020 22:36:26 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.