File indexing completed on 2024-05-12 15:53:53

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 "framewidget.h"
0021 
0022 #include <KChartChart>
0023 
0024 #include <QDebug>
0025 #include <QPainter>
0026 
0027 FrameWidget::FrameWidget( QWidget* parent, Qt::WindowFlags f )
0028     : QWidget( parent, f )
0029     , mChart( nullptr )
0030 {
0031     // this bloc left empty intentionally
0032 }
0033 
0034 void FrameWidget::setChart( KChart::Chart* chart )
0035 {
0036     mChart = chart;
0037     // This is necessary because Chart can't automatically schedule somebody else (this object) to
0038     // call its custom paint method.
0039     connect( mChart, SIGNAL(propertiesChanged()), SLOT(update()) );
0040 }
0041 
0042 void FrameWidget::paintEvent( QPaintEvent* e )
0043 {
0044     if ( !mChart ) {
0045         QWidget::paintEvent( e );
0046     } else {
0047         QPainter painter( this );
0048 
0049         const int wid = 64;
0050         const QRect  r( rect() );
0051         const QPen   oldPen(   painter.pen() );
0052         const QBrush oldBrush( painter.brush() );
0053         // paint below the chart
0054         painter.setPen( QPen(Qt::NoPen) );
0055         painter.setBrush( QBrush(QColor(0xd0,0xd0,0xff)) );
0056         painter.drawEllipse(r.left(),                 r.top(),                  wid,wid);
0057         painter.drawEllipse(r.left()+r.width()-wid-1, r.top(),                  wid,wid);
0058         painter.drawEllipse(r.left(),                 r.top()+r.height()-wid-1, wid,wid);
0059         painter.drawEllipse(r.left()+r.width()-wid-1, r.top()+r.height()-wid-1, wid,wid);
0060         painter.setBrush( oldBrush );
0061         painter.setPen(   oldPen );
0062         // paint the chart
0063         mChart->paint( &painter, QRect( r.left()+wid/2, r.top()+wid/2,
0064                                         r.width()-wid,  r.height()-wid ) );
0065         // paint over the chart
0066         painter.setPen( QPen(Qt::NoPen) );
0067         painter.setBrush( QBrush(QColor(0xd0,0xff,0xff)) );
0068         const int wid2=40;
0069         const int gap=(wid-wid2)/2;
0070         painter.drawEllipse(r.left()+gap,                 r.top()+gap,                  wid2,wid2);
0071         painter.drawEllipse(r.left()+r.width()-wid+gap-1, r.top()+gap,                  wid2,wid2);
0072         painter.drawEllipse(r.left()+gap,                 r.top()+r.height()-wid+gap-1, wid2,wid2);
0073         painter.drawEllipse(r.left()+r.width()-wid+gap-1, r.top()+r.height()-wid+gap-1, wid2,wid2);
0074         painter.setBrush( oldBrush );
0075         painter.setPen(   oldPen );
0076     }
0077 }