File indexing completed on 2024-05-12 04:20:06

0001 /**
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "framewidget.h"
0010 
0011 #include <KChartChart>
0012 
0013 #include <QDebug>
0014 #include <QPainter>
0015 
0016 FrameWidget::FrameWidget( QWidget* parent, Qt::WindowFlags f )
0017     : QWidget( parent, f )
0018     , mChart( nullptr )
0019 {
0020     // this block left empty intentionally
0021 }
0022 
0023 void FrameWidget::setChart( KChart::Chart* chart )
0024 {
0025     mChart = chart;
0026     // This is necessary because Chart can't automatically schedule somebody else (this object) to
0027     // call its custom paint method.
0028     connect( mChart, SIGNAL(propertiesChanged()), SLOT(update()) );
0029 }
0030 
0031 void FrameWidget::paintEvent( QPaintEvent* e )
0032 {
0033     if ( !mChart ) {
0034         QWidget::paintEvent( e );
0035     } else {
0036         QPainter painter( this );
0037 
0038         const int wid = 64;
0039         const QRect r( rect() );
0040         const QPen oldPen( painter.pen() );
0041         const QBrush oldBrush( painter.brush() );
0042         // paint below the chart
0043         painter.setPen( QPen( Qt::NoPen ) );
0044         painter.setBrush( QBrush( QColor( 0xd0, 0xd0, 0xff ) ) );
0045         painter.drawEllipse( r.left(),                       r.top(),                        wid, wid );
0046         painter.drawEllipse( r.left() + r.width() - wid - 1, r.top(),                        wid, wid );
0047         painter.drawEllipse( r.left(),                       r.top() + r.height() - wid - 1, wid, wid );
0048         painter.drawEllipse( r.left() + r.width() - wid - 1, r.top() + r.height() - wid - 1, wid, wid );
0049         painter.setBrush( oldBrush );
0050         painter.setPen( oldPen );
0051         // paint the chart
0052         mChart->paint( &painter, QRect( r.left() + wid / 2, r.top() + wid / 2,
0053                                         r.width() - wid,    r.height() - wid ) );
0054         // paint over the chart
0055         painter.setPen( QPen( Qt::NoPen ) );
0056         painter.setBrush( QBrush( QColor( 0xd0, 0xff, 0xff ) ) );
0057         const int wid2 = 40;
0058         const int gap = ( wid - wid2 ) / 2;
0059         painter.drawEllipse( r.left() + gap,                       r.top() + gap,                        wid2, wid2 );
0060         painter.drawEllipse( r.left() + r.width() - wid + gap - 1, r.top() + gap,                        wid2, wid2 );
0061         painter.drawEllipse( r.left() + gap,                       r.top() + r.height() - wid + gap - 1, wid2, wid2 );
0062         painter.drawEllipse( r.left() + r.width() - wid + gap - 1, r.top() + r.height() - wid + gap - 1, wid2, wid2 );
0063         painter.setBrush( oldBrush );
0064         painter.setPen( oldPen );
0065     }
0066 }