KChart

KChartAbstractAreaWidget.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KChartAbstractAreaWidget.h"
10#include "KChartAbstractAreaWidget_p.h"
11
12#include "KChartMath_p.h"
13
14
15using namespace KChart;
16
17
18AbstractAreaWidget::Private::Private()
19{
20 // this block left empty intentionally
21}
22
23AbstractAreaWidget::Private::~Private()
24{
25 // this block left empty intentionally
26}
27
28
29void AbstractAreaWidget::Private::resizeLayout(
30 AbstractAreaWidget* widget, const QSize& size )
31{
32 if ( size == currentLayoutSize ) return;
33
34 currentLayoutSize = size;
35
36 // Now we call adjust the size, for the inner parts of the widget.
37 int left;
38 int top;
39 int right;
40 int bottom;
41 widget->getFrameLeadings( left, top, right, bottom );
42 const QSize innerSize( size.width() - left - right,
43 size.height() - top - bottom );
44 // With this adjusted size we call the real resizeLayout method,
45 // which normally will call resizeLayout( size ) in the derived class
46 // - which in turn is the place to resize the layout of that class.
47 widget->resizeLayout( innerSize );
48}
49
50
51AbstractAreaWidget::AbstractAreaWidget( QWidget* parent )
52 : QWidget( parent )
53 , AbstractAreaBase( new Private() )
54{
55 init();
56}
57
58AbstractAreaWidget::~AbstractAreaWidget()
59{
60 // this block left empty intentionally
61}
62
63void AbstractAreaWidget::init()
64{
65 // this block left empty intentionally
66}
67
69{
70 // this block left empty intentionally
71}
72
73#define d d_func()
74
75void AbstractAreaWidget::resizeLayout( const QSize& size )
76{
77 Q_UNUSED( size );
78 // this block left empty intentionally
79}
80
82{
83 Q_UNUSED( event );
84 QPainter painter( this );
85 if ( size() != d->currentLayoutSize ) {
86 d->resizeLayout( this, size() );
87 }
88 paintAll( painter );
89}
90
92{
93 if ( rect.isEmpty() ) return;
94
95 d->resizeLayout( this, rect.size() );
96
97 const QPoint translation( rect.topLeft() );
98 painter.translate( translation );
99 paintAll( painter );
100 painter.translate( -translation.x(), -translation.y() );
101
102/*
103 // guide for subclassing
104
105 // set up the contents of the widget so we get a useful geometry
106 needSizeHint();
107
108 const QRect oldGeometry( layout()->geometry() );
109 const QRect newGeo( QPoint(0,0), rect.size() );
110 const bool mustChangeGeo = layout() && oldGeometry != newGeo;
111 if ( mustChangeGeo )
112 layout()->setGeometry( newGeo );
113 painter.translate( rect.left(), rect.top() );
114 paintAll( painter );
115 painter.translate( -rect.left(), -rect.top() );
116 if ( mustChangeGeo )
117 layout()->setGeometry( oldGeometry );
118*/
119}
120
122{
123 // this block left empty intentionally
124}
125
127{
128 paintBackground( painter, QRect(QPoint(0, 0), size() ) );
129 paintFrame( painter, QRect(QPoint(0, 0), size() ) );
130
131/*
132 // guide for subclassing
133
134 // we do not call setContentsMargins() now,
135 // but we call resizeLayout() whenever the size or the frame has changed
136
137 // adjust the widget's content margins,
138 // to be sure all content gets calculated
139 // to fit into the inner rectangle
140 const QRect oldGeometry( areaGeometry() );
141 const QRect inner( innerRect() );
142 //qDebug() << "areaGeometry():" << oldGeometry
143 // << " contentsRect():" << contentsRect() << " inner:" << inner;
144 if ( contentsRect() != inner ) {
145 //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner;
146 setContentsMargins(
147 inner.left(),
148 inner.top(),
149 oldGeometry.width() - inner.width() - 1,
150 oldGeometry.height() - inner.height() - 1 );
151 //forceRebuild();
152 }
153*/
154 int left;
155 int top;
156 int right;
157 int bottom;
158 getFrameLeadings( left, top, right, bottom );
159 const QPoint translation( left, top );
160 painter.translate( translation );
161 paint( &painter );
162 painter.translate( -translation.x(), -translation.y() );
163}
164
166{
167 return geometry();
168}
169
171{
172 Q_EMIT positionChanged( this );
173}
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background,...
void getFrameLeadings(int &left, int &top, int &right, int &bottom) const
An area in the chart with a background, a frame, etc.
virtual void needSizeHint()
Call this to trigger an conditional re-building of the widget's internals.
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
virtual void paint(QPainter *painter)=0
Overwrite this to paint the inner contents of your widget.
virtual void forceRebuild()
Call this to trigger an unconditional re-building of the widget's internals.
void paintEvent(QPaintEvent *event) override
Draws the background and frame, then calls paint().
void paintAll(QPainter &painter)
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
Q_EMITQ_EMIT
T qobject_cast(QObject *object)
void translate(const QPoint &offset)
int x() const const
int y() const const
int height() const const
int width() const const
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 11:55:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.