Commit 1929bb92 authored by Matthias Messmer's avatar Matthias Messmer

improved the function editor

svn path=/trunk/kdeedu/kmplot/; revision=295717
parent 1a057f46
......@@ -29,6 +29,7 @@
// KDE includes
#include <kpushbutton.h>
#include <klineedit.h>
// locale includes
#include "FktDlg.h"
......@@ -40,47 +41,28 @@
FktDlg::FktDlg( QWidget* parent, const char* name ) : Inherited( parent, name )
{
int ix;
QString fname, fstr;
lb_fktliste->clear();
// adding all yet added functions
for ( ix = 0; ix < ps.ufanz; ++ix )
{
if ( ps.getfkt( ix, fname, fstr ) == -1 )
continue;
lb_fktliste->insertItem( ps.fktext[ ix ].extstr );
}
if ( lb_fktliste->count() == 0 )
{
le_fktstr->setText( "f(x)=" ); // perhaps a good starting point
le_fktstr->selectAll();
}
le_fktstr->setFocus();
QPopupMenu *menu_types = new QPopupMenu( this );
menu_types->insertItem( i18n( "function" ), this, SLOT( onEditFunction() ) );
menu_types->insertItem( i18n( "parametric" ), this, SLOT( onEditParametric() ) );
menu_types->insertItem( i18n( "polar" ), this, SLOT( onEditPolar() ) );
PushButtonApply->setPopup( menu_types );
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::onapply()
void FktDlg::onnew()
{
int ix;
char c0;
QString fname, fstr, str;
fstr = le_fktstr->text();
// fstr = le_fktstr->text();
if ( !fstr.isEmpty() )
{
// left from semicolon is function equation
......@@ -123,10 +105,10 @@ void FktDlg::onapply()
p = fstr.find( '=' );
fstr = fstr.left( p + 1 );
fstr[ 0 ] = 'y';
le_fktstr->setText( fstr );
/* le_fktstr->setText( fstr );
le_fktstr->setFocus();
le_fktstr->deselect();
return ;
*/ return ;
}
}
else if ( c0 == 'y' )
......@@ -138,22 +120,12 @@ void FktDlg::onapply()
}
}
lb_fktliste->insertItem( fstr );
le_fktstr->clear();
// le_fktstr->clear();
}
errflg = 0;
updateView();
}
void FktDlg::onok()
{
onapply();
if ( errflg == 0 )
{
( ( MainDlg* ) parentWidget() )->fdlg = 0;
close( TRUE );
}
}
void FktDlg::ondelete()
{
int ix, num;
......@@ -170,37 +142,27 @@ void FktDlg::ondelete()
void FktDlg::onedit()
{
int ix, num;
if ( ( num = lb_fktliste->currentItem() ) == -1 )
return ;
ix = getIx( lb_fktliste->text( num ) );
chflg = 1;
ps.delfkt( ix );
le_fktstr->setText( lb_fktliste->text( num ) );
lb_fktliste->removeItem( num );
le_fktstr->setFocus();
le_fktstr->deselect();
updateView();
}
void FktDlg::ondblclick( int )
{
onedit();
}
void FktDlg::onattr()
{
// is anything selected?
if ( lb_fktliste->currentItem() == -1 )
return ;
le_fktstr->clear();
AttrDlg attr( getIx( lb_fktliste->currentText() ) , this, "attr" );
chflg = 1;
attr.exec();
updateView();
int num = lb_fktliste->currentItem();
int index = getIx( lb_fktliste->text( num ) );
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
QString definition = ps.fktext[ index ].extstr;
// find out the function type
char prefix = definition.at(0).latin1();
switch( prefix )
{
case 'r':
onEditPolar( index, num );
break;
case 'x':
case 'y':
onEditParametric( index, num );
break;
default:
onEditFunction( index, num );
}
}
int FktDlg::getIx( const QString f_str )
......@@ -228,26 +190,54 @@ void FktDlg::onHasSelection()
bool has_selection = !( lb_fktliste->currentItem() == -1 );
PushButtonEdit->setEnabled( has_selection );
PushButtonDel->setEnabled( has_selection );
PushButtonAttr->setEnabled( has_selection );
}
void FktDlg::onEditFunction()
void FktDlg::onEditFunction( int index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->setType( KEditFunction::Function );
editFunction->show();
editFunction->initDialog( KEditFunction::Function, index );
if( editFunction->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->yFunction(), num );
}
}
void FktDlg::onEditParametric()
void FktDlg::onEditParametric( int index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->setType( KEditFunction::Parametric );
editFunction->show();
editFunction->initDialog( KEditFunction::Parametric, index );
if( editFunction->exec() == QDialog::Accepted )
{
lb_fktliste->insertItem( editFunction->xFunction() );
lb_fktliste->insertItem( editFunction->yFunction() );
}
}
void FktDlg::onEditPolar()
void FktDlg::onEditPolar( int index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->setType( KEditFunction::Polar );
editFunction->show();
editFunction->initDialog( KEditFunction::Polar, index );
if( editFunction->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->yFunction(), num );
}
}
void FktDlg::fillList()
{
int index;
QString fname, fstr;
lb_fktliste->clear();
// adding all yet added functions
for ( index = 0; index < ps.ufanz; ++index )
{
if ( ps.getfkt( index, fname, fstr ) == -1 )
continue;
lb_fktliste->insertItem( ps.fktext[ index ].extstr );
}
}
......@@ -39,7 +39,6 @@
// locale includes
#include "FktDlgData.h"
#include "AttrDlg.h"
#include "misc.h"
class KEditFunction;
......@@ -63,18 +62,19 @@ public:
FktDlg( QWidget* parent = NULL, const char* name = NULL );
/** And again an empty destructor. */
virtual ~FktDlg();
void fillList();
protected slots:
void onok();
void ondelete();
void onedit();
void ondblclick( int );
void onattr();
void onapply();
void onnew();
void onHasSelection();
void onEditFunction();
void onEditParametric();
void onEditPolar();
// edit the function, index: parser index, num: listbox index
void onEditFunction( int index = -1, int num = -1 );
void onEditParametric( int index = -1, int num = -1 );
void onEditPolar( int index = -1, int num = -1 );
private:
int getIx( const QString f_str );
......
......@@ -74,3 +74,8 @@ void KOptDlg::oncancel()
{
done( 0 );
}
void KOptDlg::onHelp()
{
kapp->invokeHelp( "", "kmplot" );
}
......@@ -42,6 +42,7 @@ protected slots:
void onok();
void oncancel();
void onHelp();
};
#endif // KOptDlg_included
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>313</width>
<height>230</height>
<width>324</width>
<height>232</height>
</rect>
</property>
<property name="caption">
......@@ -296,6 +296,12 @@
<receiver>KOptDlgData</receiver>
<slot>oncancel()</slot>
</connection>
<connection>
<sender>pushButton19</sender>
<signal>clicked()</signal>
<receiver>KOptDlgData</receiver>
<slot>onHelp()</slot>
</connection>
</connections>
<tabstops>
<tabstop>axesLineWidth</tabstop>
......@@ -310,6 +316,7 @@
<slots>
<slot>oncancel()</slot>
<slot>onok()</slot>
<slot>onHelp()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
<includehints>
......
......@@ -23,18 +23,21 @@
*
*/
// local includes
#include "KoordDlg.h"
#include "KoordDlg.moc"
#include "settings.h"
// Qt includes
#include <qbuttongroup.h>
#include <qlineedit.h>
#include <qcheckbox.h>
// KDE includes
#include <kcolorbutton.h>
#include <kmessagebox.h>
#include <knuminput.h>
// local includes
#include "KoordDlg.h"
#include "KoordDlg.moc"
#include "settings.h"
#define Inherited KoordDlgData
......@@ -48,6 +51,10 @@ KoordDlg::KoordDlg( QWidget* parent, const char* name, bool modal ) : Inherited(
kdy = koordy;
setachsen();
cb_beschr->setChecked( mode & BESCHRIFTUNG );
axesLineWidth->setValue( AchsenDicke );
ticLineWidth->setValue( TeilstrichDicke );
ticLength->setValue( TeilstrichLaenge );
color_button->setColor( QColor( AchsenFarbe ) );
}
KoordDlg::~KoordDlg()
......@@ -158,6 +165,11 @@ void KoordDlg::onok()
m = 0;
mode &= ~BESCHRIFTUNG;
}
AchsenDicke = axesLineWidth->value();
TeilstrichDicke = ticLineWidth->value();
TeilstrichLaenge = ticLength->value();
AchsenFarbe = color_button->color().rgb();
if ( cb_default->isChecked() )
{
......@@ -168,6 +180,10 @@ void KoordDlg::onok()
Settings::setYMin( yminstr );
Settings::setYMax( ymaxstr );
Settings::setShowLabel( m == 1 );
Settings::setAxesLineWidth( AchsenDicke );
Settings::setTicWidth( TeilstrichDicke );
Settings::setTicLength( TeilstrichLaenge );
Settings::setAxesColor( AchsenFarbe );
}
done( 1 );
}
......@@ -177,12 +193,14 @@ void KoordDlg::oncancel()
done( 0 );
}
/*
void KoordDlg::onoptions()
{
KOptDlg odlg;
odlg.exec();
}
*/
void KoordDlg::xclicked( int ix )
{
......@@ -205,3 +223,8 @@ void KoordDlg::onYChanged()
kdy = 4;
setachsen();
}
void KoordDlg::onHelp()
{
kapp->invokeHelp( "", "kmplot" );
}
......@@ -67,11 +67,12 @@ protected slots:
void onok();
void oncancel();
void onoptions();
// void onoptions();
void xclicked( int );
void yclicked( int );
void onXChanged();
void onYChanged();
void onHelp();
};
#endif // KoordDlg_included
This diff is collapsed.
......@@ -45,7 +45,7 @@
#include "settingspagescaling.h"
#include "settingspagefonts.h"
MainDlg::MainDlg( KCmdLineArgs* args, const char* name ) : KMainWindow( 0, name )
MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name ) : KMainWindow( 0, name )
{
init();
fdlg = 0;
......@@ -54,6 +54,7 @@ MainDlg::MainDlg( KCmdLineArgs* args, const char* name ) : KMainWindow( 0, name
setCentralWidget( view );
setupActions();
setupStatusBar();
m_sessionId = sessionId;
if (args -> count() > 0) openFile( args -> url(0).fileName() );
}
......@@ -123,7 +124,7 @@ void MainDlg::save()
if ( datei.isEmpty() ) // if there is no file name set yet
saveas();
else
doSave();
doSave( datei );
}
void MainDlg::saveas()
......@@ -133,13 +134,13 @@ void MainDlg::saveas()
{
if ( datei.find( "." ) == -1 ) // no file extension
datei = datei + ".fkt"; // use fkt-type as default
doSave();
doSave( datei );
setCaption( datei );
}
}
// here the real storing is done...
void MainDlg::doSave()
void MainDlg::doSave( QString filename )
{
////////////
// save as svg by drawing into a QPicture and saving it as svg
......@@ -215,7 +216,7 @@ void MainDlg::doSave()
}
}
QFile xmlfile( datei );
QFile xmlfile( filename );
xmlfile.open( IO_WriteOnly );
QTextStream ts( &xmlfile );
doc.save( ts, 4 );
......@@ -236,15 +237,17 @@ void MainDlg::load()
if ( d.isEmpty() )
return ;
openFile(d);
datei = d;
setCaption( datei );
}
void MainDlg::openFile( QString d )
void MainDlg::openFile( QString filename )
{
init();
QDomDocument doc( "kmpdoc" );
QFile f( d );
QFile f( filename );
if ( !f.open( IO_ReadOnly ) )
return ;
if ( !doc.setContent( &f ) )
......@@ -315,11 +318,6 @@ void MainDlg::openFile( QString d )
ymin = ps.eval( yminstr );
ymax = ps.eval( ymaxstr );
}
datei = d;
setCaption( datei );
view->update();
}
......@@ -426,8 +424,13 @@ void MainDlg::bezeichnungen()
void MainDlg::funktionen()
{
if ( !fdlg ) fdlg = new FktDlg( this );
fdlg->show();
if ( !fdlg ) fdlg = new FktDlg( this ); // make the dialog only if not allready done
fdlg->fillList(); //
QString tmpName = locate ( "tmp", "" ) + "kmplot-" + m_sessionId;
doSave( tmpName );
if( fdlg->exec() == QDialog::Rejected ) openFile( tmpName );
else QFile::remove( tmpName );
view->update();
}
void MainDlg::skalierung()
......
......@@ -71,7 +71,7 @@ class MainDlg : public KMainWindow
Q_OBJECT
public:
MainDlg( KCmdLineArgs* args, const char* name = NULL );
MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name = NULL );
virtual ~MainDlg();
friend class FktDlg;
friend class BezWnd;
......@@ -96,7 +96,7 @@ public slots:
private:
void setupActions();
void doSave();
void doSave( QString filename );
void setupStatusBar();
void addTag( QDomDocument &doc, QDomElement &parentTag, const QString tagName, const QString tagValue );
void openFile( QString d );
......@@ -113,6 +113,7 @@ private:
BezWnd *bez;
KToggleAction *view_bezeichnungen;
View *view;
QString m_sessionId;
private slots:
void newToolbarConfig();
......
......@@ -24,10 +24,15 @@
*/
// Qt includes
#include <qcheckbox.h>
#include <qlabel.h>
// KDE includes
#include <kcolorbutton.h>
#include <knuminput.h>
#include <klineedit.h>
#include <kdebug.h>
// local includes
#include "keditfunction.h"
#include "keditfunction.moc"
......@@ -39,35 +44,119 @@ KEditFunction::KEditFunction( XParser* parser, QWidget* parent, const char* name
m_parser = parser;
}
void KEditFunction::setType( const FunctionType t )
/**
* Fill the dialog's widgets with the properties of the parser function number index.
*/
void KEditFunction::initDialog( const FunctionType t, int index )
{
m_type = t;
switch( t )
m_index = index;
setVisibleWidgets();
if( m_index == -1 ) clearWidgets();
else setWidgets();
}
void KEditFunction::setVisibleWidgets()
{
switch( m_type )
{
case Function:
this->setCaption( "Edit Function Plot" );
this->setCaption( i18n( "Edit Function Plot" ) );
kLineEditXFunction->hide();
textLabelX->hide();
textLabelXF->hide();
textLabelArgX->hide();
textLabelY->setText( "" );
textLabelArgY->setText( "(x) = " );
checkBoxDerivative1->show();
checkBoxDerivative2->show();
break;
case Parametric:
this->setCaption( "Edit Parametric Plot" );
this->setCaption( i18n( "Edit Parametric Plot" ) );
kLineEditXFunction->show();
textLabelX->show();
textLabelXF->show();
textLabelArgX->show();
textLabelY->setText( "y" );
textLabelArgY->setText( "(t) = " );
checkBoxDerivative1->hide();
checkBoxDerivative2->hide();
break;
case Polar:
this->setCaption( "Edit Polar Plot" );
this->setCaption( i18n( "Edit Polar Plot" ) );
kLineEditXFunction->hide();
textLabelX->hide();
textLabelXF->hide();
textLabelArgX->hide();
textLabelY->setText( "r" );
textLabelArgY->setText( "(theta) = " );
checkBoxDerivative1->show();
checkBoxDerivative2->show();
}
updateGeometry();
}
void KEditFunction::clearWidgets()
{
kLineEditName->clear();
kLineEditXFunction->clear();
kLineEditYFunction->clear();
checkBoxHide->setChecked( false );
checkBoxDerivative1->setChecked( false );
checkBoxDerivative2->setChecked( false );
checkBoxRange->setChecked( false );
min->clear();
max->clear();
kIntNumInputLineWidth->setValue( m_parser->dicke0 );
kColorButtonColor->setColor( "#000000" );
}
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;