Commit fd305f9c authored by Fredrik Edemar's avatar Fredrik Edemar

My first patch. This adds support for drawing antiderivative with Euler's...

My first patch. This adds support for drawing antiderivative with Euler's method, a new plot function dialog, a constant editor, ability to change between radians and degrees + automatic suggestion for function names. Big thanks to pipesmoker and annma on IRC!

svn path=/trunk/kdeedu/kmplot/; revision=311398
parent 861e2981
......@@ -29,12 +29,13 @@
// KDE includes
#include <kapplication.h>
#include <klocale.h>
#include <kpushbutton.h>
// locale includes
#include "FktDlg.h"
#include "FktDlg.moc"
#include "keditfunction.h"
#include "editfunction.h"
#include "keditparametric.h"
#include "keditpolar.h"
#include "MainDlg.h"
......@@ -84,17 +85,12 @@ void FktDlg::slotEdit()
// find out the function type
char prefix = m_parser->fktext[ index ].extstr.at(0).latin1();
switch( prefix )
{
case 'r':
slotEditPolar( index, num );
break;
case 'x':
slotEditParametric( index, getIx( lb_fktliste->text( num ).section( ";", 1, 1) ), num );
break;
default:
slotEditFunction( index, num );
}
if ( prefix == 'r')
slotEditPolar( index, num );
else if ( prefix == 'x')
slotEditParametric( index, getIx( lb_fktliste->text( num ).section( ";", 1, 1) ), num );
else
slotEditFunction( index, num );
updateView();
}
......@@ -136,7 +132,8 @@ void FktDlg::slotHasSelection()
void FktDlg::slotEditFunction( int index, int num )
{
KEditFunction* editFunction = new KEditFunction( m_parser, this );
EditFunction* editFunction = new EditFunction( m_parser, this );
if ( index==-1&&num==-1) editFunction->setCaption(i18n( "New Function Plot" ));
editFunction->initDialog( index );
if( editFunction->exec() == QDialog::Accepted )
{
......@@ -148,6 +145,7 @@ void FktDlg::slotEditFunction( int index, int num )
void FktDlg::slotEditParametric( int x_index, int y_index, int num )
{
KEditParametric* editParametric = new KEditParametric( m_parser, this );
if ( x_index==-1&&y_index==-1&&num==-1) editParametric->setCaption(i18n( "New Parametric Plot" ));
editParametric->initDialog( x_index, y_index );
if( editParametric->exec() == QDialog::Accepted )
{
......@@ -160,6 +158,7 @@ void FktDlg::slotEditParametric( int x_index, int y_index, int num )
void FktDlg::slotEditPolar( int index, int num )
{
KEditPolar* editPolar = new KEditPolar( m_parser, this );
if ( index==-1&&num==-1) editPolar->setCaption(i18n( "New Polar Plot" ));
editPolar->initDialog( index );
if( editPolar->exec() == QDialog::Accepted )
{
......
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>FktDlgData</class>
<widget class="QDialog">
<property name="name">
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>429</width>
<height>353</height>
<width>462</width>
<height>355</height>
</rect>
</property>
<property name="minimumSize">
......@@ -21,7 +21,7 @@
<property name="caption">
<string>Edit Plots</string>
</property>
<vbox>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
......@@ -31,7 +31,79 @@
<property name="spacing">
<number>6</number>
</property>
<widget class="QFrame">
<widget class="QLayoutWidget" row="1" column="0">
<property name="name">
<cstring>layout3</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>pushButtonHelp</cstring>
</property>
<property name="text">
<string>&amp;Help</string>
</property>
<property name="accel">
<string>Alt+H</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer6</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<property name="name">
<cstring>PushButtonOk</cstring>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
<property name="accel">
<string>Alt+O</string>
</property>
<property name="toolTip" stdset="0">
<string>apply the changes and close the dialog</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click here to apply your changes and close this dialog.</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>pushButtonCancel</cstring>
</property>
<property name="text">
<string>&amp;Cancel</string>
</property>
<property name="accel">
<string>Alt+C</string>
</property>
<property name="toolTip" stdset="0">
<string>cancel without any changes</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click here to close the dialog without any changes.</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QFrame" row="0" column="0">
<property name="name">
<cstring>frame5</cstring>
</property>
......@@ -45,7 +117,7 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QListBox" row="0" column="0" rowspan="6" colspan="1">
<widget class="QListBox" row="0" column="0" rowspan="7" colspan="1">
<property name="name">
<cstring>lb_fktliste</cstring>
</property>
......@@ -98,35 +170,24 @@
<string>Click here to define a new function. There are 3 types of function, explicite given functions, parametric plots and polar plots. Choose the appropriate type from the drop down list.</string>
</property>
</widget>
<widget class="QPushButton" row="3" column="1">
<spacer row="6" column="1">
<property name="name">
<cstring>PushButtonEdit</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Edit</string>
<cstring>Spacer1</cstring>
</property>
<property name="accel">
<string>Alt+E</string>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="toolTip" stdset="0">
<string>edit the selected function</string>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="whatsThis" stdset="0">
<string>Click here to edit the selected function.</string>
<property name="sizeHint">
<size>
<width>20</width>
<height>70</height>
</size>
</property>
</widget>
<widget class="QPushButton" row="4" column="1">
</spacer>
<widget class="QPushButton" row="5" column="1">
<property name="name">
<cstring>PushButtonDel</cstring>
</property>
......@@ -154,7 +215,7 @@
<string>Click here to delete the selected function from the list.</string>
</property>
</widget>
<widget class="QPushButton" row="1" column="1">
<widget class="QPushButton" row="2" column="1">
<property name="name">
<cstring>PushButtonNewParametric</cstring>
</property>
......@@ -179,7 +240,7 @@
<string>Click here to define a new function. There are 3 types of function, explicite given functions, parametric plots and polar plots. Choose the appropriate type from the drop down list.</string>
</property>
</widget>
<widget class="QPushButton" row="2" column="1">
<widget class="QPushButton" row="3" column="1">
<property name="name">
<cstring>PushButtonNewPolar</cstring>
</property>
......@@ -204,98 +265,37 @@
<string>Click here to define a new function. There are 3 types of function, explicite given functions, parametric plots and polar plots. Choose the appropriate type from the drop down list.</string>
</property>
</widget>
<spacer row="5" column="1">
<property name="name">
<cstring>Spacer1</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>80</height>
</size>
</property>
</spacer>
</grid>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>pushButtonHelp</cstring>
</property>
<property name="text">
<string>&amp;Help</string>
</property>
<property name="accel">
<string>Alt+H</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer6</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QPushButton">
<widget class="QPushButton" row="4" column="1">
<property name="name">
<cstring>PushButtonOk</cstring>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
<property name="accel">
<string>Alt+O</string>
</property>
<property name="toolTip" stdset="0">
<string>apply the changes and close the dialog</string>
<cstring>PushButtonEdit</cstring>
</property>
<property name="whatsThis" stdset="0">
<string>Click here to apply your changes and close this dialog.</string>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>pushButtonCancel</cstring>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Cancel</string>
<string>&amp;Edit</string>
</property>
<property name="accel">
<string>Alt+C</string>
<string>Alt+E</string>
</property>
<property name="toolTip" stdset="0">
<string>cancel without any changes</string>
<string>edit the selected function</string>
</property>
<property name="whatsThis" stdset="0">
<string>Click here to close the dialog without any changes.</string>
<string>Click here to edit the selected function.</string>
</property>
</widget>
</hbox>
</grid>
</widget>
</vbox>
</grid>
</widget>
<connections>
<connection>
......@@ -378,6 +378,7 @@
<slot>slotNewPolar()</slot>
<slot>slotNewFunction()</slot>
<slot access="protected">slotHelp()</slot>
<slot>slotNewPrime()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>
......@@ -37,11 +37,12 @@
#include <kmessagebox.h>
// local includes
#include "keditfunction.h"
#include "editfunction.h"
#include "keditparametric.h"
#include "keditpolar.h"
#include "kmplotio.h"
#include "kprinterdlg.h"
#include "kconstanteditor.h"
#include "MainDlg.h"
#include "MainDlg.moc"
#include "settings.h"
......@@ -51,6 +52,9 @@
#include "settingspageprecision.h"
#include "settingspagescaling.h"
#include "xparser.h"
#include "kmplotio.h"
MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name ) : KMainWindow( 0, name ), m_recentFiles( 0 )
{
......@@ -62,6 +66,7 @@ MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name
QToolTip::add( m_quickEdit, i18n( "Enter a function equation, for example: f(x)=x^2" ) );
setupActions();
setupStatusBar();
loadConstants();
m_sessionId = sessionId;
if (args -> count() > 0)
{
......@@ -77,10 +82,12 @@ MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name
m_settingsDialog = new KConfigDialog( this, "settings", Settings::self() );
// create and add the page(s)
m_precisionSettings = new SettingsPagePrecision( 0, "precisionSettings" );
m_settingsDialog->addPage( m_precisionSettings, i18n( "Precision" ), "" );
m_constantsSettings = new KConstantEditor( view, 0, "constantsSettings" );
m_settingsDialog->addPage( m_precisionSettings, i18n( "Precision" ), "" );
m_settingsDialog->addPage( m_constantsSettings, i18n( "Constants" ), "" );
// User edited the configuration - update your local copies of the
// configuration data
connect( m_settingsDialog, SIGNAL( settingsChanged() ), this, SLOT(updateSettings() ) );
connect( m_settingsDialog, SIGNAL( settingsChanged() ), this, SLOT(updateSettings() ) );
m_modified = false;
setAutoSaveSettings();
}
......@@ -88,6 +95,7 @@ MainDlg::MainDlg( const QString sessionId, KCmdLineArgs* args, const char* name
MainDlg::~MainDlg()
{
m_recentFiles->saveEntries( m_config );
saveConstants();
}
void MainDlg::setupActions()
......@@ -334,6 +342,12 @@ void MainDlg::editFonts()
fontsDialog->show();
}
void MainDlg::editConstants()
{
QConstantEditor* contsDialog = new QConstantEditor();
contsDialog->show();
}
void MainDlg::slotNames()
{
if ( !bez )
......@@ -348,7 +362,8 @@ void MainDlg::slotNames()
void MainDlg::newFunction()
{
KEditFunction* editFunction = new KEditFunction( view->parser(), this );
EditFunction* editFunction = new EditFunction( view->parser(), this );
editFunction->setCaption(i18n( "New Function Plot" ) );
editFunction->initDialog();
m_modified = editFunction->exec() == QDialog::Accepted;
view->update();
......@@ -357,6 +372,7 @@ void MainDlg::newFunction()
void MainDlg::newParametric()
{
KEditParametric* editParametric = new KEditParametric( view->parser(), this );
editParametric->setCaption(i18n( "New Parametric Plot"));
editParametric->initDialog();
m_modified = editParametric->exec() == QDialog::Accepted;
view->update();
......@@ -365,6 +381,7 @@ void MainDlg::newParametric()
void MainDlg::newPolar()
{
KEditPolar* editPolar = new KEditPolar( view->parser(), this );
editPolar->setCaption(i18n( "New Polar Plot"));
editPolar->initDialog();
m_modified = editPolar->exec() == QDialog::Accepted;
view->update();
......@@ -373,7 +390,7 @@ void MainDlg::newPolar()
void MainDlg::slotEditPlots()
{
if ( !fdlg ) fdlg = new FktDlg( this, view->parser() ); // make the dialog only if not allready done
fdlg->getPlots(); //
fdlg->getPlots();
QString tmpName = locate ( "tmp", "" ) + "kmplot-" + m_sessionId;
KmPlotIO::save( view->parser(), tmpName );
if( fdlg->exec() == QDialog::Rejected )
......@@ -386,9 +403,14 @@ void MainDlg::slotEditPlots()
view->update();
}
void MainDlg::slotQuickEdit( const QString& f_str )
void MainDlg::slotQuickEdit(const QString& tmp_f_str )
{
//creates a valid name for the function if the user has forgotten that
QString f_str( tmp_f_str );
view->parser()->fixFunctionName(f_str);
int index = view->parser()->addfkt( f_str );
if( index == -1 )
{
view->parser()->errmsg();
......@@ -396,11 +418,13 @@ void MainDlg::slotQuickEdit( const QString& f_str )
m_quickEdit->selectAll();
return;
}
view->parser()->fktext[index].anti_mode = 0;
view->parser()->fktext[ index ].extstr = f_str;
view->parser()->getext( index );
m_quickEdit->clear();
m_modified = true;
view->update();
view->parser()->errmsg();
}
......@@ -484,3 +508,61 @@ void MainDlg::slotFullScreen()
}
}
void MainDlg::loadConstants()
{
KSimpleConfig conf ("kcalcrc");
conf.setGroup("Constants");
QString tmp;
QString tmp_constant;
char constant;
double value;
for( int i=0; ;i++)
{
tmp.setNum(i+1);
tmp_constant = conf.readEntry("nameConstant"+tmp," ");
value = conf.readDoubleNumEntry("valueConstant"+tmp,1.23456789);
constant = tmp_constant.at(0).latin1();
if ( tmp_constant == " " || value == 1.23456789)
break;
else
{
bool stop = false;
if ( !view->parser()->constant.empty() )
for( ; !stop;constant++)
{
for( int k = 0; k< (int)view->parser()->constant.size() && !stop;k++)
{
if (constant != view->parser()->constant[k].constant)
{
constant = view->parser()->constant[k].constant;
stop = true;
}
}
if (constant == 'Z')
constant = 'A'-1;
}
/*kdDebug() << "**************" << endl;
kdDebug() << "C:" << constant << endl;
kdDebug() << "V:" << value << endl;*/
view->parser()->constant.append(Constant(constant, value) );
}
}
}
void MainDlg::saveConstants()
{
KSimpleConfig conf ("kcalcrc");
conf.deleteGroup("Constants");
conf.setGroup("Constants");
QString tmp;
for( int i = 0; i< (int)view->parser()->constant.size();i++)
{
tmp.setNum(i+1);
conf.writeEntry("nameConstant"+tmp, QString( QChar(view->parser()->constant[i].constant) ) ) ;
conf.writeEntry("valueConstant"+tmp, view->parser()->constant[i].value);
}
}
......@@ -54,8 +54,11 @@ class SettingsPageColor;
class SettingsPageFonts;
class SettingsPagePrecision;
class SettingsPageScaling;
class KConstantEditor;
class KToggleFullScreenAction;
/** @short This is the main window of KmPlot.
*
* Its central widget view contains the parser, accessable via its parser() function.
......@@ -77,6 +80,7 @@ class MainDlg : public KMainWindow
friend class FktDlg;
/// This class needs access to private members, too.
friend class BezWnd;
static bool test;
public slots:
/// Implement the color edit dialog
......@@ -87,6 +91,8 @@ class MainDlg : public KMainWindow
void editScaling();
/// Implement the fonts edit dialog
void editFonts();
/// Implement the constants edit dialog
void editConstants();
/// Implement the dialog to enter a function plot and its options
void newFunction();
/// Implement the dialog to enter a parametric plot and its options
......@@ -131,8 +137,14 @@ class MainDlg : public KMainWindow
KConfigDialog* m_settingsDialog;
///The Precision page for the Configure KmPlot dialog
SettingsPagePrecision* m_precisionSettings;
///The Constants page for the Configure KmPlot constants
KConstantEditor* m_constantsSettings;
/// The fullscreen action to be plugged/unplegged to the toolbar
KToggleFullScreenAction* m_fullScreen;
/// Loading the constants by start
void loadConstants();
/// Loading the constants when closing the program
void saveConstants();
protected slots:
/// Implement the File -> Open action
......@@ -177,7 +189,7 @@ class MainDlg : public KMainWindow
* Manages the LineEdit content after returnPressed() is emitted.
* @param f_str the content of the KLineEdit
*/
void slotQuickEdit( const QString& f_str );
void slotQuickEdit( const QString& tmp_f_str );
/// Enable or disable fullscreen
void slotFullScreen();
......
bin_PROGRAMS = kmplot
kmplot_SOURCES = FktDlgData.ui BezWndData.ui xparser.cpp parser.cpp main.cpp diagr.cpp View.cpp MainDlg.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 kmplotio.cpp
kmplot_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) $(LIB_KDEPRINT)
EXTRA_DIST = kmplot.desktop BezWnd.h FktDlg.h MainDlg.cpp MainDlg.h View.h diagr.cpp diagr.h parser.h xparser.h kprinterdlg.h qeditfunction.ui keditfunction.h keditparametric.h keditpolar.h kmplotio.h
kmplot_SOURCES = FktDlgData.ui BezWndData.ui parser.cpp xparser.cpp main.cpp diagr.cpp View.cpp MainDlg.cpp FktDlg.cpp BezWnd.cpp kprinterdlg.cpp settings.kcfgc settingspagecolor.ui kconstanteditor.cpp settingspagecoords.ui settingspagefonts.ui settingspagescaling.ui settingspageprecision.ui qeditprimefunction.ui qeditparametric.ui keditparametric.cpp qeditpolar.ui keditpolar.cpp editfunctionpage.ui editderivativespage.ui editantiderivativepage.ui editfunction.cpp qeditconstant.ui qconstanteditor.ui keditconstant.cpp kmplotio.cpp
kmplot_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) $(LIB_KDEPRINT)
EXTRA_DIST = kmplot.desktop BezWnd.h FktDlg.h MainDlg.cpp MainDlg.h View.h diagr.cpp diagr.h xparser.h parser.h kprinterdlg.h qeditprimefunction.ui keditparametric.h keditpolar.h keditconstant.h kconstanteditor.h kmplotio.h
xdg_apps_DATA = kmplot.desktop
kde_kcfg_DATA = kmplot.kcfg
kde_kcfg_DATA = kmplot.kcfg
# set the include path for X, qt and KDE
INCLUDES= $(all_includes)
......@@ -28,4 +30,3 @@ messages: rc.cpp
if test -n "$$LIST"; then \
$(XGETTEXT) $$LIST -o $(podir)/kmplot.pot; \