You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
5.9 KiB
206 lines
5.9 KiB
15 years ago
|
/***************************************************************************
|
||
|
kplotobject.h - A list of points to be plotted
|
||
|
-------------------
|
||
|
begin : Sun 18 May 2003
|
||
|
copyright : (C) 2003 by Jason Harris
|
||
|
email : kstars@30doradus.org
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#ifndef KPLOTOBJECT_H
|
||
|
#define KPLOTOBJECT_H
|
||
|
|
||
|
|
||
15 years ago
|
class TQString;
|
||
|
class TQPainter;
|
||
15 years ago
|
|
||
|
#include <kdemacros.h>
|
||
|
|
||
|
/**class DRect
|
||
15 years ago
|
*@short equivalent of TQRect with double x,y coordinates
|
||
15 years ago
|
*@author Jason Harris
|
||
|
*@version 1.0
|
||
|
*/
|
||
|
class KDE_EXPORT DRect {
|
||
|
public:
|
||
|
DRect() { DRect( 0.0, 0.0, 1.0, 1.0 ); }
|
||
|
DRect( double x, double y, double w, double h ) { X = x; Y = y; W = w; H = h; }
|
||
|
~DRect() {}
|
||
|
|
||
|
double x() const { return X; }
|
||
|
double y() const { return Y; }
|
||
|
double x2() const { return X + W; }
|
||
|
double y2() const { return Y + H; }
|
||
|
double width() const { return W; }
|
||
|
double height() const { return H; }
|
||
|
|
||
|
void setX( double x ) { X = x; }
|
||
|
void setY( double y ) { Y = y; }
|
||
|
void setWidth( double w ) { W = w; }
|
||
|
void setHeight( double h ) { H = h; }
|
||
|
|
||
|
private:
|
||
|
double X,Y,W,H;
|
||
|
};
|
||
|
|
||
|
/**class DPoint
|
||
15 years ago
|
*@short equivalent of TQPoint with double x,y coordinates
|
||
15 years ago
|
*@author Jason Harris
|
||
|
*@version 1.0
|
||
|
*/
|
||
|
class KDE_EXPORT DPoint {
|
||
|
public:
|
||
|
DPoint() { DPoint( 0.0, 0.0 ); }
|
||
|
DPoint( double x, double y ) { setX( x ); setY( y ); }
|
||
|
~DPoint() {}
|
||
|
|
||
|
double x() const { return X; }
|
||
|
double y() const { return Y; }
|
||
|
|
||
15 years ago
|
TQPoint qpoint( TQRect pb, DRect db ) {
|
||
15 years ago
|
int px = pb.left() + int( pb.width()*( x() - db.x() )/db.width() );
|
||
|
int py = pb.top() + int( pb.height()*( db.y2() - y() )/db.height() );
|
||
15 years ago
|
return TQPoint( px, py );
|
||
15 years ago
|
}
|
||
|
|
||
|
void setX( double x ) { X = x; }
|
||
|
void setY( double y ) { Y = y; }
|
||
|
|
||
|
private:
|
||
|
double X, Y;
|
||
|
};
|
||
|
|
||
|
/**@class KPlotObject
|
||
|
*@short Encapsulates an object to be plotted in a KPlotWidget.
|
||
|
*@author Jason Harris
|
||
|
*@version 1.0
|
||
14 years ago
|
*Each KPlotObject consists of a list of TQPoints, an object type, a color, a size,
|
||
15 years ago
|
*and a TQString name. An additional integer (param) specifies something further
|
||
15 years ago
|
*about the object's appearance, depending on its type. There is a draw function
|
||
15 years ago
|
*for plotting the object on a KPlotWidget's TQPainter.
|
||
15 years ago
|
*/
|
||
|
class KDE_EXPORT KPlotObject{
|
||
|
public:
|
||
|
/**@enum PTYPE
|
||
|
*The Type classification of the KPlotObject
|
||
|
*/
|
||
|
enum PTYPE { POINTS=0, CURVE=1, LABEL=2, POLYGON=3, UNKNOWN_TYPE };
|
||
|
|
||
|
/**@enum PPARAM
|
||
|
*Parameter specifying the kind of points
|
||
|
*/
|
||
|
enum PPARAM { DOT=0, CIRCLE=1, SQUARE=2, LETTER=3, UNKNOWN_POINT };
|
||
|
|
||
|
/**@enum CPARAM
|
||
|
*Parameter specifying the kind of line. These are numerically equal to
|
||
14 years ago
|
*the TQt::PenStyle enum values.
|
||
15 years ago
|
*/
|
||
|
enum CPARAM { NO_LINE=0, SOLID=1, DASHED=2, DOTTED=3, DASHDOTTED=4, DASHDOTDOTTED=5, UNKNOWN_CURVE };
|
||
|
|
||
|
/**Default constructor. Create a POINTS-type object with an empty list of points.
|
||
|
*/
|
||
|
KPlotObject();
|
||
|
|
||
|
/**Constructor. Create a KPlotObject according to the arguments.
|
||
|
*/
|
||
15 years ago
|
KPlotObject( const TQString &name, const TQString &color, PTYPE otype, unsigned int size=2, unsigned int param=0 );
|
||
15 years ago
|
|
||
|
/**Destructor (empty)
|
||
|
*/
|
||
|
~KPlotObject();
|
||
|
|
||
|
/**@return the KPlotObject's Name
|
||
|
*/
|
||
15 years ago
|
TQString name() const { return Name; }
|
||
15 years ago
|
|
||
|
/**@short set the KPlotObject's Name
|
||
|
*@param n the new name
|
||
|
*/
|
||
15 years ago
|
void setName( const TQString &n ) { Name = n; }
|
||
15 years ago
|
|
||
|
/**@return the KPlotObject's Color
|
||
|
*/
|
||
15 years ago
|
TQString color() const { return Color; }
|
||
15 years ago
|
|
||
|
/**@short set the KPlotObject's Color
|
||
|
*@param c the new color
|
||
|
*/
|
||
15 years ago
|
void setColor( const TQString &c ) { Color = c; }
|
||
15 years ago
|
|
||
|
/**@return the KPlotObject's Type
|
||
|
*/
|
||
|
PTYPE type() const { return Type; }
|
||
|
|
||
|
/**@short set the KPlotObject's Type
|
||
|
*@param t the new type
|
||
|
*/
|
||
|
void setType( PTYPE t ) { Type = t; }
|
||
|
|
||
|
/**@return the KPlotObject's Size
|
||
|
*/
|
||
|
unsigned int size() const { return Size; }
|
||
|
|
||
|
/**@short set the KPlotObject's Size
|
||
|
*@param s the new size
|
||
|
*/
|
||
|
void setSize( unsigned int s ) { Size = s; }
|
||
|
|
||
|
/**@return the KPlotObject's type-specific Parameter
|
||
|
*Parameter is an unsigned int because it can either be a PPARAM or a CPARAM enum.
|
||
|
*/
|
||
|
unsigned int param() const { return Parameter; }
|
||
|
|
||
|
/**@short set the KPlotObject's type-specific Parameter
|
||
|
*@param p the new parameter
|
||
|
*Parameter is an unsigned int because it can either be a PPARAM or a CPARAM enum.
|
||
|
*/
|
||
|
void setParam( unsigned int p ) { Parameter = p; }
|
||
|
|
||
|
/**@return a pointer to the DPoint at position i
|
||
|
*@param i the index of the desired point.
|
||
|
*/
|
||
|
DPoint* point( unsigned int i ) { return pList.at(i); }
|
||
|
|
||
15 years ago
|
TQPtrList<DPoint>* points() { return &pList; }
|
||
15 years ago
|
|
||
|
/**@short Add a point to the object's list.
|
||
|
*@param p the DPoint to add.
|
||
|
*/
|
||
|
void addPoint( const DPoint &p ) { pList.append( new DPoint( p.x(), p.y() ) ); }
|
||
|
|
||
|
/**@short Add a point to the object's list. This is an overloaded function,
|
||
|
*provided for convenience. It behaves essentially like the above function.
|
||
|
*@param p pointer to the DPoint to add.
|
||
|
*/
|
||
|
void addPoint( DPoint *p ) { pList.append( p ); }
|
||
|
|
||
15 years ago
|
/**@short remove the TQPoint at position index from the list of points
|
||
15 years ago
|
*@param index the index of the point to be removed.
|
||
|
*/
|
||
|
void removePoint( unsigned int index );
|
||
|
|
||
14 years ago
|
/**@return the number of TQPoints currently in the list
|
||
15 years ago
|
*/
|
||
|
unsigned int count() const { return pList.count(); }
|
||
|
|
||
|
/**@short clear the Object's points list
|
||
|
*/
|
||
|
void clearPoints() { pList.clear(); }
|
||
|
|
||
|
private:
|
||
15 years ago
|
TQPtrList<DPoint> pList;
|
||
15 years ago
|
PTYPE Type;
|
||
|
unsigned int Size, Parameter;
|
||
15 years ago
|
TQString Color, Name;
|
||
15 years ago
|
};
|
||
|
|
||
|
#endif
|