moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kalzium / src / plotwidget.cpp
blobdeab10cbb1fb67976d3ce07fdb164d9ad635c5ad
1 /***************************************************************************
3 plotwidget.cpp - description
4 -------------------
5 copyright : (C) 2004 by Carsten Niehaus
6 email : cniehaus@kde.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "plotwidget.h"
20 //KDE-Includes
21 #include <kdebug.h>
22 #include <kimageio.h>
24 //QT-Includes
25 #include <qpainter.h>
27 PlotWidget::PlotWidget( double x1,
28 double x2,
29 double y1,
30 double y2,
31 QWidget *parent,
32 const char* name)
33 : KPlotWidget( x1, x2, y1, y2, parent, name )
35 m_connectPoints = false;
38 void PlotWidget::drawObjects( QPainter *p )
40 for ( KPlotObject *po = ObjectList.first(); po; po = ObjectList.next() ) {
42 if ( po->points()->count() ) {
43 //draw the plot object
44 p->setPen( QColor( po->color() ) );
46 switch ( po->type() ) {
47 case KPlotObject::POINTS :
49 p->setBrush( QColor( po->color() ) );
51 for ( DPoint *dp = po->points()->first(); dp; dp = po->points()->next() )
53 QPoint q = dp->qpoint( PixRect, DataRect );
54 int x1 = q.x() - po->size()/2;
55 int y1 = q.y() - po->size()/2;
57 switch( po->param() )
59 case KPlotObject::CIRCLE :
60 p->drawEllipse( x1, y1, po->size(), po->size() );
61 break;
62 case KPlotObject::SQUARE : p->drawRect( x1, y1, po->size(), po->size() ); break;
63 case KPlotObject::LETTER : p->drawText( q, po->name().left(1) ); break;
64 default: p->drawPoint( q );
67 if (m_connectPoints)
69 int p1x, p1y, //the first point
70 p2x, p2y; //the second point
72 DPoint *dp = po->points()->first();
74 while ( dp )
76 QPoint point = dp->qpoint( PixRect, DataRect );
77 p1x = point.x();
78 p1y = point.y();
80 p->drawLine(p1x,p1y,p2x,p2y);
82 p2x = p1x;
83 p2y = p1y;
85 dp = po->points()->next();
88 kdDebug() << "nach der for-Schleife" << endl;
90 p->setBrush( Qt::NoBrush );
91 break;
94 case KPlotObject::CURVE :
96 p->setPen( QPen( QColor( po->color() ), po->size(), (QPen::PenStyle)po->param() ) );
97 DPoint *dp = po->points()->first();
98 p->moveTo( dp->qpoint( PixRect, DataRect ) );
99 for ( dp = po->points()->next(); dp; dp = po->points()->next() )
100 p->lineTo( dp->qpoint( PixRect, DataRect ) );
101 break;
104 case KPlotObject::LABEL : //draw label centered at point in x, and slightly below point in y.
106 QPoint q = po->points()->first()->qpoint( PixRect, DataRect );
107 p->drawText( q.x()-20, q.y()+6, 40, 10, Qt::AlignCenter | Qt::DontClip, po->name() );
108 break;
111 case KPlotObject::POLYGON :
113 p->setPen( QPen( QColor( po->color() ), po->size(), (QPen::PenStyle)po->param() ) );
114 p->setBrush( po->color() );
116 QPointArray a( po->count() );
118 unsigned int i=0;
119 for ( DPoint *dp = po->points()->first(); dp; dp = po->points()->next() )
120 a.setPoint( i++, dp->qpoint( PixRect, DataRect ) );
122 p->drawPolygon( a );
123 break;
126 case KPlotObject::UNKNOWN_TYPE : break;
132 #include "plotwidget.moc"