Commit 6dd3e1b6 authored by Matthias Messmer's avatar Matthias Messmer

* Redesign of the function edits

* fixing the color preselection

svn path=/trunk/kdeedu/kmplot/; revision=301564
parent 8c443c7d
......@@ -135,6 +135,7 @@
<kdevfileview>
<groups>
<hidenonprojectfiles>false</hidenonprojectfiles>
<hidenonlocation>false</hidenonlocation>
</groups>
<tree>
<hidepatterns>*.o,*.lo,CVS,*.moc,*~</hidepatterns>
......
......@@ -80,3 +80,10 @@ kmplot/keditfunction.h
kmplot/keditfunction.cpp
/qfunctionlist.h
/qfunctionlist.cpp
kmplot/settingspageprecision.ui
kmplot/keditparametric.cpp
kmplot/keditparametric.h
kmplot/keditpolar.cpp
kmplot/keditpolar.h
kmplot/qeditparametric.ui
kmplot/qeditpolar.ui
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter Mller
* 2000, 2002 kd.moeller@t-online.de
*
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
// Qt includes
#include <qcheckbox.h>
#include <qlabel.h>
#include <qwhatsthis.h>
// KDE includes
#include <kcolorbutton.h>
#include <knuminput.h>
#include <klineedit.h>
#include <kdebug.h>
// local includes
#include "keditparametric.h"
#include "keditparametric.moc"
#include "xparser.h"
KEditParametric::KEditParametric( XParser* parser, QWidget* parent, const char* name ) :
QEditParametric( parent, name )
{
m_parser = parser;
}
/**
* Fill the dialog's widgets with the properties of the parser function number index.
*/
void KEditParametric::initDialog( int x_index, int y_index )
{
m_x_index = x_index;
m_y_index = y_index;
if( m_x_index == -1 ) clearWidgets();
else setWidgets();
}
/**
* Clear alls widgets values
*/
void KEditParametric::clearWidgets()
{
kLineEditName->clear();
kLineEditXFunction->clear();
kLineEditYFunction->clear();
checkBoxHide->setChecked( false );
checkBoxRange->setChecked( false );
min->clear();
max->clear();
kIntNumInputLineWidth->setValue( m_parser->dicke0 );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].farbe0 );
}
/**
* Fill the dialog's widgets with values from the parser
*/
void KEditParametric::setWidgets()
{
QString name, expression;
splitEquation( m_parser->fktext[ m_x_index ].extstr, name, expression );
kLineEditName->setText( name );
kLineEditXFunction->setText( expression );
splitEquation( m_parser->fktext[ m_y_index ].extstr, name, expression );
kLineEditYFunction->setText( expression );
checkBoxHide->setChecked( m_parser->fktext[ m_x_index ].f_mode == 0 );
checkBoxRange->setChecked( m_parser->fktext[ m_x_index ].dmin == m_parser->fktext[ m_x_index ].dmax == 0 );
min->setText( m_parser->fktext[ m_x_index ].str_dmin );
max->setText( m_parser->fktext[ m_x_index ].str_dmax );
kIntNumInputLineWidth->setValue( m_parser->fktext[ m_x_index ].dicke );
kColorButtonColor->setColor( m_parser->fktext[ m_x_index ].farbe );
}
/**
* Overwrites the dialog's accept() method to make sure, that the user's input is valid.
*/
void KEditParametric::accept()
{
// if we are editing an existing function, first delete the old one
if( m_x_index != -1 )
{
m_parser->delfkt( m_x_index );
m_x_index = -1;
}
if( m_y_index != -1 )
{
m_parser->delfkt( m_y_index );
m_y_index = -1;
}
// find a name not allready used
if( kLineEditName->text().isEmpty() )
kLineEditName->setText( newName() );
int index = m_parser->addfkt( xFunction() );
if( index == -1 )
{
m_parser->errmsg();
this->raise();
kLineEditXFunction->setFocus();
kLineEditXFunction->selectAll();
return;
}
m_parser->fktext[ index ].extstr = xFunction();
m_parser->getext( index );
if( checkBoxHide->isChecked() )
m_parser->fktext[ index ].f_mode = 0;
if( checkBoxRange->isChecked() )
{
// TODO: check empty boundaries and syntax
m_parser->fktext[ index ].str_dmin = min->text();
m_parser->fktext[ index ].dmin = m_parser->eval( min->text() );
m_parser->fktext[ index ].str_dmax = max->text();
m_parser->fktext[ index ].dmax = m_parser->eval( max->text() );
}
m_parser->fktext[ index ].dicke = kIntNumInputLineWidth->value();
m_parser->fktext[ index ].farbe = kColorButtonColor->color().rgb();
index = m_parser->addfkt( yFunction() );
if( index == -1 )
{
m_parser->errmsg();
this->raise();
kLineEditYFunction->setFocus();
kLineEditYFunction->selectAll();
return;
}
m_parser->fktext[ index ].extstr = yFunction();
m_parser->getext( index );
// call inherited method
QEditParametric::accept();
}
QString KEditParametric::newName()
{
int i = 0;
QString name;
// prepend the correct prefix
name = "xf%1";
do
{
i++;
} while( m_parser->getfix( name.arg( i ) ) != -1 );
// cut off prefix again, will be added later
name = name.right( name.length()-1 );
return name.arg( i );
}
/**
* return the well formed function equation
*/
QString KEditParametric::xFunction()
{
return "x" + kLineEditName->text() + "(t)=" + kLineEditXFunction->text();
}
/**
* extract function name and expression from a given expression
*/
void KEditParametric::splitEquation( const QString equation, QString &name, QString &expression )
{
int start = 0;
if( equation[ 0 ] == 'r' || equation[ 0 ] == 'x' || equation[ 0 ] == 'y' ) start++;
int length = equation.find( '(' ) - start;
name = equation.mid( start, length );
expression = equation.section( '=', 1, 1 );
}
/**
* return the well formed function equation
*/
QString KEditParametric::yFunction()
{
return "y" + kLineEditName->text() + "(t)=" + kLineEditYFunction->text();
}
const QString KEditParametric::functionItem()
{
return xFunction()+";"+yFunction();
}
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter Möller
* 2000, 2002 kd.moeller@t-online.de
*
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef KEDITPARAMETRIC_H
#define KEDITPARAMETRIC_H
#include "qeditparametric.h"
class XParser;
class KEditParametric : public QEditParametric
{
Q_OBJECT
public:
KEditParametric( XParser* parser, QWidget* parent = NULL, const char* name = NULL );
virtual ~KEditParametric() {};
void initDialog( int index = -1, int y_index = -1 );
const QString functionItem();
private:
void clearWidgets();
void setWidgets();
QString xFunction();
QString yFunction();
QString newName();
void splitEquation( const QString equation, QString &name, QString &expression );
XParser* m_parser;
int m_x_index, m_y_index;
protected:
virtual void accept();
};
#endif
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter Mller
* 2000, 2002 kd.moeller@t-online.de
*
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
// Qt includes
#include <qcheckbox.h>
#include <qlabel.h>
#include <qwhatsthis.h>
// KDE includes
#include <kcolorbutton.h>
#include <knuminput.h>
#include <klineedit.h>
#include <kdebug.h>
// local includes
#include "keditpolar.h"
#include "keditpolar.moc"
#include "xparser.h"
KEditPolar::KEditPolar( XParser* parser, QWidget* parent, const char* name ) :
QEditPolar( parent, name )
{
m_parser = parser;
}
/**
* Fill the dialog's widgets with the properties of the parser function number index.
*/
void KEditPolar::initDialog( int index )
{
m_index = index;
if( m_index == -1 ) clearWidgets();
else setWidgets();
}
/**
* Clear alls widgets values
*/
void KEditPolar::clearWidgets()
{
kLineEditYFunction->clear();
checkBoxHide->setChecked( false );
checkBoxRange->setChecked( false );
min->clear();
max->clear();
kIntNumInputLineWidth->setValue( m_parser->dicke0 );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].farbe0 );
}
/**
* Fill the dialog's widgets with values from the parser
*/
void KEditPolar::setWidgets()
{
QString function = m_parser->fktext[ m_index ].extstr;
function = function.right( function.length()-1 );
kLineEditYFunction->setText( function );
checkBoxHide->setChecked( m_parser->fktext[ m_index ].f_mode == 0 );
checkBoxRange->setChecked( m_parser->fktext[ m_index ].dmin == m_parser->fktext[ m_index ].dmax == 0 );
min->setText( m_parser->fktext[ m_index ].str_dmin );
max->setText( m_parser->fktext[ m_index ].str_dmax );
kIntNumInputLineWidth->setValue( m_parser->fktext[ m_index ].dicke );
kColorButtonColor->setColor( m_parser->fktext[ m_index ].farbe );
}
/**
* Overwrites the dialog's accept() method to make sure, that the user's input is valid.
*/
void KEditPolar::accept()
{
// if we are editing an existing function, first delete the old one
if( m_index != -1 )
{
m_parser->delfkt( m_index );
m_index = -1;
}
int index = m_parser->addfkt( functionItem() );
if( index == -1 )
{
m_parser->errmsg();
this->raise();
kLineEditYFunction->setFocus();
kLineEditYFunction->selectAll();
return;
}
m_parser->fktext[ index ].extstr = functionItem();
m_parser->getext( index );
if( checkBoxHide->isChecked() )
m_parser->fktext[ index ].f_mode = 0;
if( checkBoxRange->isChecked() )
{
// TODO: check empty boundaries and syntax
m_parser->fktext[ index ].str_dmin = min->text();
m_parser->fktext[ index ].dmin = m_parser->eval( min->text() );
m_parser->fktext[ index ].str_dmax = max->text();
m_parser->fktext[ index ].dmax = m_parser->eval( max->text() );
}
m_parser->fktext[ index ].dicke = kIntNumInputLineWidth->value();
m_parser->fktext[ index ].farbe = kColorButtonColor->color().rgb();
// call inherited method
QEditPolar::accept();
}
/**
* return the well formed function equation
*/
const QString KEditPolar::functionItem()
{
return "r" + kLineEditYFunction->text();
}
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter Möller
* 2000, 2002 kd.moeller@t-online.de
*
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef KEDITPOLAR_H
#define KEDITPOLAR_H
#include "qeditpolar.h"
class XParser;
class KEditPolar : public QEditPolar
{
Q_OBJECT
public:
KEditPolar( XParser* parser, QWidget* parent = NULL, const char* name = NULL );
virtual ~KEditPolar() {};
void initDialog( int index = -1 );
// void setFunction( int index );
const QString functionItem();
private:
void clearWidgets();
void setWidgets();
XParser* m_parser;
int m_index;
protected:
virtual void accept();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment