1 /***************************************************************************
3 plotwidget.cpp - description
5 copyright : (C) 2004 by Carsten Niehaus
6 email : cniehaus@kde.org
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #include "plotwidget.h"
27 PlotWidget::PlotWidget( double x1
,
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;
59 case KPlotObject::CIRCLE
:
60 p
->drawEllipse( x1
, y1
, po
->size(), po
->size() );
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
);
69 int p1x
, p1y
, //the first point
70 p2x
, p2y
; //the second point
72 DPoint
*dp
= po
->points()->first();
76 QPoint point
= dp
->qpoint( PixRect
, DataRect
);
80 p
->drawLine(p1x
,p1y
,p2x
,p2y
);
85 dp
= po
->points()->next();
88 kdDebug() << "nach der for-Schleife" << endl
;
90 p
->setBrush( Qt::NoBrush
);
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
) );
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() );
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() );
119 for ( DPoint
*dp
= po
->points()->first(); dp
; dp
= po
->points()->next() )
120 a
.setPoint( i
++, dp
->qpoint( PixRect
, DataRect
) );
126 case KPlotObject::UNKNOWN_TYPE
: break;
132 #include "plotwidget.moc"