Commit 8c443c7d authored by Matthias Messmer's avatar Matthias Messmer

* Redesign of the function edits

* fixing the color preselection

svn path=/trunk/kdeedu/kmplot/; revision=301561
parent 2863b046
......@@ -34,8 +34,10 @@
// locale includes
#include "FktDlg.h"
#include "FktDlg.moc"
#include "MainDlg.h"
#include "keditfunction.h"
#include "keditparametric.h"
#include "keditpolar.h"
#include "MainDlg.h"
#include <kdebug.h>
......@@ -43,91 +45,12 @@
FktDlg::FktDlg( QWidget* parent, const char* name ) : Inherited( parent, name )
{
/* QPopupMenu *menu_types = new QPopupMenu( this );
menu_types->insertItem( i18n( "Function Plot" ), this, SLOT( onEditFunction() ) );
menu_types->insertItem( i18n( "Parametric Plot" ), this, SLOT( onEditParametric() ) );
menu_types->insertItem( i18n( "Polar Plot" ), this, SLOT( onEditPolar() ) );
PushButtonNew->setPopup( menu_types );*/
editFunction = 0;
}
FktDlg::~FktDlg()
{
}
// Slots
// void FktDlg::onnew()
// {
// int ix;
// char c0;
// QString fname, fstr, str;
//
// // fstr = le_fktstr->text();
// if ( !fstr.isEmpty() )
// {
// // left from semicolon is function equation
// int i = fstr.find( ';' );
//
// if ( i == -1 )
// str = fstr;
// else
// str = fstr.left( i );
//
// // test the function equation syntax
// ix = ps.addfkt( str );
// if ( ix == -1 )
// {
// ps.errmsg();
// errflg = 1;
// return ;
// }
//
// // handle the extensions
// ps.fktext[ ix ].extstr = fstr;
// // test the extension syntax
// if ( ps.getext( ix ) == -1 )
// {
// errflg = 1;
// return ;
// }
//
// // handle parametric functions: xf(t), yf(t)
// if ( ( c0 = fstr[ 0 ].latin1() ) == 'x' )
// {
// ps.getfkt( ix, fname, str );
// fname[ 0 ] = 'y';
// if ( ps.getfix( fname ) == -1 )
// {
// int p;
//
// lb_fktliste->insertItem( fstr );
// // fktidx.append( lb_fktliste->currentItem() );
// p = fstr.find( '=' );
// fstr = fstr.left( p + 1 );
// fstr[ 0 ] = 'y';
// /* le_fktstr->setText( fstr );
// le_fktstr->setFocus();
// le_fktstr->deselect();
// */ return ;
// }
// }
// else if ( c0 == 'y' )
// {
// if ( ps.getfkt( ix, fname, str ) != -1 )
// {
// fname[ 0 ] = 'x';
// ix = ps.getfix( fname );
// }
// }
// lb_fktliste->insertItem( fstr );
// // le_fktstr->clear();
// }
// errflg = 0;
// updateView();
// }
void FktDlg::ondelete()
{
int ix, num;
......@@ -135,6 +58,7 @@ void FktDlg::ondelete()
if ( ( num = lb_fktliste->currentItem() ) == -1 )
return ;
// TODO: delete parametric pair of function
ix = getIx( lb_fktliste->text( num ) );
chflg = 1;
ps.delfkt( ix );
......@@ -147,8 +71,6 @@ void FktDlg::onedit()
int num = lb_fktliste->currentItem();
int index = getIx( lb_fktliste->text( num ).section( ";", 0, 0) );
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
// find out the function type
char prefix = ps.fktext[ index ].extstr.at(0).latin1();
......@@ -195,35 +117,35 @@ void FktDlg::onHasSelection()
void FktDlg::onEditFunction( int index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Function, index );
KEditFunction* editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( index );
if( editFunction->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->yFunction(), num );
if( index == -1 ) lb_fktliste->insertItem( editFunction->functionItem() );
else lb_fktliste->changeItem( editFunction->functionItem(), num );
}
}
void FktDlg::onEditParametric( int x_index, int y_index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Parametric, x_index, y_index );
if( editFunction->exec() == QDialog::Accepted )
KEditParametric* editParametric = new KEditParametric( &ps, this );
editParametric->initDialog( x_index, y_index );
if( editParametric->exec() == QDialog::Accepted )
{
if( x_index == -1 )
lb_fktliste->insertItem( editFunction->xFunction() + ";" + editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->xFunction() + ";" + editFunction->yFunction(), num );
lb_fktliste->insertItem( editParametric->functionItem() );
else lb_fktliste->changeItem( editParametric->functionItem(), num );
}
}
void FktDlg::onEditPolar( int index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Polar, index );
if( editFunction->exec() == QDialog::Accepted )
KEditPolar* editPolar = new KEditPolar( &ps, this );
editPolar->initDialog( index );
if( editPolar->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->yFunction(), num );
if( index == -1 ) lb_fktliste->insertItem( editPolar->functionItem() );
else lb_fktliste->changeItem( editPolar->functionItem(), num );
}
}
......
......@@ -84,7 +84,6 @@ private:
void updateView();
int chflg;
int errflg;
KEditFunction *editFunction;
};
#endif // FktDlg_included
......@@ -9,7 +9,7 @@
<x>0</x>
<y>0</y>
<width>429</width>
<height>344</height>
<height>346</height>
</rect>
</property>
<property name="minimumSize">
......@@ -172,9 +172,6 @@
<property name="accel">
<string>Alt+P</string>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="toolTip" stdset="0">
<string>define a new function</string>
</property>
......@@ -200,9 +197,6 @@
<property name="accel">
<string>Alt+N</string>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="toolTip" stdset="0">
<string>define a new function</string>
</property>
......@@ -275,9 +269,6 @@
<property name="accel">
<string>Alt+O</string>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="toolTip" stdset="0">
<string>apply the changes and close the dialog</string>
</property>
......
......@@ -40,17 +40,19 @@
#include <kurl.h>
// local includes
#include "keditfunction.h"
#include "keditparametric.h"
#include "keditpolar.h"
#include "kprinterdlg.h"
#include "MainDlg.h"
#include "MainDlg.moc"
#include "misc.h"
#include "kprinterdlg.h"
#include "settings.h"
#include "settingspagecolor.h"
#include "settingspagecoords.h"
#include "settingspagefonts.h"
#include "settingspageprecision.h"
#include "settingspagescaling.h"
#include "keditfunction.h"
MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name ) : KMainWindow( 0, name ), m_recentFiles( 0 )
{
......@@ -132,10 +134,10 @@ void MainDlg::setupActions()
( void ) new KAction( i18n( "Coordinate System III" ), "ksys3.png", 0, this, SLOT( onachsen3() ), actionCollection(), "coord_iii" );
// functions menu
( void ) new KAction( i18n( "&New Function Plot..." ), 0, this, SLOT( onNewFunction() ), actionCollection(), "newfunction" );
( void ) new KAction( i18n( "&New Function Plot..." ), "kfkt.png", 0, this, SLOT( onNewFunction() ), actionCollection(), "newfunction" );
( void ) new KAction( i18n( "New Parametric Plot..." ), 0, this, SLOT( onNewParametric() ), actionCollection(), "newparametric" );
( void ) new KAction( i18n( "New Polar Plot..." ), 0, this, SLOT( onNewPolar() ), actionCollection(), "newpolar" );
( void ) new KAction( i18n( "Edit Functions..." ), "kfkt.png", 0, this, SLOT( funktionen() ), actionCollection(), "functions" );
( void ) new KAction( i18n( "Edit Functions..." ), 0, this, SLOT( funktionen() ), actionCollection(), "functions" );
// help menu
view_bezeichnungen = new KToggleAction( i18n( "&Names" ), 0, this, SLOT( bezeichnungen() ), actionCollection(), "names" );
......@@ -569,24 +571,24 @@ void MainDlg::bezeichnungen()
void MainDlg::onNewFunction()
{
KEditFunction* editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Function );
editFunction->initDialog();
m_modified = editFunction->exec() == QDialog::Accepted;
view->update();
}
void MainDlg::onNewParametric()
{
KEditFunction* editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Parametric );
m_modified = editFunction->exec() == QDialog::Accepted;
KEditParametric* editParametric = new KEditParametric( &ps, this );
editParametric->initDialog();
m_modified = editParametric->exec() == QDialog::Accepted;
view->update();
}
void MainDlg::onNewPolar()
{
KEditFunction* editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Polar );
m_modified = editFunction->exec() == QDialog::Accepted;
KEditPolar* editPolar = new KEditPolar( &ps, this );
editPolar->initDialog();
m_modified = editPolar->exec() == QDialog::Accepted;
view->update();
}
......
bin_PROGRAMS = kmplot
kmplot_SOURCES = SwDlgData.ui SkalDlgData.ui RstDlgData.ui KoordDlgData.ui KOptDlgData.ui FktDlgData.ui BezWndData.ui xparser.cpp parser.cpp misc.cpp main.cpp diagr.cpp View.cpp SwDlg.cpp SkalDlg.cpp RstDlg.cpp MainDlg.cpp KoordDlg.cpp KOptDlg.cpp FktDlg.cpp BezWnd.cpp kprinterdlg.cpp settings.kcfgc settingspagecolor.ui settingspagecoords.ui settingspagefonts.ui settingspagescaling.ui settingspageprecision.ui qeditfunction.ui keditfunction.cpp
kmplot_SOURCES = SwDlgData.ui SkalDlgData.ui RstDlgData.ui KoordDlgData.ui KOptDlgData.ui FktDlgData.ui BezWndData.ui xparser.cpp parser.cpp misc.cpp main.cpp diagr.cpp View.cpp SwDlg.cpp SkalDlg.cpp RstDlg.cpp MainDlg.cpp KoordDlg.cpp KOptDlg.cpp FktDlg.cpp BezWnd.cpp kprinterdlg.cpp settings.kcfgc settingspagecolor.ui settingspagecoords.ui settingspagefonts.ui settingspagescaling.ui settingspageprecision.ui qeditfunction.ui keditfunction.cpp qeditparametric.ui keditparametric.cpp qeditpolar.ui keditpolar.cpp
kmplot_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) $(LIB_KDEPRINT)
EXTRA_DIST = kmplot.desktop BezWnd.cpp BezWnd.h FktDlg.cpp FktDlg.h KOptDlg.cpp KOptDlg.h KoordDlg.cpp KoordDlg.h MainDlg.cpp MainDlg.h RstDlg.cpp RstDlg.h SkalDlg.cpp SkalDlg.h SwDlg.cpp SwDlg.h View.cpp View.h diagr.cpp diagr.h main.cpp main.h misc.cpp misc.h parser.cpp parser.h xparser.cpp xparser.h BezWndData.ui FktDlgData.ui KOptDlgData.ui KoordDlgData.ui RstDlgData.ui SkalDlgData.ui SwDlgData.ui kprinterdlg.cpp kprinterdlg.h keditfunction.h keditfunction.cpp
EXTRA_DIST = kmplot.desktop BezWnd.cpp BezWnd.h FktDlg.cpp FktDlg.h KOptDlg.cpp KOptDlg.h KoordDlg.cpp KoordDlg.h MainDlg.cpp MainDlg.h RstDlg.cpp RstDlg.h SkalDlg.cpp SkalDlg.h SwDlg.cpp SwDlg.h View.cpp View.h diagr.cpp diagr.h main.cpp main.h misc.cpp misc.h parser.cpp parser.h xparser.cpp xparser.h BezWndData.ui FktDlgData.ui KOptDlgData.ui KoordDlgData.ui RstDlgData.ui SkalDlgData.ui SwDlgData.ui kprinterdlg.cpp kprinterdlg.h qeditfunction.ui keditfunction.h qeditparametric.ui keditparametric.h qeditpolar.ui keditpolar.h
xdg_apps_DATA = kmplot.desktop
......
......@@ -48,76 +48,18 @@ KEditFunction::KEditFunction( XParser* parser, QWidget* parent, const char* name
/**
* Fill the dialog's widgets with the properties of the parser function number index.
*/
void KEditFunction::initDialog( const FunctionType t, int index, int y_index )
void KEditFunction::initDialog( int index )
{
m_type = t;
m_index = index;
m_y_index = y_index;
setVisibleWidgets();
if( m_index == -1 ) clearWidgets();
else setWidgets();
}
/**
* Only show Widgets related to the function type.
* Some WhatsThis texts have to be adjusted, too.
*/
void KEditFunction::setVisibleWidgets()
{
switch( m_type )
{
case Function:
this->setCaption( i18n( "Edit Function Plot" ) );
textLabelX->hide();
textLabelXF->hide();
textLabelArgX->hide();
kLineEditXFunction->hide();
textLabelY->setText( "" );
textLabelArgY->setText( "(x) = " );
QWhatsThis::add( kLineEditYFunction, tr2i18n( "Enter an expression for the function.\n"
"The dummy variable is x.\n"
"Example: x^2" ) );
checkBoxDerivative1->show();
checkBoxDerivative2->show();
break;
case Parametric:
this->setCaption( i18n( "Edit Parametric Plot" ) );
kLineEditXFunction->show();
textLabelX->show();
textLabelXF->show();
textLabelArgX->show();
textLabelY->setText( "y" );
textLabelArgY->setText( "(t) = " );
QWhatsThis::add( kLineEditYFunction, tr2i18n( "Enter an expression for the function.\n"
"The dummy variable is t.\n"
"Example: sin(t)" ) );
checkBoxDerivative1->hide();
checkBoxDerivative2->hide();
break;
case Polar:
this->setCaption( i18n( "Edit Polar Plot" ) );
kLineEditXFunction->hide();
textLabelX->hide();
textLabelXF->hide();
textLabelArgX->hide();
textLabelY->setText( "r" );
textLabelArgY->setText( "(theta) = " );
QWhatsThis::add( kLineEditYFunction, tr2i18n( "Enter an expression for the function.\n"
"The dummy variable is theta.\n"
"Example: 3*theta" ) );
checkBoxDerivative1->show();
checkBoxDerivative2->show();
}
updateGeometry();
}
/**
* Clear alls widgets values
*/
void KEditFunction::clearWidgets()
{
kLineEditName->clear();
kLineEditXFunction->clear();
kLineEditYFunction->clear();
checkBoxHide->setChecked( false );
checkBoxDerivative1->setChecked( false );
......@@ -126,7 +68,7 @@ void KEditFunction::clearWidgets()
min->clear();
max->clear();
kIntNumInputLineWidth->setValue( m_parser->dicke0 );
kColorButtonColor->setColor( "#000000" );
kColorButtonColor->setColor( m_parser->fktext[ m_parser->getNextIndex() ].farbe0 );
}
/**
......@@ -134,24 +76,9 @@ void KEditFunction::clearWidgets()
*/
void KEditFunction::setWidgets()
{
QString name, expression;
splitEquation( m_parser->fktext[ m_index ].extstr, name, expression );
switch( m_type )
{
case Function:
checkBoxDerivative1->setChecked( m_parser->fktext[ m_index ].f1_mode == 1 );
checkBoxDerivative2->setChecked( m_parser->fktext[ m_index ].f2_mode == 1 );
case Polar:
kLineEditName->setText( name );
kLineEditYFunction->setText( expression );
break;
case Parametric:
kLineEditName->setText( name );
kLineEditXFunction->setText( expression );
splitEquation( m_parser->fktext[ m_y_index ].extstr, name, expression );
kLineEditYFunction->setText( expression );
break;
}
kLineEditYFunction->setText( m_parser->fktext[ m_index ].extstr );
checkBoxDerivative1->setChecked( m_parser->fktext[ m_index ].f1_mode == 1 );
checkBoxDerivative2->setChecked( m_parser->fktext[ m_index ].f2_mode == 1 );
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 );
......@@ -171,17 +98,8 @@ void KEditFunction::accept()
m_parser->delfkt( m_index );
m_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( yFunction() );
int index = m_parser->addfkt( functionItem() );
if( index == -1 )
{
m_parser->errmsg();
......@@ -190,24 +108,9 @@ void KEditFunction::accept()
kLineEditYFunction->selectAll();
return;
}
m_parser->fktext[ index ].extstr = yFunction();
m_parser->fktext[ index ].extstr = functionItem();
m_parser->getext( index );
if( kLineEditXFunction->isVisible() )
{
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( checkBoxDerivative1->isChecked() )
......@@ -231,67 +134,10 @@ void KEditFunction::accept()
QEditFunction::accept();
}
QString KEditFunction::newName()
{
int i = 0;
QString name;
// prepend the correct prefix
switch( m_type )
{
case Function:
name = "f%1";
break;
case Parametric:
name = "xf%1";
break;
case Polar:
name = "rf%1";
}
do
{
i++;
} while( m_parser->getfix( name.arg( i ) ) != -1 );
// cut off prefix again, will be added later
if( m_type == Parametric || m_type == Polar )
name = name.right( name.length()-1 );
return name.arg( i );
}
/**
* return the well formed function equation
*/
QString KEditFunction::xFunction()
{
return "x" + kLineEditName->text() + "(t)=" + kLineEditXFunction->text();
}
/**
* extract function name and expression from a given expression
* return the well formed function equation for the listbox in FktDlg
*/
void KEditFunction::splitEquation( const QString equation, QString &name, QString &expression )
const QString KEditFunction::functionItem()
{
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 KEditFunction::yFunction()
{
switch( m_type )
{
case Function:
return kLineEditName->text() + "(x)=" + kLineEditYFunction->text();
case Parametric:
return "y" + kLineEditName->text() + "(t)=" + kLineEditYFunction->text();
case Polar:
return "r" + kLineEditName->text() + "(theta)=" + kLineEditYFunction->text();
}
return kLineEditYFunction->text();
}
......@@ -37,22 +37,14 @@ class KEditFunction : public QEditFunction
KEditFunction( XParser* parser, QWidget* parent = NULL, const char* name = NULL );
virtual ~KEditFunction() {};
enum FunctionType { Function, Parametric, Polar };
void initDialog( const FunctionType t, int index = -1, int y_index = -1 );
// void setFunction( int index );
QString xFunction();
QString yFunction();
void initDialog( int index = -1 );
const QString functionItem();
private:
void setVisibleWidgets();
void clearWidgets();
void setWidgets();
QString newName();
void splitEquation( const QString equation, QString &name, QString &expression );
FunctionType m_type;
XParser* m_parser;
int m_index, m_y_index;
int m_index;
protected:
virtual void accept();
......
......@@ -30,7 +30,7 @@
<ToolBar name="mainToolBar">
<Separator />
<Action name="quickedit"/>
<Action name="functions"/>
<Action name="newfunction"/>
<Action name="coord_i"/>
<Action name="coord_ii"/>
<Action name="coord_iii"/>
......
......@@ -190,6 +190,13 @@ double Parser::Ufkt::fkt(double x)
}
}
int Parser::getNextIndex()
{
int ix = 0;
while( ( ix < ufanz ) && !ufkt[ ix ].fname.isEmpty() ) ix++;
if( ix == ufanz ) ix = -1;
return ix;
}
int Parser::addfkt(QString str)
{ int ix, p1, p2, p3;
......
......@@ -91,26 +91,28 @@ public:
int delfkt(int);
int chkfix(int),
getfkt(int, QString&, QString&),
getfix(QString),
errmsg();
getfix(QString);
int getNextIndex();
int errmsg();
void setparameter(int ix, double k) {ufkt[ix].k=k;}
~Parser();
int err, // Fehlercode:
// 0 => parse erfolgreich
// 1 => Syntaxfehler
// 2 => fehlende Klammer
// 3 => Funktion nicht bekannt
// 4 => ungltige Funktionsvariable
// 5 => zu viele Funktionen
// 6 => Speicherberlauf
// 7 => Stackberlauf
// 8 => Funktionsname bereits vergeben
// 9 => rekursiver Funktionsaufruf
errpos, // Fehlerposition
ufanz; // max. Anzahl benutzer-
int err, // Fehlercodes:
// 0 => parse erfolgreich
// 1 => Syntaxfehler
// 2 => fehlende Klammer
// 3 => Funktion nicht bekannt
// 4 => ungltige Funktionsvariable
// 5 => zu viele Funktionen
// 6 => Speicherberlauf
// 7 => Stackberlauf
// 8 => Funktionsname bereits vergeben
// 9 => rekursiver Funktionsaufruf
errpos, // Fehlerposition
ufanz; // max. Anzahl benutzer-
// definierter Funktionen
protected:
......