[kde-edu]: Cartesian plane on qt canvas

Trenton Carr trentoncarr at telkomsa.net
Tue Dec 14 11:04:01 CET 2004


On Wed, 8 Dec 2004 13:47:29 -0700, Jason Harris <kstars at 30doradus.org>  
wrote:


> let me know if that works,
> Jason
> --
> Jason Harris
> jharris at 30doradus.org

Hello Jason,

Perfect much better thanks.

I have hit another snag, unrelated to your excellent plot lib.
Every thing is working perfectly, but now I would like to connect the  
signal from a double spinbox to the trigviewer and I can't get it to work.  
I've tried what I think is everything already, can you lend an eye?

The problem is in here some where.
I even tried to put the deg_theta in it's own class, but to no avail.

#include <qlayout.h>
#include <klocale.h>
#include <knuminput.h>

#include "trigviewer.h"
#include "ktrigplotwidget.h"
#include "deg_theta.h"


TrigViewer::TrigViewer(QWidget* parent, const char* name)
         : QWidget( parent, name )

{
     QVBoxLayout *vlay = new QVBoxLayout( this, 0, -1 );

     KDoubleSpinBox *spin = new KDoubleSpinBox( 0.0, 360.0, 1, 0.0, 2,  
this, 0);

     Deg_Theta *deg = new Deg_Theta();										//fix me

     connect( spin, SIGNAL(valueChanged( double )), deg,  
SLOT(setAngle( double )));			//fix me

     deg_theta = deg->angle();    											//fix me

     pw = new KTrigPlotWidget( -100.0, 100.0, -100.0, 100.0, this );

     pw->setShowAxes( true );
     pw->setShowTickMarks( true );
     pw->setBGColor( QColor( "white" ) );
     pw->setFGColor( QColor ( "black") );
     pw->setXAxisLabel( i18n( "X-Axis" ) );
     pw->setYAxisLabel( i18n( "Y-Axis" ) );
     pw->setShowCartTrigAxes( true );
     pw->setShowCartTrigTickMarks( true );		//Might not be needed

     vlay->addWidget( pw );
     vlay->addWidget( spin );
     resize( 500, 500 );

     drawObjects();
}

TrigViewer::~TrigViewer()
{}


void TrigViewer::paintEvent( QPaintEvent* )
{
     pw->update();
}


void TrigViewer::drawObjects()
{


     KPlotObject *r_hypotenuse;				//3 sides of triangle
     KPlotObject *x_adjacent;
     KPlotObject *y_opposite;

     double radians = deg_theta * M_PI / 180;		//thank GNU for manpages,  
three days looking for this

     double X_val = 100*cos(radians);			//Find X Value
     double Y_val = 100*sin(radians);			//Find Y Value

     r_hypotenuse = new KPlotObject( "R", "black", KPlotObject::POLYGON, 2,  
KPlotObject::SOLID );
     r_hypotenuse->addPoint( new DPoint( 0.0, 0.0 ) );
     r_hypotenuse->addPoint( new DPoint( X_val, Y_val ) );
     pw->addObject( r_hypotenuse );			//Draw R

     x_adjacent = new KPlotObject( "X", "black", KPlotObject::POLYGON, 2,  
KPlotObject::SOLID );
     x_adjacent->addPoint( new DPoint( 0.0, 0.0 ) );
     x_adjacent->addPoint( new DPoint( X_val, 0.0 ) );
     pw->addObject( x_adjacent );			//Draw X

     y_opposite = new KPlotObject( "Y", "black", KPlotObject::POLYGON, 2,  
KPlotObject::SOLID );
     y_opposite->addPoint( new DPoint( X_val, 0.0 ) );
     y_opposite->addPoint( new DPoint( X_val, Y_val ) );
     pw->addObject( y_opposite );			//Draw Y
}

It all works fine if I hard code a size for deg_theta, all elements are  
draw correctly.
It also compiles with no problems.

I include a tar.bz2 with the base code for kmathtool.

By the way, your most excellent work has taught me more about coding in  
the last three days than the preceding year of books and web resources.

Kind Regards

Trenton

-- 
Master Maths George.
Postnet Suite #109                Tel: +27(0)44 873 4683
Private Bag X6590                         +27(0)82 871 6125
George                                           +27(0)82 821 0088
6529
South Africa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmathtool.tar.bz2
Type: application/bzip2
Size: 18203 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-edu/attachments/20041214/1f698eb4/kmathtool.tar-0001.bin


More information about the kde-edu mailing list