add_subdirectory(kdeeducore)
add_subdirectory(kdeeduui)
-add_subdirectory(kdeeduplot)
add_subdirectory(extdate)
add_subdirectory(libscience)
add_subdirectory(widgets)
+++ /dev/null
-# for the kdeeduplot library we have different build options depending on
-# whether we build with Qt4 only or with kde
-
-# *** common variables ***
-
-# sources for the kdeeduplot library
-set( kdeeduplot_LIB_SRCS
- kplotobject.cpp
- kplotaxis.cpp
- kplotwidget.cpp
-)
-
-if (COMPILE_WITH_QT4_ONLY)
-
- # generate moc files automatically (requires that the
- # moc files are included in the cpp files)
- qt4_automoc(${kdeeduplot_LIB_SRCS})
-
- # add the definition for a QT4_ONLY build
- add_definitions( -DQT4_ONLY )
-
- # set include directories for a Qt4 build
- include_directories(
- ${QT_INCLUDES}
- ${CMAKE_BINARY_DIR}/kdeeduplot
- )
-
- # build the kdeeduplot library
- kde4_add_library(kdeeduplot SHARED ${kdeeduplot_LIB_SRCS})
-
- # link Qt4 libraries so that users of the kdeeduplot lib do
- # not have to worry about these dependencies
- target_link_libraries(kdeeduplot ${QT_LIBRARIES} )
-
-else (COMPILE_WITH_QT4_ONLY)
-
- # build test program in the tests subdir
- add_subdirectory( tests )
-
- # generate moc files automatically (requires that the
- # moc files are included in the cpp files)
- kde4_automoc(${kdeeduplot_LIB_SRCS})
-
- # build the kdeeduplot library as shared lib
- kde4_add_library(kdeeduplot SHARED ${kdeeduplot_LIB_SRCS})
-
- # link kdeui library so that users of the kdeeduplot lib do
- # not have to worry about these dependencies
- target_link_libraries(kdeeduplot ${KDE4_KDEUI_LIBS} )
-
- # set the properties for the build
- set_target_properties(kdeeduplot PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
-
- # install the binary library file into the KDE library directory
- install(TARGETS kdeeduplot DESTINATION ${LIB_INSTALL_DIR} )
-
- # install the header files for the kdeeduplot library
- install(FILES
- libkdeedu_plot_export.h
- kplotobject.h
- kplotaxis.h
- kplotwidget.h DESTINATION ${INCLUDE_INSTALL_DIR}/libkdeedu
- )
-
-endif (COMPILE_WITH_QT4_ONLY)
+++ /dev/null
-This library provides the KPlot* classes.
-
-KPlotWidget is a QWidget-derived class that provides a virtual baseclass
-for easy data-plotting. The idea behind KPlotWidget is that you only have
-to specify information in "data units"; i.e., the natural units of the
-data being plotted. KPlotWidget automatically converts everything
-to screen pixel units.
-
-KPlotWidget draws X and Y axes with tickmarks and tick labels. It
-automatically determines how many tickmarks to use and where they should
-be, based on the data limits specified for the plot. You change the limits
-by calling setLimits( double x1, double x2, double y1, double y2 ).
-
-Data to be plotted are stored using the KPlotObject class. KPlotObject
-consists of a QList of QPointF's, each specifying the X,Y coordinates
-of a data point. KPlotObject also specifies the "type" of data to be
-plotted (POINTS or CURVE or POLYGON or LABEL).
-
-Jason Harris
-kstars@30doradus.org
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2005 Andreas Nicolai <Andreas.Nicolai@gmx.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include <math.h> //for log10(), pow(), modf()
-#include <kdebug.h>
-
-#include "kplotaxis.h"
-
-class KPlotAxis::Private
-{
- public:
- Private( KPlotAxis *qq )
- : q( qq ), m_visible( true ), m_showTickLabels( false ),
- m_labelFieldWidth( 0 ), m_labelFmt( 'g' ), m_labelPrec( -1 )
- {
- }
-
- KPlotAxis *q;
-
- bool m_visible; // Property "visible" defines if Axis is drawn or not.
- bool m_showTickLabels;
- QString m_label; // The label of the axis.
- int m_labelFieldWidth; // Field width for number labels, see QString::arg()
- char m_labelFmt; // Number format for number labels, see QString::arg()
- int m_labelPrec; // Number precision for number labels, see QString::arg()
- QList<double> m_MajorTickMarks, m_MinorTickMarks;
-};
-
-KPlotAxis::KPlotAxis( const QString &label )
- : d( new Private( this ) )
-{
- d->m_label = label;
-}
-
-KPlotAxis::~KPlotAxis()
-{
- delete d;
-}
-
-bool KPlotAxis::isVisible() const
-{
- return d->m_visible;
-}
-
-void KPlotAxis::setVisible( bool visible )
-{
- d->m_visible = visible;
-}
-
-bool KPlotAxis::areTickLabelsShown() const
-{
- return d->m_showTickLabels;
-}
-
-void KPlotAxis::setTickLabelsShown( bool b )
-{
- d->m_showTickLabels = b;
-}
-
-void KPlotAxis::setLabel( const QString& label )
-{
- d->m_label = label;
-}
-
-QString KPlotAxis::label() const
-{
- return d->m_label;
-}
-
-void KPlotAxis::setTickLabelFormat( char format, int fieldWidth, int precision )
-{
- d->m_labelFieldWidth = fieldWidth;
- d->m_labelFmt = format;
- d->m_labelPrec = precision;
-}
-
-int KPlotAxis::tickLabelWidth() const
-{
- return d->m_labelFieldWidth;
-}
-
-char KPlotAxis::tickLabelFormat() const
-{
- return d->m_labelFmt;
-}
-
-int KPlotAxis::tickLabelPrecision() const
-{
- return d->m_labelPrec;
-}
-
-void KPlotAxis::setTickMarks( double x0, double length ) {
- d->m_MajorTickMarks.clear();
- d->m_MinorTickMarks.clear();
-
- //s is the power-of-ten factor of length:
- //length = t * s; s = 10^(pwr). e.g., length=350.0 then t=3.5, s = 100.0; pwr = 2.0
- double pwr = 0.0;
- modf( log10( length ), &pwr );
- double s = pow( 10.0, pwr );
- double t = length / s;
-
- double TickDistance = 0.0; //The distance between major tickmarks
- int NumMajorTicks = 0; //will be between 3 and 5
- int NumMinorTicks = 0; //The number of minor ticks between major ticks (will be 4 or 5)
-
- //adjust s and t such that t is between 3 and 5:
- if ( t < 3.0 ) {
- t *= 10.0;
- s /= 10.0;
- // t is now between 3 and 30
- }
-
- if ( t < 6.0 ) { //accept current values
- TickDistance = s;
- NumMajorTicks = int( t );
- NumMinorTicks = 5;
- } else if ( t < 10.0 ) { // adjust by a factor of 2
- TickDistance = s * 2.0;
- NumMajorTicks = int( t / 2.0 );
- NumMinorTicks = 4;
- } else if ( t < 20.0 ) { //adjust by a factor of 4
- TickDistance = s * 4.0;
- NumMajorTicks = int( t / 4.0 );
- NumMinorTicks = 4;
- } else { //adjust by a factor of 5
- TickDistance = s * 5.0;
- NumMajorTicks = int( t / 5.0 );
- NumMinorTicks = 5;
- }
-
- //We have determined the number of tickmarks and their separation
- //Now we determine their positions in the Data space.
-
- //Tick0 is the position of a "virtual" tickmark; the first major tickmark
- //position beyond the "minimum" edge of the data range.
- double Tick0 = x0 - fmod( x0, TickDistance );
- if ( x0 < 0.0 ) {
- Tick0 -= TickDistance;
- NumMajorTicks++;
- }
-
- for ( int i=0; i<NumMajorTicks+1; i++ ) {
- double xmaj = Tick0 + i*TickDistance;
- if ( xmaj >= x0 && xmaj <= x0 + length ) {
- d->m_MajorTickMarks.append( xmaj );
- }
-
- for ( int j=1; j<NumMinorTicks; j++ ) {
- double xmin = xmaj + TickDistance*j/NumMinorTicks;
- if ( xmin >= x0 && xmin <= x0 + length )
- d->m_MinorTickMarks.append( xmin );
- }
- }
-}
-
-QString KPlotAxis::tickLabel( double val ) const {
- if ( d->m_labelFmt == 't' ) {
- while ( val < 0.0 ) val += 24.0;
- while ( val >= 24.0 ) val -= 24.0;
-
- int h = int(val);
- int m = int( 60.*(val - h) );
- return QString( "%1:%2" ).arg( h, 2, 10, QLatin1Char('0') ).arg( m, 2, 10, QLatin1Char('0') );
- }
-
- return QString( "%1" ).arg( val, d->m_labelFieldWidth, d->m_labelFmt, d->m_labelPrec );
-}
-
-QList< double > KPlotAxis::majorTickMarks() const
-{
- return d->m_MajorTickMarks;
-}
-
-QList< double > KPlotAxis::minorTickMarks() const
-{
- return d->m_MinorTickMarks;
-}
-
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2005 Andreas Nicolai <Andreas.Nicolai@gmx.net>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KPLOTAXIS_H
-#define KPLOTAXIS_H
-
-#include <QString>
-#include <QList>
-
-#include <libkdeedu_plot_export.h>
-
-/**
- * @short Axis for KPlotWidget
- *
- * Contains all data for drawing an axis including format specification axis labels.
- *
- * @author Andreas Nicolai
- * @version 1.0
- */
-class KDEEDUPLOT_EXPORT KPlotAxis {
-public:
-
- /**
- * Constructor, constructs an axis with the label @p label.
- */
- explicit KPlotAxis( const QString& label = QString() );
-
- /**
- * Destructor.
- */
- ~KPlotAxis();
-
- /**
- * @return whether the axis is visible or not
- */
- bool isVisible() const;
-
- /**
- * Sets the "visible" property of the axis.
- */
- void setVisible( bool visible );
-
- /**
- * @return whether tick labels will be drawn for this axis
- */
- bool areTickLabelsShown() const;
-
- /**
- * Determine whether tick labels will be drawn for this axis.
- */
- void setTickLabelsShown( bool b );
-
- /**
- * Sets the axis label.
- * Set the label to an empty string to omit the axis label.
- * @param label a string describing the data plotted on the axis.
- */
- void setLabel( const QString& label );
-
- /**
- * @return the axis label
- */
- QString label() const;
-
- /**
- * @return the ticklabel string for the given value, rendered according
- * to the current format specification.
- * @param the value to be rendered as a tick label.
- * @sa setTickLabelFormat()
- */
- QString tickLabel( double value ) const;
-
- /**
- * Set the display format for converting the double value of the
- * tick's position to the QString for the tick label.
- *
- * Normally, the format character is one of 'e', 'E', 'f', 'g', or 'G'
- * (see the documentation for QString::arg(double) for details).
- *
- * In addition, it is possible to set the format character to 't';
- * in this case the tickmark value is interpreted as a time in hours,
- * and the ticklabel string will be in "hh:mm" clock format.
- * Note that when the format character is 't', the fieldWidth and prec
- * values are ignored.
- *
- * @param format the format specification character
- * @param fieldWidth the number of characters in the output string.
- * If set to 0, the string will be as wide as it needs to be to fully
- * render the value.
- * @param precision the number of characters following the decimal point.
- */
- void setTickLabelFormat( char format = 'g', int fieldWidth = 0, int precision = -1 );
-
- /**
- * @return the field width of the tick labels
- */
- int tickLabelWidth() const;
-
- /**
- * @return the number format of the tick labels
- */
- char tickLabelFormat() const;
-
- /**
- * @return the number precision of the tick labels
- */
- int tickLabelPrecision() const;
-
- /**
- * Determine the positions of major and minor tickmarks for this axis.
- * @param x0 the minimum data coordinate of the axis.
- * @param length the range covered by the axis, in data units.
- * @sa majorTickMarks()
- * @sa minorTickMarks()
- */
- void setTickMarks( double x0, double length );
-
- /**
- * @return the list with the major tickmarks
- */
- QList< double > majorTickMarks() const;
-
- /**
- * @return the list with the minor tickmarks
- */
- QList< double > minorTickMarks() const;
-
-private:
- class Private;
- Private * const d;
-
- Q_DISABLE_COPY( KPlotAxis )
-};
-
-#endif // KPLOTAXIS_H
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2003 Jason Harris <kstars@30doradus.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include <QtAlgorithms>
-#include <QPainter>
-
-#include <kdebug.h>
-
-#include "kplotobject.h"
-#include "kplotwidget.h"
-
-class KPlotPoint::Private
-{
- public:
- Private( KPlotPoint * qq, const QPointF &p, const QString &l, double bw )
- : q( qq ), point( p ), label( l ), barWidth( bw )
- {
- }
-
- KPlotPoint *q;
-
- QPointF point;
- QString label;
- double barWidth;
-};
-
-
-class KPlotObject::Private
-{
- public:
- Private( KPlotObject * qq )
- : q( qq )
- {
- }
-
- ~Private()
- {
- qDeleteAll( pList );
- }
-
- KPlotObject *q;
-
- QList<KPlotPoint*> pList;
- PlotTypes type;
- PointStyle pointStyle;
- double size;
- QPen pen, linePen, barPen, labelPen;
- QBrush brush, barBrush;
-};
-
-
-KPlotPoint::KPlotPoint()
- : d( new Private( this, QPointF(), QString(), 0.0 ) )
-{
-}
-
-KPlotPoint::KPlotPoint( double x, double y, const QString &label, double barWidth )
- : d( new Private( this, QPointF( x, y ), label, barWidth ) )
-{
-}
-
-KPlotPoint::KPlotPoint( const QPointF &p, const QString &label, double barWidth )
- : d( new Private( this, p, label, barWidth ) )
-{
-}
-
-KPlotPoint::~KPlotPoint()
-{
- delete d;
-}
-
-QPointF KPlotPoint::position() const
-{
- return d->point;
-}
-
-void KPlotPoint::setPosition( const QPointF &pos )
-{
- d->point = pos;
-}
-
-double KPlotPoint::x() const
-{
- return d->point.x();
-}
-
-void KPlotPoint::setX( double x )
-{
- d->point.setX( x );
-}
-
-double KPlotPoint::y() const
-{
- return d->point.y();
-}
-
-void KPlotPoint::setY( double y )
-{
- d->point.setY( y );
-}
-
-QString KPlotPoint::label() const
-{
- return d->label;
-}
-
-void KPlotPoint::setLabel( const QString &label )
-{
- d->label = label;
-}
-
-double KPlotPoint::barWidth() const
-{
- return d->barWidth;
-}
-
-void KPlotPoint::setBarWidth( double w )
-{
- d->barWidth = w;
-}
-
-
-KPlotObject::KPlotObject( const QColor &c, PlotType t, double size, PointStyle ps )
- : d( new Private( this ) )
-{
- //By default, all pens and brushes are set to the given color
- setBrush( c );
- setBarBrush( c );
- setPen( QPen( brush(), 1 ) );
- setLinePen( pen() );
- setBarPen( pen() );
- setLabelPen( pen() );
-
- d->type |= t;
- setSize( size );
- setPointStyle( ps );
-}
-
-KPlotObject::~KPlotObject()
-{
- delete d;
-}
-
-KPlotObject::PlotTypes KPlotObject::plotTypes() const
-{
- return d->type;
-}
-
-void KPlotObject::setShowPoints( bool b )
-{
- if ( b )
- {
- d->type |= KPlotObject::Points;
- }
- else
- {
- d->type &= ~KPlotObject::Points;
- }
-}
-
-void KPlotObject::setShowLines( bool b )
-{
- if ( b )
- {
- d->type |= KPlotObject::Lines;
- }
- else
- {
- d->type &= ~KPlotObject::Lines;
- }
-}
-
-void KPlotObject::setShowBars( bool b )
-{
- if ( b )
- {
- d->type |= KPlotObject::Bars;
- }
- else
- {
- d->type &= ~KPlotObject::Bars;
- }
-}
-
-double KPlotObject::size() const
-{
- return d->size;
-}
-
-void KPlotObject::setSize( double s )
-{
- d->size = s;
-}
-
-KPlotObject::PointStyle KPlotObject::pointStyle() const
-{
- return d->pointStyle;
-}
-
-void KPlotObject::setPointStyle( PointStyle p )
-{
- d->pointStyle = p;
-}
-
-const QPen& KPlotObject::pen() const
-{
- return d->pen;
-}
-
-void KPlotObject::setPen( const QPen &p )
-{
- d->pen = p;
-}
-
-const QPen& KPlotObject::linePen() const
-{
- return d->linePen;
-}
-
-void KPlotObject::setLinePen( const QPen &p )
-{
- d->linePen = p;
-}
-
-const QPen& KPlotObject::barPen() const
-{
- return d->barPen;
-}
-
-void KPlotObject::setBarPen( const QPen &p )
-{
- d->barPen = p;
-}
-
-const QPen& KPlotObject::labelPen() const
-{
- return d->labelPen;
-}
-
-void KPlotObject::setLabelPen( const QPen &p )
-{
- d->labelPen = p;
-}
-
-const QBrush KPlotObject::brush() const
-{
- return d->brush;
-}
-
-void KPlotObject::setBrush( const QBrush &b )
-{
- d->brush = b;
-}
-
-const QBrush KPlotObject::barBrush() const
-{
- return d->barBrush;
-}
-
-void KPlotObject::setBarBrush( const QBrush &b )
-{
- d->barBrush = b;
-}
-
-QList< KPlotPoint* > KPlotObject::points() const
-{
- return d->pList;
-}
-
-void KPlotObject::addPoint( const QPointF &p, const QString &label, double barWidth )
-{
- Q_UNUSED( barWidth )
- addPoint( new KPlotPoint( p.x(), p.y(), label ) );
-}
-
-void KPlotObject::addPoint( KPlotPoint *p )
-{
- if ( !p )
- return;
- d->pList.append( p );
-}
-
-void KPlotObject::addPoint( double x, double y, const QString &label, double barWidth )
-{
- Q_UNUSED( barWidth )
- addPoint( new KPlotPoint( x, y, label ) );
-}
-
-void KPlotObject::removePoint( int index ) {
- if ( ( index < 0 ) || ( index >= d->pList.count() ) ) {
- kWarning() << "KPlotObject::removePoint(): index " << index << " out of range!" << endl;
- return;
- }
-
- d->pList.removeAt( index );
-}
-
-void KPlotObject::clearPoints()
-{
- qDeleteAll( d->pList );
- d->pList.clear();
-}
-
-void KPlotObject::draw( QPainter *painter, KPlotWidget *pw ) {
- //Order of drawing determines z-distance: Bars in the back, then lines,
- //then points, then labels.
-
- if ( d->type & Bars ) {
- painter->setPen( barPen() );
- painter->setBrush( barBrush() );
-
- for ( int i=0; i<d->pList.size(); ++i ) {
- double w = 0;
- if ( d->pList[i]->barWidth() == 0.0 ) {
- if ( i<d->pList.size()-1 )
- w = d->pList[i+1]->x() - d->pList[i]->x();
- //For the last bin, we'll just keep the previous width
-
- } else {
- w = d->pList[i]->barWidth();
- }
-
- QPointF pp = d->pList[i]->position();
- QPointF p1( pp.x() - 0.5*w, 0.0 );
- QPointF p2( pp.x() + 0.5*w, pp.y() );
- QPointF sp1 = pw->mapToWidget( p1 );
- QPointF sp2 = pw->mapToWidget( p2 );
-
- QRectF barRect = QRectF( sp1.x(), sp1.y(), sp2.x()-sp1.x(), sp2.y()-sp1.y() ).normalized();
- painter->drawRect( barRect );
- pw->maskRect( barRect, 0.25 );
- }
- }
-
- //Draw lines:
- if ( d->type & Lines ) {
- painter->setPen( linePen() );
-
- QPointF Previous = QPointF(); //Initialize to null
-
- foreach ( KPlotPoint *pp, d->pList ) {
- //q is the position of the point in screen pixel coordinates
- QPointF q = pw->mapToWidget( pp->position() );
-
- if ( ! Previous.isNull() ) {
- painter->drawLine( Previous, q );
- pw->maskAlongLine( Previous, q );
- }
-
- Previous = q;
- }
- }
-
- //Draw points:
- if ( d->type & Points ) {
-
- foreach( KPlotPoint *pp, d->pList ) {
- //q is the position of the point in screen pixel coordinates
- QPointF q = pw->mapToWidget( pp->position() );
- if ( pw->pixRect().contains( q.toPoint(), false ) ) {
- double x1 = q.x() - size();
- double y1 = q.y() - size();
- QRectF qr = QRectF( x1, y1, 2*size(), 2*size() );
-
- //Mask out this rect in the plot for label avoidance
- pw->maskRect( qr, 2.0 );
-
- painter->setPen( pen() );
- painter->setBrush( brush() );
-
- switch ( pointStyle() ) {
- case Circle:
- painter->drawEllipse( qr );
- break;
-
- case Letter:
- painter->drawText( qr, Qt::AlignCenter, pp->label().left(1) );
- break;
-
- case Triangle:
- {
- QPolygonF tri;
- tri << QPointF( q.x() - size(), q.y() + size() )
- << QPointF( q.x(), q.y() - size() )
- << QPointF( q.x() + size(), q.y() + size() );
- painter->drawPolygon( tri );
- break;
- }
-
- case Square:
- painter->drawRect( qr );
- break;
-
- case Pentagon:
- {
- QPolygonF pent;
- pent << QPointF( q.x(), q.y() - size() )
- << QPointF( q.x() + size(), q.y() - 0.309*size() )
- << QPointF( q.x() + 0.588*size(), q.y() + size() )
- << QPointF( q.x() - 0.588*size(), q.y() + size() )
- << QPointF( q.x() - size(), q.y() - 0.309*size() );
- painter->drawPolygon( pent );
- break;
- }
-
- case Hexagon:
- {
- QPolygonF hex;
- hex << QPointF( q.x(), q.y() + size() )
- << QPointF( q.x() + size(), q.y() + 0.5*size() )
- << QPointF( q.x() + size(), q.y() - 0.5*size() )
- << QPointF( q.x(), q.y() - size() )
- << QPointF( q.x() - size(), q.y() + 0.5*size() )
- << QPointF( q.x() - size(), q.y() - 0.5*size() );
- painter->drawPolygon( hex );
- break;
- }
-
- case Asterisk:
- painter->drawLine( q, QPointF( q.x(), q.y() + size() ) );
- painter->drawLine( q, QPointF( q.x() + size(), q.y() + 0.5*size() ) );
- painter->drawLine( q, QPointF( q.x() + size(), q.y() - 0.5*size() ) );
- painter->drawLine( q, QPointF( q.x(), q.y() - size() ) );
- painter->drawLine( q, QPointF( q.x() - size(), q.y() + 0.5*size() ) );
- painter->drawLine( q, QPointF( q.x() - size(), q.y() - 0.5*size() ) );
- break;
-
- case Star:
- {
- QPolygonF star;
- star << QPointF( q.x(), q.y() - size() )
- << QPointF( q.x() + 0.2245*size(), q.y() - 0.309*size() )
- << QPointF( q.x() + size(), q.y() - 0.309*size() )
- << QPointF( q.x() + 0.363*size(), q.y() + 0.118*size() )
- << QPointF( q.x() + 0.588*size(), q.y() + size() )
- << QPointF( q.x(), q.y() + 0.382*size() )
- << QPointF( q.x() - 0.588*size(), q.y() + size() )
- << QPointF( q.x() - 0.363*size(), q.y() + 0.118*size() )
- << QPointF( q.x() - size(), q.y() - 0.309*size() )
- << QPointF( q.x() - 0.2245*size(), q.y() - 0.309*size() );
- painter->drawPolygon( star );
- break;
- }
-
- default:
- break;
- }
- }
- }
- }
-
- //Draw labels
- painter->setPen( labelPen() );
-
- foreach ( KPlotPoint *pp, d->pList ) {
- QPoint q = pw->mapToWidget( pp->position() ).toPoint();
- if ( pw->pixRect().contains(q, false) && ! pp->label().isEmpty() ) {
- pw->placeLabel( painter, pp );
- }
- }
-
-}
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2003 Jason Harris <kstars@30doradus.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KPLOTOBJECT_H
-#define KPLOTOBJECT_H
-
-#include <QColor>
-#include <QPointF>
-#include <QString>
-#include <QPen>
-#include <QBrush>
-
-#include <libkdeedu_plot_export.h>
-
-class QPainter;
-class KPlotWidget;
-
-/**
- * @class KPlotPoint
- * @short Encapsulates a point in the plot.
- * A KPlotPoint consists of X and Y coordinates (in Data units),
- * an optional label string, and an optional bar-width,
- * The bar-width is only used for plots of type KPlotObject::Bars,
- * and it allows the width of each bar to be set manually. If
- * bar-widths are omitted, then the widths will be set automatically,
- * based on the halfway-mark between adjacent points.
- */
-class KDEEDUPLOT_EXPORT KPlotPoint {
- public:
- /**
- * Default constructor.
- */
- explicit KPlotPoint();
- /**
- * Constructor. Sets the KPlotPoint according to the given arguments
- * @param x the X-position for the point, in Data units
- * @param y the Y-position for the point, in Data units
- * @param label the label string for the point. If the string
- * is defined, the point will be labeled in the plot.
- * @param width the bar width to use for this point (only used for
- * plots of type KPlotObject::Bars)
- */
- KPlotPoint( double x, double y, const QString &label = QString(), double width = 0.0 );
- /**
- * Constructor. Sets the KPlotPoint according to the given arguments
- * @param p the position for the point, in Data units
- * @param label the label string for the point. If the string
- * is defined, the point will be labeled in the plot.
- * @param width the bar width to use for this point (only used for
- * plots of type KPlotObject::Bars)
- */
- explicit KPlotPoint( const QPointF &p, const QString &label = QString(), double width = 0.0 );
- /**
- * Destructor
- */
- ~KPlotPoint();
-
- /**
- * @return the position of the point, in data units
- */
- QPointF position() const;
- /**
- * Set the position of the point, in data units
- * @param pos the new position for the point.
- */
- void setPosition( const QPointF &pos );
- /**
- * @return the X-position of the point, in data units
- */
- double x() const;
- /**
- * Set the X-position of the point, in Data units
- */
- void setX( double x );
- /**
- * @return the Y-position of the point, in data units
- */
- double y() const;
- /**
- * Set the Y-position of the point, in Data units
- */
- void setY( double y );
-
- /**
- * @return the label for the point
- */
- QString label() const;
- /**
- * Set the label for the point
- */
- void setLabel( const QString &label );
-
- /**
- * @return the bar-width for the point
- */
- double barWidth() const;
- /**
- * Set the bar-width for the point
- */
- void setBarWidth( double w );
-
- private:
- class Private;
- Private * const d;
-
- Q_DISABLE_COPY( KPlotPoint )
-};
-
-/**
- * @class KPlotObject
- * @short Encapsulates an object to be plotted in a KPlotWidget.
- *
- * Think of a KPlotObject as a set of data displayed as a group in the plot.
- * Each KPlotObject consists of a list of KPlotPoints, a "type" controlling
- * how the data points are displayed (some combination of Points, Lines, or
- * Bars), a color, and a size. There is also a parameter which controls the
- * shape of the points used to display the KPlotObject.
- *
- * @note KPlotObject will take care of the points added to it, so when clearing
- * the points list (eg with clearPoints()) any previous reference to a KPlotPoint
- * already added to a KPlotObject will be invalid.
- *
- * @author Jason Harris
- * @version 1.1
- */
-class KDEEDUPLOT_EXPORT KPlotObject{
-public:
- /**
- * The type classification of the KPlotObject.
- *
- * These are bitmask values that can be OR'd together, so that a set
- * of points can be represented in the plot in multiple ways.
- *
- * @note points should be added in order of increasing x-coordinate
- * when using Bars.
- */
- enum PlotType
- {
- UnknownType = 0,
- Points = 1, ///< each KPlotPoint is represented with a drawn point
- Lines = 2, ///< each KPlotPoint is connected with a line
- Bars = 4 ///< each KPlotPoint is shown as a vertical bar
- };
- Q_DECLARE_FLAGS( PlotTypes, PlotType )
-
- /**
- * The possible kind of points.
- */
- enum PointStyle
- {
- NoPoints = 0,
- Circle = 1,
- Letter = 2,
- Triangle = 3,
- Square = 4,
- Pentagon = 5,
- Hexagon = 6,
- Asterisk = 7,
- Star = 8,
- UnknwonPoint
- };
-
- /**
- * Constructor.
- * @param color The color for plotting this object. By default this sets
- * the color for Points, Lines and Bars, but there are functions to
- * override any of these.
- * @param otype the PlotType for this object
- * @param size the size to use for the points, in pixels
- * @param ps The PointStyle describing the shape for the points
- */
- explicit KPlotObject( const QColor &color = Qt::white, PlotType otype = Points, double size = 2, PointStyle ps = Circle );
-
- /**
- * Destructor.
- */
- ~KPlotObject();
-
- /**
- * @return the plot flags of the object
- */
- PlotTypes plotTypes() const;
-
- /**
- * Set whether points will be drawn for this object
- * @param b if true, points will be drawn
- */
- void setShowPoints( bool b );
-
- /**
- * Set whether lines will be drawn for this object
- * @param b if true, lines will be drawn
- */
- void setShowLines( bool b );
-
- /**
- * Set whether bars will be drawn for this object
- * @param b if true, bars will be drawn
- */
- void setShowBars( bool b );
-
- /**
- * @return the size of the object
- */
- double size() const;
-
- /**
- * Set the new size for the object
- * @param s the new size
- */
- void setSize( double s );
-
- /**
- * @return the style used for drawing the points of the object
- */
- PointStyle pointStyle() const;
-
- /**
- * Set a new style for drawing the points
- * @param p the new style
- */
- void setPointStyle( PointStyle p );
-
- /**
- * @return the default pen for this Object.
- * If no other pens are set, this pen will be used for
- * points, lines, bars and labels (this pen is always used for points).
- */
- const QPen& pen() const;
- /**
- * Set the default pen for this object
- * @p The pen to use
- */
- void setPen( const QPen &p );
-
- /**
- * @return the pen to use for drawing lines for this Object.
- */
- const QPen& linePen() const;
- /**
- * Set the pen to use for drawing lines for this object
- * @p The pen to use
- */
- void setLinePen( const QPen &p );
-
- /**
- * @return the pen to use for drawing bars for this Object.
- */
- const QPen& barPen() const;
- /**
- * Set the pen to use for drawing bars for this object
- * @p The pen to use
- */
- void setBarPen( const QPen &p );
-
- /**
- * @return the pen to use for drawing labels for this Object.
- */
- const QPen& labelPen() const;
- /**
- * Set the pen to use for labels for this object
- * @p The pen to use
- */
- void setLabelPen( const QPen &p );
-
- /**
- * @return the default Brush to use for this Object.
- */
- const QBrush brush() const;
- /**
- * Set the default brush for this object
- * @b The brush to use
- */
- void setBrush( const QBrush &b );
-
- /**
- * @return the brush to use for filling bars for this Object.
- */
- const QBrush barBrush() const;
- /**
- * Set the brush to use for drawing bars for this object
- * @b The brush to use
- */
- void setBarBrush( const QBrush &b );
-
- /**
- * @return the list of KPlotPoints that make up this object
- */
- QList< KPlotPoint* > points() const;
-
- /**
- * Add a point to the object's list.
- * @param p the QPointF to add.
- * @param label the optional text label
- * @param barWidth the width of the bar, if this object is drawn as bars
- */
- void addPoint( const QPointF &p, const QString &label = QString(), double barWidth = 0.0 );
-
- /**
- * Add a point to the object's list.
- * @overload
- * @param p pointer to the KPlotPoint to add.
- */
- void addPoint( KPlotPoint *p );
-
- /**
- * Add a point to the object's list.
- * @overload
- * @param x the X-coordinate of the point to add.
- * @param y the Y-coordinate of the point to add.
- * @param label the optional text label
- * @param barWidth the width of the bar, if this object is drawn as bars
- */
- void addPoint( double x, double y, const QString &label = QString(), double barWidth = 0.0 );
-
- /**
- * Remove the QPointF at position index from the list of points
- * @param index the index of the point to be removed.
- */
- void removePoint( int index );
-
- /**
- * Remove and destroy the points of this object
- */
- void clearPoints();
-
- /**
- * Draw this KPlotObject on the given QPainter
- * @param p The QPainter to draw on
- * @param pw the KPlotWidget to draw on (this is needed
- * for the KPlotWidget::mapToWidget() function)
- */
- void draw( QPainter *p, KPlotWidget *pw );
-
-private:
- class Private;
- Private * const d;
-
- Q_DISABLE_COPY( KPlotObject )
-};
-Q_DECLARE_OPERATORS_FOR_FLAGS( KPlotObject::PlotTypes )
-
-#endif
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2003 Jason Harris <kstars@30doradus.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include <math.h>
-#include <kdebug.h>
-
-#include <qevent.h>
-#include <QHash>
-#include <QPainter>
-#include <QPixmap>
-#include <QToolTip>
-#include <QtAlgorithms>
-
-#include "kplotwidget.h"
-#include "kplotwidget.moc"
-
-#include "kplotaxis.h"
-#include "kplotobject.h"
-
-#define XPADDING 20
-#define YPADDING 20
-#define BIGTICKSIZE 10
-#define SMALLTICKSIZE 4
-#define TICKOFFSET 0
-
-class KPlotWidget::Private
-{
- public:
- Private( KPlotWidget *qq )
- : q( qq ),
- cBackground( Qt::black ), cForeground( Qt::white ), cGrid( Qt::gray ),
- showGrid( false ), showObjectToolTip( true ), useAntialias( false )
- {
- // create the axes and setting their default properties
- KPlotAxis *leftAxis = new KPlotAxis();
- leftAxis->setTickLabelsShown( true );
- axes.insert( LeftAxis, leftAxis );
- KPlotAxis *bottomAxis = new KPlotAxis();
- bottomAxis->setTickLabelsShown( true );
- axes.insert( BottomAxis, bottomAxis );
- KPlotAxis *rightAxis = new KPlotAxis();
- axes.insert( RightAxis, rightAxis );
- KPlotAxis *topAxis = new KPlotAxis();
- axes.insert( TopAxis, topAxis );
- }
-
- ~Private()
- {
- qDeleteAll( objectList );
- qDeleteAll( axes );
- }
-
- KPlotWidget *q;
-
- void calcDataRectLimits( double x1, double x2, double y1, double y2 );
- /**
- * @return a value indicating how well the given rectangle is
- * avoiding masked regions in the plot. A higher returned value
- * indicates that the rectangle is intersecting a larger portion
- * of the masked region, or a portion of the masked region which
- * is weighted higher.
- * @param r The rectangle to be tested
- */
- float rectCost( const QRectF &r ) const;
-
- //Colors
- QColor cBackground, cForeground, cGrid;
- //draw options
- bool showGrid, showObjectToolTip, useAntialias;
- //padding
- int leftPadding, rightPadding, topPadding, bottomPadding;
- // hashmap with the axes we have
- QHash<Axis, KPlotAxis*> axes;
- // List of KPlotObjects
- QList<KPlotObject*> objectList;
- // Limits of the plot area in data units
- QRectF dataRect, secondDataRect;
- // Limits of the plot area in pixel units
- QRect pixRect;
- // Grid of bools to mask "used" regions of the plot
- float plotMask[100][100];
- double px[100], py[100];
-};
-
-KPlotWidget::KPlotWidget( QWidget * parent )
- : QFrame( parent ), d( new Private( this ) )
-{
- setAttribute( Qt::WA_OpaquePaintEvent );
- setAttribute( Qt::WA_NoSystemBackground );
-
- d->secondDataRect = QRectF(); //default: no secondary data rect
- // sets the default limits
- d->calcDataRectLimits( 0.0, 1.0, 0.0, 1.0 );
-
- setDefaultPaddings();
-
- setMinimumSize( 150, 150 );
- resize( minimumSizeHint() );
-}
-
-KPlotWidget::~KPlotWidget()
-{
- delete d;
-}
-
-QSize KPlotWidget::minimumSizeHint() const
-{
- return QSize( 150, 150 );
-}
-
-QSize KPlotWidget::sizeHint() const
-{
- return size();
-}
-
-void KPlotWidget::setLimits( double x1, double x2, double y1, double y2 )
-{
- d->calcDataRectLimits( x1, x2, y1, y2 );
- update();
-}
-
-void KPlotWidget::Private::calcDataRectLimits( double x1, double x2, double y1, double y2 )
-{
- double XA1, XA2, YA1, YA2;
- if (x2<x1) { XA1=x2; XA2=x1; }
- else { XA1=x1; XA2=x2; }
- if ( y2<y1) { YA1=y2; YA2=y1; }
- else { YA1=y1; YA2=y2; }
-
- if ( XA2 == XA1 ) {
- kWarning() << k_funcinfo << "x1 and x2 cannot be equal. Setting x2 = x1 + 1.0" << endl;
- XA2 = XA1 + 1.0;
- }
- if ( YA2 == YA1 ) {
- kWarning() << k_funcinfo << "y1 and y2 cannot be equal. Setting y2 = y1 + 1.0" << endl;
- YA2 = YA1 + 1.0;
- }
- dataRect = QRectF( XA1, YA1, XA2 - XA1, YA2 - YA1 );
-
- q->axis( LeftAxis )->setTickMarks( dataRect.y(), dataRect.height() );
- q->axis( BottomAxis )->setTickMarks( dataRect.x(), dataRect.width() );
-
- if ( secondDataRect.isNull() )
- {
- q->axis( RightAxis )->setTickMarks( dataRect.y(), dataRect.height() );
- q->axis( TopAxis )->setTickMarks( dataRect.x(), dataRect.width() );
- }
-}
-
-void KPlotWidget::setSecondaryLimits( double x1, double x2, double y1, double y2 ) {
- double XA1, XA2, YA1, YA2;
- if (x2<x1) { XA1=x2; XA2=x1; }
- else { XA1=x1; XA2=x2; }
- if ( y2<y1) { YA1=y2; YA2=y1; }
- else { YA1=y1; YA2=y2; }
-
- if ( XA2 == XA1 ) {
- kWarning() << k_funcinfo << "x1 and x2 cannot be equal. Setting x2 = x1 + 1.0" << endl;
- XA2 = XA1 + 1.0;
- }
- if ( YA2 == YA1 ) {
- kWarning() << k_funcinfo << "y1 and y2 cannot be equal. Setting y2 = y1 + 1.0" << endl;
- YA2 = YA1 + 1.0;
- }
- d->secondDataRect = QRectF( XA1, YA1, XA2-XA1, YA2-YA1 );
-
- axis(RightAxis)->setTickMarks( d->secondDataRect.y(), d->secondDataRect.height() );
- axis(TopAxis)->setTickMarks( d->secondDataRect.x(), d->secondDataRect.width() );
-
- update();
-}
-
-void KPlotWidget::clearSecondaryLimits() {
- d->secondDataRect = QRectF();
- axis(RightAxis)->setTickMarks( d->dataRect.y(), d->dataRect.height() );
- axis(TopAxis)->setTickMarks( d->dataRect.x(), d->dataRect.width() );
-
- update();
-}
-
-QRectF KPlotWidget::dataRect() const
-{
- return d->dataRect;
-}
-
-QRectF KPlotWidget::secondaryDataRect() const
-{
- return d->secondDataRect;
-}
-
-void KPlotWidget::addPlotObject( KPlotObject *object )
-{
- // skip null pointers
- if ( !object )
- return;
- d->objectList.append( object );
- update();
-}
-
-void KPlotWidget::addPlotObjects( const QList< KPlotObject* >& objects )
-{
- bool addedsome = false;
- foreach ( KPlotObject *o, objects )
- {
- if ( !o )
- continue;
-
- d->objectList.append( o );
- addedsome = true;
- }
- if ( addedsome )
- update();
-}
-
-QList< KPlotObject* > KPlotWidget::plotObjects() const
-{
- return d->objectList;
-}
-
-void KPlotWidget::removeAllPlotObjects()
-{
- if ( d->objectList.isEmpty() )
- return;
-
- qDeleteAll( d->objectList );
- d->objectList.clear();
- update();
-}
-
-void KPlotWidget::resetPlotMask() {
- for (int ix=0; ix<100; ++ix )
- for ( int iy=0; iy<100; ++iy )
- d->plotMask[ix][iy] = 0.0;
-}
-
-void KPlotWidget::resetPlot() {
- qDeleteAll( d->objectList );
- d->objectList.clear();
- clearSecondaryLimits();
- d->calcDataRectLimits( 0.0, 1.0, 0.0, 1.0 );
- KPlotAxis *a = axis( RightAxis );
- a->setLabel( QString() );
- a->setTickLabelsShown( false );
- a = axis( TopAxis );
- a->setLabel( QString() );
- a->setTickLabelsShown( false );
- axis(KPlotWidget::LeftAxis)->setLabel( QString() );
- axis(KPlotWidget::BottomAxis)->setLabel( QString() );
- resetPlotMask();
-}
-
-void KPlotWidget::replacePlotObject( int i, KPlotObject *o )
-{
- // skip null pointers and invalid indexes
- if ( !o || i < 0 || i >= d->objectList.count() )
- return;
- d->objectList.replace( i, o );
- update();
-}
-
-QColor KPlotWidget::backgroundColor() const
-{
- return d->cBackground;
-}
-
-QColor KPlotWidget::foregroundColor() const
-{
- return d->cForeground;
-}
-
-QColor KPlotWidget::gridColor() const
-{
- return d->cGrid;
-}
-
-void KPlotWidget::setBackgroundColor( const QColor &bg ) {
- d->cBackground = bg;
- update();
-}
-
-void KPlotWidget::setForegroundColor( const QColor &fg )
-{
- d->cForeground = fg;
- update();
-}
-
-void KPlotWidget::setGridColor( const QColor &gc )
-{
- d->cGrid = gc;
- update();
-}
-
-bool KPlotWidget::isGridShown() const
-{
- return d->showGrid;
-}
-
-bool KPlotWidget::isObjectToolTipShown() const
-{
- return d->showObjectToolTip;
-}
-
-bool KPlotWidget::antialiasing() const
-{
- return d->useAntialias;
-}
-
-void KPlotWidget::setAntialiasing( bool b )
-{
- d->useAntialias = b;
- update();
-}
-
-void KPlotWidget::setShowGrid( bool show ) {
- d->showGrid = show;
- update();
-}
-
-void KPlotWidget::setObjectToolTipShown( bool show )
-{
- d->showObjectToolTip = show;
-}
-
-
-KPlotAxis* KPlotWidget::axis( Axis type )
-{
- QHash<Axis, KPlotAxis*>::Iterator it = d->axes.find( type );
- return it != d->axes.end() ? it.value() : 0;
-}
-
-const KPlotAxis* KPlotWidget::axis( Axis type ) const
-{
- QHash<Axis, KPlotAxis*>::ConstIterator it = d->axes.find( type );
- return it != d->axes.end() ? it.value() : 0;
-}
-
-QRect KPlotWidget::pixRect() const
-{
- return d->pixRect;
-}
-
-QList<KPlotPoint*> KPlotWidget::pointsUnderPoint( const QPoint& p ) const {
- QList<KPlotPoint*> pts;
- foreach ( KPlotObject *po, d->objectList ) {
- foreach ( KPlotPoint *pp, po->points() ) {
- if ( ( p - mapToWidget( pp->position() ).toPoint() ).manhattanLength() <= 4 )
- pts << pp;
- }
- }
-
- return pts;
-}
-
-
-bool KPlotWidget::event( QEvent* e ) {
- if ( e->type() == QEvent::ToolTip ) {
- if ( d->showObjectToolTip )
- {
- QHelpEvent *he = static_cast<QHelpEvent*>( e );
- QList<KPlotPoint*> pts = pointsUnderPoint( he->pos() - QPoint( leftPadding(), topPadding() ) - contentsRect().topLeft() );
- if ( pts.count() > 0 ) {
- QToolTip::showText( he->globalPos(), pts.front()->label(), this );
- }
- }
- e->accept();
- return true;
- }
- else
- return QFrame::event( e );
-}
-
-void KPlotWidget::resizeEvent( QResizeEvent* e ) {
- QFrame::resizeEvent( e );
-}
-
-void KPlotWidget::setPixRect() {
- int newWidth = contentsRect().width() - leftPadding() - rightPadding();
- int newHeight = contentsRect().height() - topPadding() - bottomPadding();
- // PixRect starts at (0,0) because we will translate by leftPadding(), topPadding()
- d->pixRect = QRect( 0, 0, newWidth, newHeight );
- for ( int i=0; i<100; ++i ) {
- d->px[i] = double(i*d->pixRect.width())/100.0 + double(d->pixRect.x());
- d->py[i] = double(i*d->pixRect.height())/100.0 + double(d->pixRect.y());
- }
-}
-
-QPointF KPlotWidget::mapToWidget( const QPointF& p ) const
-{
- float px = d->pixRect.left() + d->pixRect.width() * ( p.x() - d->dataRect.x() ) / d->dataRect.width();
- float py = d->pixRect.top() + d->pixRect.height() * ( d->dataRect.y() + d->dataRect.height() - p.y() ) / d->dataRect.height();
- return QPointF( px, py );
-}
-
-void KPlotWidget::maskRect( const QRectF& r, float value ) {
- //Loop over Mask grid points that are near the target rectangle.
- int ix1 = int( 100.0*(r.x() - d->pixRect.x())/d->pixRect.width() );
- int iy1 = int( 100.0*(r.y() - d->pixRect.y())/d->pixRect.height() );
- if ( ix1 < 0 ) ix1 = 0;
- if ( iy1 < 0 ) iy1 = 0;
- int ix2 = int( 100.0*(r.right() - d->pixRect.x())/d->pixRect.width() ) + 2;
- int iy2 = int( 100.0*(r.bottom() - d->pixRect.y())/d->pixRect.height() ) + 2;
- if ( ix1 > 99 ) ix1 = 99;
- if ( iy1 > 99 ) iy1 = 99;
-
- for ( int ix=ix1; ix<ix2; ++ix )
- for ( int iy=iy1; iy<iy2; ++iy )
- d->plotMask[ix][iy] += value;
-}
-
-void KPlotWidget::maskAlongLine( const QPointF &p1, const QPointF &p2, float value ) {
- //Determine slope and zeropoint of line
- double m = (p2.y() - p1.y())/(p2.x() - p1.x());
- double y0 = p1.y() - m*p1.x();
-
- //Make steps along line from p1 to p2, computing the nearest
- //gridpoint position at each point.
- double x1 = p1.x();
- double x2 = p2.x();
- if ( x1 > x2 ) {
- x1 = p2.x();
- x2 = p1.x();
- }
- for ( double x=x1; x<x2; x+=0.01*(x2-x1) ) {
- double y = y0 + m*x;
- int ix = int( 100.0*( x - d->pixRect.x() )/d->pixRect.width() );
- int iy = int( 100.0*( y - d->pixRect.y() )/d->pixRect.height() );
-
- if ( ix >= 0 && ix < 100 && iy >= 0 && iy < 100 )
- d->plotMask[ix][iy] += value;
-
- }
-}
-
-void KPlotWidget::placeLabel( QPainter *painter, KPlotPoint *pp ) {
- int textFlags = Qt::TextSingleLine | Qt::AlignCenter;
-
- float rbest = 100;
- float bestCost = 1.0e7;
- QPointF pos = mapToWidget( pp->position() );
- QRectF bestRect;
- int ix0 = int( 100.0*( pos.x() - d->pixRect.x() )/d->pixRect.width() );
- int iy0 = int( 100.0*( pos.y() - d->pixRect.y() )/d->pixRect.height() );
-
- QFontMetricsF fm( painter->font(), painter->device() );
- int xmin = qMax( ix0 - 20, 0 );
- int xmax = qMin( ix0 + 20, 100 );
- int ymin = qMax( iy0 - 20, 0 );
- int ymax = qMin( iy0 + 20, 100 );
- for ( int ix = xmin; ix < xmax; ++ix )
- {
- for ( int iy = ymin; iy < ymax; ++iy )
- {
- QRectF labelRect = fm.boundingRect( QRectF( d->px[ix], d->py[iy], 1, 1 ), textFlags, pp->label() );
- //Add some padding to labelRect
- labelRect.adjust( -2, -2, 2, 2 );
-
- float r = sqrt( (ix-ix0)*(ix-ix0) + (iy-iy0)*(iy-iy0) );
- float cost = d->rectCost( labelRect ) + 0.1*r;
-
- if ( cost < bestCost ) {
- bestRect = labelRect;
- bestCost = cost;
- rbest = r;
- }
- }
- }
-
- if ( ! bestRect.isNull() ) {
- painter->drawText( bestRect, textFlags, pp->label() );
-
- //Is a line needed to connect the label to the point?
- if ( rbest > 2.0 ) {
- //Draw a rectangle around the label
- painter->setBrush( QBrush() );
- //QPen pen = painter->pen();
- //pen.setStyle( Qt::DotLine );
- //painter->setPen( pen );
- painter->drawRoundRect( bestRect );
-
- //Now connect the label to the point with a line.
- //The line is drawn from the center of the near edge of the rectangle
- float xline = bestRect.center().x();
- if ( bestRect.left() > pos.x() )
- xline = bestRect.left();
- if ( bestRect.right() < pos.x() )
- xline = bestRect.right();
-
- float yline = bestRect.center().y();
- if ( bestRect.top() > pos.y() )
- yline = bestRect.top();
- if ( bestRect.bottom() < pos.y() )
- yline = bestRect.bottom();
-
- painter->drawLine( QPointF( xline, yline ), pos );
- }
-
- //Mask the label's rectangle so other labels won't overlap it.
- maskRect( bestRect );
- }
-}
-
-float KPlotWidget::Private::rectCost( const QRectF &r ) const
-{
- int ix1 = int( 100.0 * ( r.x() - pixRect.x() ) / pixRect.width() );
- int ix2 = int( 100.0 * ( r.right() - pixRect.x() ) / pixRect.width() );
- int iy1 = int( 100.0 * ( r.y() - pixRect.y() ) / pixRect.height() );
- int iy2 = int( 100.0 * ( r.bottom() - pixRect.y() ) / pixRect.height() );
- float cost = 0.0;
-
- for ( int ix=ix1; ix<ix2; ++ix ) {
- for ( int iy=iy1; iy<iy2; ++iy ) {
- if ( ix >= 0 && ix < 100 && iy >= 0 && iy < 100 ) {
- cost += plotMask[ix][iy];
- } else {
- cost += 100.;
- }
- }
- }
-
- return cost;
-}
-
-void KPlotWidget::paintEvent( QPaintEvent *e ) {
- // let QFrame draw its default stuff (like the frame)
- QFrame::paintEvent( e );
- QPainter p;
-
- p.begin( this );
- p.setRenderHint( QPainter::Antialiasing, d->useAntialias );
- p.fillRect( rect(), backgroundColor() );
- p.translate( leftPadding(), topPadding() );
-
- setPixRect();
- p.setClipRect( d->pixRect );
- p.setClipping( true );
-
- resetPlotMask();
-
- foreach( KPlotObject *po, d->objectList )
- po->draw( &p, this );
-
- //DEBUG_MASK
- /*
- p.setPen( Qt::magenta );
- p.setBrush( Qt::magenta );
- for ( int ix=0; ix<100; ++ix ) {
- for ( int iy=0; iy<100; ++iy ) {
- if ( PlotMask[ix][iy] > 0.0 ) {
- double x = d->pixRect.x() + double(ix*d->pixRect.width())/100.;
- double y = d->pixRect.y() + double(iy*d->pixRect.height())/100.;
-
- p.drawRect( QRectF(x-1, y-1, 2, 2 ) );
- }
- }
- }
- */
-
- p.setClipping( false );
- drawAxes( &p );
-
- p.end();
-}
-
-void KPlotWidget::drawAxes( QPainter *p ) {
- if ( d->showGrid ) {
- p->setPen( gridColor() );
-
- //Grid lines are placed at locations of primary axes' major tickmarks
- //vertical grid lines
- foreach ( double xx, axis(BottomAxis)->majorTickMarks() ) {
- double px = d->pixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
- p->drawLine( QPointF( px, 0.0 ), QPointF( px, double(d->pixRect.height()) ) );
- }
- //horizontal grid lines
- foreach( double yy, axis(LeftAxis)->majorTickMarks() ) {
- double py = d->pixRect.height() * (yy - d->dataRect.y()) / d->dataRect.height();
- p->drawLine( QPointF( 0.0, py ), QPointF( double(d->pixRect.width()), py ) );
- }
- }
-
- p->setPen( foregroundColor() );
- p->setBrush( Qt::NoBrush );
-
- //set small font for tick labels
- QFont f = p->font();
- int s = f.pointSize();
- f.setPointSize( s - 2 );
- p->setFont( f );
-
- /*** BottomAxis ***/
- KPlotAxis *a = axis(BottomAxis);
- if (a->isVisible()) {
- //Draw axis line
- p->drawLine( 0, d->pixRect.height(), d->pixRect.width(), d->pixRect.height() );
-
- // Draw major tickmarks
- foreach( double xx, a->majorTickMarks() ) {
- double px = d->pixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
- if ( px > 0 && px < d->pixRect.width() ) {
- p->drawLine( QPointF( px, double(d->pixRect.height() - TICKOFFSET)),
- QPointF( px, double(d->pixRect.height() - BIGTICKSIZE - TICKOFFSET)) );
-
- //Draw ticklabel
- if ( a->areTickLabelsShown() ) {
- QRect r( int(px) - BIGTICKSIZE, d->pixRect.height()+BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
- p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, a->tickLabel( xx ) );
- }
- }
- }
-
- // Draw minor tickmarks
- foreach ( double xx, a->minorTickMarks() ) {
- double px = d->pixRect.width() * (xx - d->dataRect.x()) / d->dataRect.width();
- if ( px > 0 && px < d->pixRect.width() ) {
- p->drawLine( QPointF( px, double(d->pixRect.height() - TICKOFFSET)),
- QPointF( px, double(d->pixRect.height() - SMALLTICKSIZE -TICKOFFSET)) );
- }
- }
-
- // Draw BottomAxis Label
- if ( ! a->label().isEmpty() ) {
- QRect r( 0, d->pixRect.height() + 2*YPADDING, d->pixRect.width(), YPADDING );
- p->drawText( r, Qt::AlignCenter, a->label() );
- }
- } //End of BottomAxis
-
- /*** LeftAxis ***/
- a = axis(LeftAxis);
- if (a->isVisible()) {
- //Draw axis line
- p->drawLine( 0, 0, 0, d->pixRect.height() );
-
- // Draw major tickmarks
- foreach( double yy, a->majorTickMarks() ) {
- double py = d->pixRect.height() * ( 1.0 - (yy - d->dataRect.y()) / d->dataRect.height() );
- if ( py > 0 && py < d->pixRect.height() ) {
- p->drawLine( QPointF( TICKOFFSET, py ), QPointF( double(TICKOFFSET + BIGTICKSIZE), py ) );
-
- //Draw ticklabel
- if ( a->areTickLabelsShown() ) {
- QRect r( -2*BIGTICKSIZE-SMALLTICKSIZE, int(py)-SMALLTICKSIZE, 2*BIGTICKSIZE, 2*SMALLTICKSIZE );
- p->drawText( r, Qt::AlignRight | Qt::AlignVCenter | Qt::TextDontClip, a->tickLabel( yy ) );
- }
- }
- }
-
- // Draw minor tickmarks
- foreach ( double yy, a->minorTickMarks() ) {
- double py = d->pixRect.height() * ( 1.0 - (yy - d->dataRect.y()) / d->dataRect.height() );
- if ( py > 0 && py < d->pixRect.height() ) {
- p->drawLine( QPointF( TICKOFFSET, py ), QPointF( double(TICKOFFSET + SMALLTICKSIZE), py ) );
- }
- }
-
- //Draw LeftAxis Label. We need to draw the text sideways.
- if ( ! a->label().isEmpty() ) {
- //store current painter translation/rotation state
- p->save();
-
- //translate coord sys to left corner of axis label rectangle, then rotate 90 degrees.
- p->translate( -3*XPADDING, d->pixRect.height() );
- p->rotate( -90.0 );
-
- QRect r( 0, 0, d->pixRect.height(), XPADDING );
- p->drawText( r, Qt::AlignCenter, a->label() ); //draw the label, now that we are sideways
-
- p->restore(); //restore translation/rotation state
- }
- } //End of LeftAxis
-
- //Prepare for top and right axes; we may need the secondary data rect
- double x0 = d->dataRect.x();
- double y0 = d->dataRect.y();
- double dw = d->dataRect.width();
- double dh = d->dataRect.height();
- if ( secondaryDataRect().isValid() ) {
- x0 = secondaryDataRect().x();
- y0 = secondaryDataRect().y();
- dw = secondaryDataRect().width();
- dh = secondaryDataRect().height();
- }
-
- /*** TopAxis ***/
- a = axis(TopAxis);
- if (a->isVisible()) {
- //Draw axis line
- p->drawLine( 0, 0, d->pixRect.width(), 0 );
-
- // Draw major tickmarks
- foreach( double xx, a->majorTickMarks() ) {
- double px = d->pixRect.width() * (xx - x0) / dw;
- if ( px > 0 && px < d->pixRect.width() ) {
- p->drawLine( QPointF( px, TICKOFFSET ), QPointF( px, double(BIGTICKSIZE + TICKOFFSET)) );
-
- //Draw ticklabel
- if ( a->areTickLabelsShown() ) {
- QRect r( int(px) - BIGTICKSIZE, (int)-1.5*BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
- p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, a->tickLabel( xx ) );
- }
- }
- }
-
- // Draw minor tickmarks
- foreach ( double xx, a->minorTickMarks() ) {
- double px = d->pixRect.width() * (xx - x0) / dw;
- if ( px > 0 && px < d->pixRect.width() ) {
- p->drawLine( QPointF( px, TICKOFFSET ), QPointF( px, double(SMALLTICKSIZE + TICKOFFSET)) );
- }
- }
-
- // Draw TopAxis Label
- if ( ! a->label().isEmpty() ) {
- QRect r( 0, 0 - 3*YPADDING, d->pixRect.width(), YPADDING );
- p->drawText( r, Qt::AlignCenter, a->label() );
- }
- } //End of TopAxis
-
- /*** RightAxis ***/
- a = axis(RightAxis);
- if (a->isVisible()) {
- //Draw axis line
- p->drawLine( d->pixRect.width(), 0, d->pixRect.width(), d->pixRect.height() );
-
- // Draw major tickmarks
- foreach( double yy, a->majorTickMarks() ) {
- double py = d->pixRect.height() * ( 1.0 - (yy - y0) / dh );
- if ( py > 0 && py < d->pixRect.height() ) {
- p->drawLine( QPointF( double(d->pixRect.width() - TICKOFFSET), py ),
- QPointF( double(d->pixRect.width() - TICKOFFSET - BIGTICKSIZE), py ) );
-
- //Draw ticklabel
- if ( a->areTickLabelsShown() ) {
- QRect r( d->pixRect.width() + SMALLTICKSIZE, int(py)-SMALLTICKSIZE, 2*BIGTICKSIZE, 2*SMALLTICKSIZE );
- p->drawText( r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, a->tickLabel( yy ) );
- }
- }
- }
-
- // Draw minor tickmarks
- foreach ( double yy, a->minorTickMarks() ) {
- double py = d->pixRect.height() * ( 1.0 - (yy - y0) / dh );
- if ( py > 0 && py < d->pixRect.height() ) {
- p->drawLine( QPointF( double(d->pixRect.width() - 0.0), py ),
- QPointF( double(d->pixRect.width() - 0.0 - SMALLTICKSIZE), py ) );
- }
- }
-
- //Draw RightAxis Label. We need to draw the text sideways.
- if ( ! a->label().isEmpty() ) {
- //store current painter translation/rotation state
- p->save();
-
- //translate coord sys to left corner of axis label rectangle, then rotate 90 degrees.
- p->translate( d->pixRect.width() + 2*XPADDING, d->pixRect.height() );
- p->rotate( -90.0 );
-
- QRect r( 0, 0, d->pixRect.height(), XPADDING );
- p->drawText( r, Qt::AlignCenter, a->label() ); //draw the label, now that we are sideways
-
- p->restore(); //restore translation/rotation state
- }
- } //End of RightAxis
-}
-
-int KPlotWidget::leftPadding() const
-{
- if ( d->leftPadding >= 0 )
- return d->leftPadding;
- const KPlotAxis *a = axis( LeftAxis );
- if ( a && a->isVisible() && a->areTickLabelsShown() )
- {
- return !a->label().isEmpty() ? 3 * XPADDING : 2 * XPADDING;
- }
- return XPADDING;
-}
-
-int KPlotWidget::rightPadding() const
-{
- if ( d->rightPadding >= 0 )
- return d->rightPadding;
- const KPlotAxis *a = axis( RightAxis );
- if ( a && a->isVisible() && a->areTickLabelsShown() )
- {
- return !a->label().isEmpty() ? 3 * XPADDING : 2 * XPADDING;
- }
- return XPADDING;
-}
-
-int KPlotWidget::topPadding() const
-{
- if ( d->topPadding >= 0 )
- return d->topPadding;
- const KPlotAxis *a = axis( TopAxis );
- if ( a && a->isVisible() && a->areTickLabelsShown() )
- {
- return !a->label().isEmpty() ? 3 * YPADDING : 2 * YPADDING;
- }
- return YPADDING;
-}
-
-int KPlotWidget::bottomPadding() const
-{
- if ( d->bottomPadding >= 0 )
- return d->bottomPadding;
- const KPlotAxis *a = axis( BottomAxis );
- if ( a && a->isVisible() && a->areTickLabelsShown() )
- {
- return !a->label().isEmpty() ? 3 * YPADDING : 2 * YPADDING;
- }
- return YPADDING;
-}
-
-void KPlotWidget::setLeftPadding( int padding )
-{
- d->leftPadding = padding;
-}
-
-void KPlotWidget::setRightPadding( int padding )
-{
- d->rightPadding = padding;
-}
-
-void KPlotWidget::setTopPadding( int padding )
-{
- d->topPadding = padding;
-}
-
-void KPlotWidget::setBottomPadding( int padding )
-{
- d->bottomPadding = padding;
-}
-
-void KPlotWidget::setDefaultPaddings()
-{
- d->leftPadding = -1;
- d->rightPadding = -1;
- d->topPadding = -1;
- d->bottomPadding = -1;
-}
-
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 2003 Jason Harris <kstars@30doradus.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KPLOTWIDGET_H
-#define KPLOTWIDGET_H
-
-#include <QFrame>
-#include <QList>
-
-#include <libkdeedu_plot_export.h>
-
-class KPlotAxis;
-class KPlotObject;
-class KPlotPoint;
-
-/**
- *@class KPlotWidget
- *
- *@short Generic data plotting widget.
- *
- *Widget for drawing plots. The basic idea behind KPlotWidget is that
- *you don't have to worry about any transformation from your data's
- *natural units to screen pixel coordinates; this is handled internally
- *by the widget.
- *
- *Data to be plotted are represented by one or more instances of
- *KPlotObject. KPlotObject contains a list of QPointFs to be plotted
- *(again, in the data's natural units), as well as information about how
- *the data are to be rendered in the plot (i.e., as separate points or
- *connected by lines? With what color and point style? etc). See
- *KPlotObject for more information.
- *
- *KPlotWidget automatically adds axis labels with tickmarks and tick
- *labels. These are encapsulated in the KPlotAxis class. All you have
- *to do is set the limits of the plotting area in data units, and
- *KPlotWidget wil figure out the optimal positions and labels for the
- *tickmarks on the axes.
- *
- *Example of usage:
- *
- * @code
-KPlotWidget *kpw = new KPlotWidget( parent );
-// setting our limits for the plot
-kpw->setLimits( 1.0, 5.0, 1.0, 25.0 );
-
-// creating a red polygon ...
-KPlotObject *kpo = new KPlotObject( Qt::red, KPlotObject::LINES );
-// ... adding some points to it ...
-for ( float x = 1.0; x <= 5.0; x += 0.1 )
- kpo->addPoint( x, x*x );
-// ... and adding the object to the plot widget
-kpw->addPlotObject( kpo );
- * @endcode
- *
- *@note KPlotWidget will take care of the objects added to it, so when
- *clearing the objects list (eg with removeAllPlotObjects()) any previous
- *reference to a KPlotObject already added to a KPlotWidget will be invalid.
- *
- *@author Jason Harris
- *@version 1.1
- */
-class KDEEDUPLOT_EXPORT KPlotWidget : public QFrame {
- Q_OBJECT
- Q_PROPERTY(int leftPadding READ leftPadding)
- Q_PROPERTY(int rightPadding READ rightPadding)
- Q_PROPERTY(int topPadding READ topPadding)
- Q_PROPERTY(int bottomPadding READ bottomPadding)
- Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
- Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
- Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor)
- Q_PROPERTY(bool grid READ isGridShown WRITE setShowGrid)
- Q_PROPERTY(bool objectToolTip READ isObjectToolTipShown WRITE setObjectToolTipShown)
-public:
- /**
- * Constructor.
- * @param parent the parent widget
- */
- explicit KPlotWidget( QWidget * parent = 0 );
-
- /**
- * Destructor.
- */
- virtual ~KPlotWidget();
-
- /**
- * The kinds of axes we have
- */
- enum Axis
- {
- LeftAxis = 0, ///< the left axis
- BottomAxis, ///< the bottom axis
- RightAxis, ///< the right axis
- TopAxis ///< the top axis
- };
-
- /**
- *@return suggested size for widget
- */
- virtual QSize minimumSizeHint() const;
- virtual QSize sizeHint() const;
-
- /**
- * Set new data limits for the plot.
- * @param x1 the minimum X value in data units
- * @param x2 the maximum X value in data units
- * @param y1 the minimum Y value in data units
- * @param y2 the maximum Y value in data units
- */
- void setLimits( double x1, double x2, double y1, double y2 );
-
- /**
- * Reset the secondary data limits, which control the top and right axes.
- * Note that all data points are plotted using the coordinates defined by
- * the primary data limits, so this function is only useful for plotting
- * alternate axes along the top and right edges.
- * @param x1 the minimum X value in secondary data units
- * @param x2 the maximum X value in secondary data units
- * @param y1 the minimum Y value in secondary data units
- * @param y2 the maximum Y value in secondary data units
- * @sa setLimits()
- */
- void setSecondaryLimits( double x1, double x2, double y1, double y2 );
-
- /**
- * Unset the secondary limits, so the top and right axes
- * show the same tickmarks as the bottom and left axes (no tickmark
- * labels will be drawn for the top and right axes in this case)
- */
- void clearSecondaryLimits();
-
- /**
- * Return the rect in natural limits representing the shown data.
- * @warning the coordinate system of QRectF and the human one are not the same!
- * Though, the height of the rect is really the height of the data rect.
- */
- QRectF dataRect() const;
-
- QRectF secondaryDataRect() const;
-
- /**
- * Add an item to the list of KPlotObjects to be plotted.
- * @note do not use this multiple time if many objects have to be added,
- addPlotObjects() is strongly suggested in this case
- * @param object the KPlotObject to be added
- */
- void addPlotObject( KPlotObject *object );
-
- /**
- * Add more than one KPlotObject at one time.
- * @param objects the KPlotObject's to be added
- */
- void addPlotObjects( const QList< KPlotObject* >& objects );
-
- /**
- * @return the list of the current objects
- */
- QList< KPlotObject* > plotObjects() const;
-
- /**
- * Remove and delete all items from the list of KPlotObjects
- */
- void removeAllPlotObjects();
-
- /**
- * Reset the PlotMask so that all regions are empty
- */
- void resetPlotMask();
-
- /**
- * Clear the object list, reset the data limits, and remove axis labels
- */
- void resetPlot();
-
- /**
- * Replace an item in the KPlotObject list.
- * @param i the index of th item to be replaced
- * @param o pointer to the replacement KPlotObject
- */
- void replacePlotObject( int i, KPlotObject *o );
-
- /**
- * Return the background color of the plot.
- *
- * The default color is black.
- */
- QColor backgroundColor() const;
-
- /**
- * Return the foreground color, used for axes, tickmarks and associated
- * labels.
- *
- * The default color is white.
- */
- QColor foregroundColor() const;
-
- /**
- * Return the grid color.
- *
- * The default color is gray.
- */
- QColor gridColor() const;
-
- /**
- * Set the background color
- * @param bg the new background color
- */
- void setBackgroundColor( const QColor &bg );
-
- /**
- * Set the foreground color
- * @param fg the new foreground color
- */
- void setForegroundColor( const QColor &fg );
-
- /**
- * Set the grid color
- * @param gc the new grid color
- */
- void setGridColor( const QColor &gc );
-
- /**
- * @return whether the grid lines are shown
- */
- bool isGridShown() const;
-
- /**
- * Return whether the tooltip for the point objects is shown.
- *
- * It's enabled by default.
- */
- bool isObjectToolTipShown() const;
-
- /**
- * @return whether the antialiasing is active
- */
- bool antialiasing() const;
-
- /**
- * Toggle the antialiasing when drawing.
- */
- void setAntialiasing( bool b );
-
- /**
- * @return the number of pixels to the left of the plot area.
- * Padding values are set to -1 by default; if unchanged, this function will try to guess
- * a good value, based on whether ticklabels and/or axis labels are to be drawn.
- */
- int leftPadding() const;
- /**
- * @return the number of pixels to the right of the plot area.
- * Padding values are set to -1 by default; if unchanged, this function will try to guess
- * a good value, based on whether ticklabels and/or axis labels are to be drawn.
- */
- int rightPadding() const;
- /**
- * @return the number of pixels above the plot area.
- * Padding values are set to -1 by default; if unchanged, this function will try to guess
- * a good value, based on whether ticklabels and/or axis labels are to be drawn.
- */
- int topPadding() const;
- /**
- * @return the number of pixels below the plot area.
- * Padding values are set to -1 by default; if unchanged, this function will try to guess
- * a good value, based on whether ticklabels and/or axis labels are to be drawn.
- */
- int bottomPadding() const;
-
- /**
- * Set the number of pixels to the left of the plot area.
- * Set this to -1 to revert to automatic determination of padding values.
- */
- void setLeftPadding( int padding );
- /**
- * Set the number of pixels to the right of the plot area.
- * Set this to -1 to revert to automatic determination of padding values.
- */
- void setRightPadding( int padding );
- /**
- * Set the number of pixels above the plot area.
- * Set this to -1 to revert to automatic determination of padding values.
- */
- void setTopPadding( int padding );
- /**
- * Set the number of pixels below the plot area.
- * Set this to -1 to revert to automatic determination of padding values.
- */
- void setBottomPadding( int padding );
-
- /**
- * Revert all four padding values to be automatically determined.
- */
- void setDefaultPaddings();
-
- /**
- * Map a coordinate @p p from the data rect to the physical pixel rect.
- * Used mainly when drawing.
- * @return the coordinate in the pixel coordinate system
- */
- QPointF mapToWidget( const QPointF& p ) const;
-
- /**
- * Indicate that object labels should not occupy the given
- * rectangle in the plot. The rectangle is in pixel coordinates.
- *
- * @note You should not normally call this function directly.
- * It is called by KPlotObject when points, bars and labels are drawn.
- * @param r the rectangle defining the region in the plot that
- * text labels should avoid (in pixel coordinates)
- * @param value Allows you to determine how strongly the rectangle
- * should be avoided. Larger values are avoided more strongly.
- */
- void maskRect( const QRectF &r, float value=1.0 );
-
- /**
- * Indicate that object labels should not be placed over the line
- * joining the two given points (in pixel coordinates).
- *
- * @note You should not normally call this function directly.
- * It is called by KPlotObject when lines are drawn in the plot.
- * @param p1 the starting point for the line
- * @param p2 the ending point for the line
- * @param value Allows you to determine how strongly the line
- * should be avoided. Larger values are avoided more strongly.
- */
- void maskAlongLine( const QPointF &p1, const QPointF &p2, float value=1.0 );
-
- /**
- * Place an object label optimally in the plot. This function will
- * attempt to place the label as close as it can to the point to which
- * the label belongs, while avoiding overlap with regions of the plot
- * that have been masked.
- *
- * @note You should not normally call this function directly.
- * It is called internally in KPlotObject::draw().
- *
- * @param painter Pointer to the painter on which to draw the label
- * @param pp pointer to the KPlotPoint whose label is to be drawn.
- */
- void placeLabel( QPainter *painter, KPlotPoint *pp );
-
- /**
- * Get the axis of the specified @p type, or 0 if no axis has been set.
- * @sa Axis
- */
- KPlotAxis* axis( Axis type );
-
- /**
- * Get the axis of the specified @p type, or 0 if no axis has been set.
- * @sa Axis
- */
- const KPlotAxis* axis( Axis type ) const;
-
- QRect pixRect() const;
-
- public Q_SLOTS:
- /**
- * Toggle whether grid lines are drawn at major tickmarks.
- * @param show if true, grid lines will be drawn.
- */
- void setShowGrid( bool show );
-
- /**
- * Toggle the display of a tooltip for point objects.
- * @param show whether show the tooltip.
- */
- void setObjectToolTipShown( bool show );
-
-protected:
- /**
- * Generic event handler.
- */
- virtual bool event( QEvent* );
-
- /**
- * The paint event handler, executed when update() or repaint() is called.
- */
- virtual void paintEvent( QPaintEvent* );
-
- /**
- * The resize event handler, called when the widget is resized.
- */
- virtual void resizeEvent( QResizeEvent* );
-
- /**
- * Draws the plot axes and axis labels.
- * @internal Internal use only; one should simply call update()
- * to draw the widget with axes and all objects.
- * @param p pointer to the painter on which we are drawing
- */
- virtual void drawAxes( QPainter *p );
-
- /**
- * Synchronize the PixRect with the current widget size and
- * padding settings
- */
- void setPixRect();
-
- /**
- * @return a list of points in the plot which are within 4 pixels
- * of the screen position given as an argument.
- * @param p The screen position from which to check for plot points.
- */
- QList<KPlotPoint*> pointsUnderPoint( const QPoint& p ) const;
-
- private:
- class Private;
- Private * const d;
-
- Q_DISABLE_COPY( KPlotWidget )
-};
-
-#endif
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (c) 2006 Pino Toscano <toscano.pino@tiscali.it>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KDEEDU_PLOT_EXPORT_H
-#define KDEEDU_PLOT_EXPORT_H
-
-#ifndef QT4_ONLY
-
-/* needed for KDE_EXPORT macros */
-#include <kdemacros.h>
-
-#if defined Q_OS_WIN
-
-#ifndef KDEEDUPLOT_EXPORT
-# ifdef MAKE_KDEEDUPLOT_LIB
-# define KDEEDUPLOT_EXPORT KDE_EXPORT
-# else
-# define KDEEDUPLOT_EXPORT KDE_IMPORT
-# endif
-#endif
-
-#else
-/* export statements for unix */
-#define KDEEDUPLOT_EXPORT KDE_EXPORT
-#endif
-
-#else // QT4_ONLY
-
-#define KDEEDUPLOT_EXPORT QT_EXPORT
-
-#endif // QT4_ONLY
-
-
-#endif
+++ /dev/null
-if(KDE4_BUILD_TESTS)
-include_directories( ${CMAKE_SOURCE_DIR}/libkdeedu/kdeeduplot )
-
-
-########### next target ###############
-
-set(testplot_SRCS testplot_widget.cpp testplot_main.cpp )
-
-kde4_automoc(${testplot_SRCS})
-
-kde4_add_executable(testplot ${testplot_SRCS})
-
-target_link_libraries(testplot ${KDE4_KDECORE_LIBS} kdeeduplot m )
-
-endif(KDE4_BUILD_TESTS)
-
+++ /dev/null
-/***************************************************************************
- testplot_main.cpp - description
- -------------------
- begin : Thu Oct 26 2006
- copyright : (C) 2006 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. *
- * *
- ***************************************************************************/
-
-#include "testplot_widget.h"
-#include <kapplication.h>
-#include <kcmdlineargs.h>
-#include <kaboutdata.h>
-#include <klocale.h>
-
-static const char description[] = I18N_NOOP("KPlotWidget test program");
-static const char notice[] = I18N_NOOP("Performs various tests of KPlotWidget");
-
-static KCmdLineOptions options[] =
-{
- KCmdLineLastOption
-};
-
-int main( int argc, char *argv[] )
-{
- KAboutData aboutData( "testplot", I18N_NOOP("Test KPlotWidget"),
- "0.1", description, KAboutData::License_GPL,
- I18N_NOOP("(c) 2006, Jason Harris"), notice,
- "http://edu.kde.org/");
- aboutData.addAuthor("Jason Harris", 0,
- "kstars@30doradus.org", "http://edu.kde.org/");
-
- KCmdLineArgs::init( argc, argv, &aboutData );
-
- KApplication a;
- TestPlot *tp = new TestPlot(0);
- tp->show();
- QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
- return a.exec();
-}
+++ /dev/null
-/***************************************************************************
- testplot_widget.cpp - description
- -------------------
- begin : Thu Oct 26 2006
- copyright : (C) 2006 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. *
- * *
- ***************************************************************************/
-
-#include <math.h>
-#include <QComboBox>
-#include <QVBoxLayout>
-#include <kdebug.h>
-
-#include "../kplotwidget.h"
-#include "../kplotobject.h"
-#include "../kplotaxis.h"
-#include "testplot_widget.h"
-
-TestPlot::TestPlot( QWidget *p ) : KMainWindow( p ), po1(0), po2(0) {
- QWidget *w = new QWidget(this);
- vlay = new QVBoxLayout(w);
-
- PlotSelector = new QComboBox( w );
- PlotSelector->addItem( "Points plot" );
- PlotSelector->addItem( "Lines plot" );
- PlotSelector->addItem( "Bars plot" );
- PlotSelector->addItem( "Points plot with labels" );
- PlotSelector->addItem( "Points, lines and bars" );
- PlotSelector->addItem( "Points, lines and bars with labels" );
-
- plot = new KPlotWidget( w );
- plot->setMinimumSize( 400,400 );
- plot->setAntialiasing( true );
- vlay->addWidget( PlotSelector );
- vlay->addWidget( plot );
-
- setCentralWidget( w );
-
- connect( PlotSelector, SIGNAL( activated( int ) ), this, SLOT( slotSelectPlot( int ) ) );
-
- slotSelectPlot( PlotSelector->currentIndex() );
-}
-
-void TestPlot::slotSelectPlot( int n ) {
- plot->resetPlot();
-
- switch ( n ) {
- case 0: //Points plot
- {
- plot->setLimits( -6.0, 11.0, -10.0, 110.0 );
-
- po1 = new KPlotObject( Qt::white, KPlotObject::Points, 4, KPlotObject::Asterisk );
- po2 = new KPlotObject( Qt::green, KPlotObject::Points, 4, KPlotObject::Triangle );
-
- for ( float x=-5.0; x<=10.0; x+=1.0 ) {
- po1->addPoint( x, x*x );
- po2->addPoint( x, 50.0 - 5.0*x );
- }
-
- plot->addPlotObject( po1 );
- plot->addPlotObject( po2 );
-
- plot->update();
- break;
- }
-
- case 1: //Lines plot
- {
- plot->setLimits( -0.1, 6.38, -1.1, 1.1 );
- plot->setSecondaryLimits( -5.73, 365.55, -1.1, 1.1 );
- plot->axis(KPlotWidget::TopAxis)->setTickLabelsShown( true );
- plot->axis(KPlotWidget::BottomAxis)->setLabel("Angle [radians]");
- plot->axis(KPlotWidget::TopAxis)->setLabel("Angle [degrees]");
-
- po1 = new KPlotObject( Qt::red, KPlotObject::Lines, 2 );
- po2 = new KPlotObject( Qt::cyan, KPlotObject::Lines, 2 );
-
- for ( float t=0.0; t<=6.28; t+=0.04 ) {
- po1->addPoint( t, sin(t) );
- po2->addPoint( t, cos(t) );
- }
-
- plot->addPlotObject( po1 );
- plot->addPlotObject( po2 );
-
- plot->update();
- break;
- }
-
- case 2: //Bars plot
- {
- plot->setLimits( -7.0, 7.0, -5.0, 105.0 );
-
- po1 = new KPlotObject( Qt::white, KPlotObject::Bars, 2 );
- po1->setBarBrush( QBrush(Qt::green, Qt::Dense4Pattern) );
-
- for ( float x=-6.5; x<=6.5; x+=0.5 ) {
- po1->addPoint( x, 100*exp( -0.5*x*x ), "", 0.5 );
- }
-
- plot->addPlotObject( po1 );
-
- plot->update();
- break;
- }
-
- case 3: //Points plot with labels
- {
- plot->setLimits( -1.1, 1.1, -1.1, 1.1 );
-
- po1 = new KPlotObject( Qt::yellow, KPlotObject::Points, 10, KPlotObject::Star );
- po1->setLabelPen( QPen(Qt::green) );
-
- po1->addPoint( 0.0, 0.8, "North" );
- po1->addPoint( 0.57, 0.57, "Northeast" );
- po1->addPoint( 0.8, 0.0, "East" );
- po1->addPoint( 0.57, -0.57, "Southeast" );
- po1->addPoint( 0.0, -0.8, "South" );
- po1->addPoint( -0.57, -0.57, "Southwest" );
- po1->addPoint( -0.8, 0.0, "West" );
- po1->addPoint( -0.57, 0.57, "Northwest" );
-
- plot->addPlotObject( po1 );
-
- plot->update();
- break;
- }
-
- case 4: //Points, Lines and Bars plot
- {
- plot->setLimits( -2.1, 2.1, -0.1, 4.1 );
-
- po1 = new KPlotObject( Qt::white, KPlotObject::Points, 10, KPlotObject::Pentagon );
-
- po1->setShowLines( true );
- po1->setShowBars( true );
- po1->setLabelPen( QPen( QColor( "#AA8800" ) ) );
- po1->setLinePen( QPen( Qt::red, 3.0, Qt::DashDotLine ) );
- po1->setBarBrush( QBrush( Qt::blue, Qt::BDiagPattern ) );
-
- po1->addPoint( -1.75, 0.5 );
- po1->addPoint( -1.25, 1.0 );
- po1->addPoint( -0.75, 1.25 );
- po1->addPoint( -0.25, 1.5 );
- po1->addPoint( 0.25, 2.5 );
- po1->addPoint( 0.75, 3.0 );
- po1->addPoint( 1.25, 1.5 );
- po1->addPoint( 1.75, 1.75 );
-
- plot->addPlotObject( po1 );
-
- update();
- break;
- }
-
- case 5: //Points, Lines and Bars plot with labels
- {
- plot->setLimits( -2.1, 2.1, -0.1, 4.1 );
-
- po1 = new KPlotObject( Qt::white, KPlotObject::Points, 10, KPlotObject::Pentagon );
-
- po1->setShowLines( true );
- po1->setShowBars( true );
- po1->setLabelPen( QPen( QColor( "#AA8800" ) ) );
- po1->setLinePen( QPen( Qt::red, 3.0, Qt::DashDotLine ) );
- po1->setBarBrush( QBrush( Qt::blue, Qt::BDiagPattern ) );
-
- po1->addPoint( -1.75, 0.5, "A" );
- po1->addPoint( -1.25, 1.0, "B" );
- po1->addPoint( -0.75, 1.25, "C" );
- po1->addPoint( -0.25, 1.5, "D" );
- po1->addPoint( 0.25, 2.5, "E" );
- po1->addPoint( 0.75, 3.0, "F" );
- po1->addPoint( 1.25, 1.5, "G" );
- po1->addPoint( 1.75, 1.75, "H" );
-
- plot->addPlotObject( po1 );
-
- update();
- break;
- }
- }
-}
-
-#include "testplot_widget.moc"
+++ /dev/null
-/***************************************************************************
- testplot_widget.h - description
- -------------------
- begin : Thu Oct 26 2006
- copyright : (C) 2006 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 TESTPLOT_WIDGET_H
-#define TESTPLOT_WIDGET_H
-
-#include <kmainwindow.h>
-
-class QComboBox;
-class QVBoxLayout;
-class KPlotWidget;
-class KPlotObject;
-
-class TestPlot : public KMainWindow {
- Q_OBJECT
-
- public:
- TestPlot( QWidget *parent=0 );
- ~TestPlot() {}
-
- public slots:
- void slotSelectPlot( int index );
-
- private:
-
- QVBoxLayout *vlay;
- QComboBox *PlotSelector;
- KPlotWidget *plot;
- KPlotObject *po1, *po2;
-};
-
-#endif