Commit 13dadb77 authored by Fredrik Edemar's avatar Fredrik Edemar

* KmPlot is now built on KPart.

* When opening a file or pressing the "New" button a new window is shown :-)
* Fixed a crash in the function editor when deleting a function.

CCMAIL: kdmoeller@foni.net,bmlmessmer@web.de

svn path=/trunk/kdeedu/kmplot/; revision=349553
parent 0deb014c
......@@ -45,7 +45,7 @@
#define Inherited FktDlgData
FktDlg::FktDlg( QWidget* parent, XParser* parser ) : Inherited( parent, "editPlots" ), m_parser(parser)
FktDlg::FktDlg( QWidget* parent, View *view ) : Inherited( parent, "editPlots" ), m_view(view)
{
}
......@@ -66,16 +66,16 @@ void FktDlg::slotDelete()
if( lb_fktliste->text( num )[0] == 'x' )
{
// Delete pair of parametric function
int const ix = m_parser->ixValue( getParamId( lb_fktliste->text( num ) ) );
int const ix = m_view->parser()->ixValue( getParamId( lb_fktliste->text( num ) ) );
if ( ix == -1)
return;
m_parser->delfkt( ix+1 );
m_parser->delfkt( ix );
m_view->parser()->delfkt( ix+1 );
m_view->parser()->delfkt( ix );
}
else
{
// only one function to be deleted
m_parser->delfkt( m_parser->ixValue(getId( lb_fktliste->text( num ))) );
m_view->parser()->delfkt( m_view->parser()->ixValue(getId( lb_fktliste->text( num ))) );
}
lb_fktliste->removeItem( num );
......@@ -94,19 +94,19 @@ void FktDlg::slotEdit()
int const id = getId( lb_fktliste->currentText().section( ";", 0, 0) ) ;
// find out the function type
char const prefix = m_parser->ufkt[ m_parser->ixValue(id) ].extstr.at(0).latin1();
char const prefix = m_view->parser()->ufkt[ m_view->parser()->ixValue(id) ].extstr.at(0).latin1();
if ( prefix == 'r')
slotEditPolar( id, num );
else if ( prefix == 'x')
slotEditParametric( id, m_parser->ixValue(getId( lb_fktliste->text( num ).section( ";", 1, 1) )), num );
slotEditParametric( id, m_view->parser()->ixValue(getId( lb_fktliste->text( num ).section( ";", 1, 1) )), num );
else
slotEditFunction( id, num );
}
int FktDlg::getId( const QString &f_str )
{
for( QValueVector<Ufkt>::iterator it = m_parser->ufkt.begin(); it != m_parser->ufkt.end(); ++it)
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->extstr == f_str )
return it->id;
......@@ -117,7 +117,7 @@ int FktDlg::getId( const QString &f_str )
int FktDlg::getParamId( const QString &f_str)
{
QString const fname = f_str.section( "(", 0, 0 );
for( QValueVector<Ufkt>::iterator it = m_parser->ufkt.begin(); it != m_parser->ufkt.end(); ++it)
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fname == fname )
return it->id;
......@@ -127,7 +127,8 @@ int FktDlg::getParamId( const QString &f_str)
void FktDlg::updateView()
{
( ( MainDlg* ) parentWidget() ) ->view->drawPlot();
//( ( MainDlg* )parentWidget() ) ->view->drawPlot();
m_view->drawPlot();
}
void FktDlg::slotHasSelection()
......@@ -139,7 +140,7 @@ void FktDlg::slotHasSelection()
void FktDlg::slotEditFunction( int id, int num )
{
EditFunction* editFunction = new EditFunction( m_parser, this );
EditFunction* editFunction = new EditFunction( m_view->parser(), this );
if ( id==-1&&num==-1) editFunction->setCaption(i18n( "New Function Plot" ));
else editFunction->setCaption(i18n( "Edit Function Plot" ));
editFunction->initDialog( id );
......@@ -155,7 +156,7 @@ void FktDlg::slotEditFunction( int id, int num )
void FktDlg::slotEditParametric( int x_id, int y_id, int num )
{
KEditParametric* editParametric = new KEditParametric( m_parser, this );
KEditParametric* editParametric = new KEditParametric( m_view->parser(), this );
if ( x_id==-1&&y_id==-1&&num==-1) editParametric->setCaption(i18n( "New Parametric Plot" ));
editParametric->initDialog( x_id, y_id );
if( editParametric->exec() == QDialog::Accepted )
......@@ -170,7 +171,7 @@ void FktDlg::slotEditParametric( int x_id, int y_id, int num )
void FktDlg::slotEditPolar( int id, int num )
{
KEditPolar* editPolar = new KEditPolar( m_parser, this );
KEditPolar* editPolar = new KEditPolar( m_view->parser(), this );
if ( id==-1&&num==-1) editPolar->setCaption(i18n( "New Polar Plot" ));
editPolar->initDialog( id );
if( editPolar->exec() == QDialog::Accepted )
......@@ -203,7 +204,7 @@ void FktDlg::getPlots()
lb_fktliste->clear();
// adding all yet added functions
for( QValueVector<Ufkt>::iterator it = m_parser->ufkt.begin(); it != m_parser->ufkt.end(); ++it)
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if( it->fname.isEmpty() || it->extstr[0] == 'y' ) continue;
if( it->extstr[0] == 'x' )
......
......@@ -32,6 +32,7 @@
// locale includes
#include "FktDlgData.h"
#include "View.h"
class XParser;
......@@ -51,7 +52,7 @@ public:
* @param parent Parent widget.
* @param parser points to the current parser instance.
*/
FktDlg( QWidget* parent, XParser* parser );
FktDlg( QWidget* parent, View* view );
/// Empty destructor.
virtual ~FktDlg();
/// Fill the widgets with plots contained in th parser instance.
......@@ -101,7 +102,7 @@ private:
/// Called when the dialog is showed
void showEvent ( QShowEvent * );
/// Ponts to the parser instance.
XParser* m_parser;
View* m_view;
/// indicates if a function is changed/added/removed
bool changed;
};
......
This diff is collapsed.
......@@ -34,10 +34,12 @@
// KDE includes
#include <kaction.h>
#include <kcmdlineargs.h>
#include <kmainwindow.h>
#include <kfiledialog.h>
#include <kpopupmenu.h>
#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <kparts/browserextension.h>
#include <kparts/part.h>
#include <kparts/factory.h>
#undef GrayScale
......@@ -58,7 +60,7 @@ class SettingsPagePrecision;
class SettingsPageScaling;
class KConstantEditor;
class KToggleFullScreenAction;
class BrowserExtension;
/** @short This is the main window of KmPlot.
......@@ -66,145 +68,174 @@ class KToggleFullScreenAction;
* Its central widget view contains the parser, accessable via its parser() function.
* @see View, View::m_parser, View::parser
*/
class MainDlg : public KMainWindow, virtual public MainDlgIface
class MainDlg : public KParts::ReadOnlyPart, virtual public MainDlgIface
{
Q_OBJECT
public:
/** @param sessionId used for the name of a temporary file.
* @param args containing a filename to be plot on startup.
* @param name
*/
MainDlg(QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name);
/// Cleaning up a bit.
virtual ~MainDlg();
/// This class needs access to private members, too.
friend class FktDlg;
/// This class needs access to private members, too.
friend class BezWnd;
void stopDrawing();
/// Asks the user and returns true if modified data shall be dicarded.
bool checkModified();
/// Is set to true if a file from an old file format was loaded
static bool oldfileversion;
public slots:
/// Implement the color edit dialog
void editColors();
/// Implement the coordinate system edit dialog
void editAxes();
/// Implement the scaling edit dialog
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
void newParametric();
/// Implement the dialog to enter a polar plot and its options
void newPolar();
/// Show/hide parameter slider windows
void toggleShowSlider0();
void toggleShowSlider1();
void toggleShowSlider2();
void toggleShowSlider3();
/// Implement the File -> Open action
//void slotOpen();
///Implement the File -> New action by cleaning the plot area
void slotCleanWindow();
///Save a plot i.e. save the function name and all the settings for the plot
void slotSave();
///Save a plot and choose a name for it
void slotSaveas();
///Call the dialog (an instance of FktDlg) to edit the functions and make changes on them
void slotEditPlots();
///Print the current plot
void slotPrint();
///Export the current plot as a png, svg or bmp picture
void slotExport();
///Implement the Configure KmPlot dialog
void slotSettings();
/// Calls the common function names dialog.
/// @see BezWnd::hideEvent
void slotNames();
/// Change the coordinate systems, shows negative x-values and negative y-values.
void slotCoord1();
/// Change the coordinate systems, shows positive x-values and negative y-values.
void slotCoord2();
/// Change the coordinate systems, shows positive x-values and positive y-values.
void slotCoord3();
/// Tools menu
void getYValue();
void findMinimumValue();
void findMaximumValue();
void graphArea();
private:
/// Settings the standard and non standard actions of the application.
void setupActions();
/// Called when a file is opened. The filename is is m_url
virtual bool openFile();
/// Loading the constants by start
void loadConstants();
/// Loading the constants when closing the program
void saveConstants();
/// Returns true if any changes are done
bool isModified(){return m_modified;};
/// Cached dialog to edit all functions
FktDlg *fdlg;
/// Central widget of the KMainWindow instance. tralala
View *view;
///The Recent Files action
KRecentFilesAction * m_recentFiles;
/// true == modifications not saved
bool m_modified;
///An instance of the application config file
KConfig* m_config;
///The KLineEdit which is in the toolbar
KLineEdit* m_quickEdit;
///A Configure KmPlot dialog instance
KConfigDialog* m_settingsDialog;
///The Precision page for the Configure KmPlot dialog
SettingsPagePrecision* m_generalSettings;
///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
/// A dialog used by many tools-menu-items
KMinMax *minmaxdlg;
/// the popup menu shown when cling with the right mouse button on a graph in the graph widget
KPopupMenu *m_popupmenu;
/// Loads and saves the user's file.
KmPlotIO *kmplotio;
/// Set to true if the application is readonly
bool m_readonly;
/// MainDlg's parent widget
QWidget *m_parent;
protected slots:
/**
* When you click on a File->Open Recent file, it'll open
* @param url name of the url to open
*/
void slotOpenRecent( const KURL &url );
///Update settings when there is a change in the Configure KmPlot dialog
void updateSettings();
/**
* Manages the LineEdit content after returnPressed() is emitted.
* @param f_str the content of the KLineEdit
*/
void slotQuickEdit( const QString& tmp_f_str );
void setReadOnlyStatusBarText(const QString &);
/// slots for the settings-menu
void optionsConfigureKeys();
void optionsConfigureToolbars();
};
class KmPlotPartFactory : public KParts::Factory
{
Q_OBJECT
public:
KmPlotPartFactory();
virtual ~KmPlotPartFactory();
virtual KParts::Part* createPartObject( QWidget *parentWidget, const char *widgetName,
QObject *parent, const char *name,
const char *classname, const QStringList &args );
static KInstance* instance();
public:
/** @param sessionId used for the name of a temporary file.
* @param args containing a filename to be plot on startup.
* @param name
*/
MainDlg( KCmdLineArgs* args, const char* name = NULL );
/// Cleaning up a bit.
virtual ~MainDlg();
/// This class needs access to private members, too.
friend class FktDlg;
/// This class needs access to private members, too.
friend class BezWnd;
static bool oldfileversion;
public slots:
/// Implement the color edit dialog
void editColors();
/// Implement the coordinate system edit dialog
void editAxes();
/// Implement the scaling edit dialog
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
void newParametric();
/// Implement the dialog to enter a polar plot and its options
void newPolar();
/// Show/hide parameter slider windows
void toggleShowSlider0();
void toggleShowSlider1();
void toggleShowSlider2();
void toggleShowSlider3();
/// Called when fullscren is enabled/disabled
void slotUpdateFullScreen(bool);
/// Implement the File -> Open action
void slotOpen();
///Implement the File -> New action by cleaning the plot area
void slotOpenNew();
///Save a plot i.e. save the function name and all the settings for the plot
void slotSave();
///Save a plot and choose a name for it
void slotSaveas();
///Call the dialog (an instance of FktDlg) to edit the functions and make changes on them
void slotEditPlots();
///Print the current plot
void slotPrint();
///Export the current plot as a png, svg or bmp picture
void slotExport();
///Implement the Configure KmPlot dialog
void slotSettings();
/// Calls the common function names dialog.
/// @see BezWnd::hideEvent
void slotNames();
/// Change the coordinate systems, shows negative x-values and negative y-values.
void slotCoord1();
/// Change the coordinate systems, shows positive x-values and negative y-values.
void slotCoord2();
/// Change the coordinate systems, shows positive x-values and positive y-values.
void slotCoord3();
/// Tools menu
void getYValue();
void findMinimumValue();
void findMaximumValue();
void graphArea();
private:
/// Settings the standard and non standard actions of the application.
void setupActions();
/// Predefines some space for coordinate information of the plot
void setupStatusBar();
/// Asks the user and returns true if modified data shall be dicarded.
bool checkModified();
/// The Statusbar instance
KStatusBar *stbar;
/// Cached dialog to edit all functions
FktDlg *fdlg;
/// Central widget of the KMainWindow instance. tralala
View *view;
///The Recent Files action
KRecentFilesAction * m_recentFiles;
/** Current filename of the current plot
* isEmpty() == not yet saved */
QString m_filename;
/// true == modifications not saved
bool m_modified;
///An instance of the application config file
KConfig* m_config;
///The KLineEdit which is in the toolbar
KLineEdit* m_quickEdit;
///A Configure KmPlot dialog instance
KConfigDialog* m_settingsDialog;
///The Precision page for the Configure KmPlot dialog
SettingsPagePrecision* m_generalSettings;
///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();
/// A dialog used by many tools-menu-items
KMinMax *minmaxdlg;
/// the popup menu shown when cling with the right mouse button on a graph in the graph widget
KPopupMenu *m_popupmenu;
/// Loads and saves the user's file.
KmPlotIO *kmplotio;
protected slots:
/**
* When you click on a File->Open Recent file, it'll open
* @param url name of the url to open
*/
void slotOpenRecent( const KURL &url );
///Update settings when there is a change in the Configure KmPlot dialog
void updateSettings();
/**
* Manages the LineEdit content after returnPressed() is emitted.
* @param f_str the content of the KLineEdit
*/
void slotQuickEdit( const QString& tmp_f_str );
protected:
/// Quits KmPlot after checking if modifications shall be saved.
virtual bool queryClose();
private:
static KInstance* s_instance;
static KAboutData* s_about;
};
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT
public:
BrowserExtension(MainDlg*);
public slots:
// Automatically detected by the host.
void print();
};
#endif // MainDlg_included
#ifndef MAINDLGIFACE_H
#define MAINDLGIFACE_H
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
......@@ -25,6 +23,9 @@
*
*/
#ifndef MAINDLGIFACE_H
#define MAINDLGIFACE_H
#include <dcopobject.h>
/**
......@@ -32,41 +33,39 @@
*/
/// All functions in MainDlgIface are accessible with DCOP. For descriptions about the functions, see MainDlg.
class MainDlgIface : virtual public DCOPObject
{
K_DCOP
k_dcop:
virtual void editColors() = 0;
virtual void editAxes() = 0;
virtual void editScaling() = 0;
virtual void editFonts() = 0;
virtual void editConstants() = 0;
virtual void newFunction() = 0;
virtual void newParametric() = 0;
virtual void newPolar() = 0;
virtual void toggleShowSlider0() = 0;
virtual void toggleShowSlider1() = 0;
virtual void toggleShowSlider2() = 0;
virtual void toggleShowSlider3() = 0;
virtual void slotOpen() = 0;
virtual void slotOpenNew() = 0;
virtual void slotSave() = 0;
virtual void slotSaveas() = 0;
virtual void slotEditPlots() = 0;
virtual void slotPrint() = 0;
virtual void slotExport() = 0;
virtual void slotSettings() = 0;
virtual void slotNames() = 0;
virtual void slotCoord1() = 0;
virtual void slotCoord2() = 0;
virtual void slotCoord3() = 0;
virtual void getYValue() = 0;
virtual void findMinimumValue() = 0;
virtual void findMaximumValue() = 0;
virtual void graphArea() = 0;
{
K_DCOP
k_dcop:
virtual void stopDrawing() = 0;
virtual bool isModified() = 0;
virtual bool checkModified() = 0;
virtual void editColors() = 0;
virtual void editAxes() = 0;
virtual void editScaling() = 0;
virtual void editFonts() = 0;
virtual void editConstants() = 0;
virtual void newFunction() = 0;
virtual void newParametric() = 0;
virtual void newPolar() = 0;
virtual void toggleShowSlider0() = 0;
virtual void toggleShowSlider1() = 0;
virtual void toggleShowSlider2() = 0;
virtual void toggleShowSlider3() = 0;
virtual void slotCleanWindow() = 0;
virtual void slotSave() = 0;
virtual void slotSaveas() = 0;
virtual void slotEditPlots() = 0;
virtual void slotPrint() = 0;
virtual void slotExport() = 0;
virtual void slotSettings() = 0;
virtual void slotNames() = 0;
virtual void slotCoord1() = 0;
virtual void slotCoord2() = 0;
virtual void slotCoord3() = 0;
virtual void getYValue() = 0;
virtual void findMinimumValue() = 0;
virtual void findMaximumValue() = 0;
virtual void graphArea() = 0;
};
#endif
bin_PROGRAMS = kmplot
kmplot_SOURCES = FktDlgData.ui parser.cpp xparser.cpp main.cpp diagr.cpp View.cpp MainDlg.cpp FktDlg.cpp kprinterdlg.cpp settings.kcfgc settingspagecolor.ui kconstanteditor.cpp qparametereditor.ui kparametereditor.cpp settingspagecoords.ui settingspagefonts.ui settingspagescaling.ui settingspageprecision.ui qeditparametric.ui keditparametric.cpp qeditpolar.ui keditpolar.cpp editfunctionpage.ui editderivativespage.ui editintegralpage.ui editfunction.cpp qeditconstant.ui qminmax.ui kminmax.cpp qconstanteditor.ui keditconstant.cpp kmplotio.cpp sliderwindow.ui MainDlgIface.skel
# set the include path for X, qt and KDE
INCLUDES= $(all_includes)
kmplot_LDADD = $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) $(LIB_KDEPRINT)
# these are the headers for your project
noinst_HEADERS = kmplot.h MainDlg.h
EXTRA_DIST = kmplot.desktop FktDlg.h MainDlg.cpp MainDlg.h View.h diagr.cpp diagr.h xparser.h parser.h kprinterdlg.h keditparametric.h keditpolar.h keditconstant.h kconstanteditor.h kparametereditor.h kmplotio.h kminmax.h
METASOURCES = AUTO
xdg_apps_DATA = kmplot.desktop
messages: rc.cpp
$(EXTRACTRC) *.ui >> rc.cpp
LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
if test -n "$$LIST"; then \
$(XGETTEXT) $$LIST -o $(podir)/kmplot.pot; \
fi
# messages: rc.cpp
# $(XGETTEXT) *.cpp -o $(podir)/kmplot.pot
kde_kcfg_DATA = kmplot.kcfg
# set the include path for X, qt and KDE
INCLUDES= $(all_includes)
#########################################################################
# APPLICATION SECTION
#########################################################################
# this is the program that gets installed. it's name is used for all
# of the other Makefile.am variables
bin_PROGRAMS = kmplot
METASOURCES = AUTO
# the application source, library search path, and link libraries
kmplot_SOURCES = main.cpp kmplot.cpp kmplotprogress.cpp kmplotIface.skel
kmplot_LDFLAGS = $(KDE_RPATH) $(all_libraries)
kmplot_LDADD = $(LIB_KPARTS)
# this is where the desktop file will go
appmimedir = $(kde_mimedir)/application
appmime_DATA = x-kmplot.desktop
# the library search path.
kmplot_LDFLAGS = $(all_libraries) $(KDE_RPATH)
# this is where the shell's XML-GUI resource file goes
shellrcdir = $(kde_datadir)/kmplot
shellrc_DATA = kmplot_shell.rc
rcdir = $(kde_datadir)/kmplot
rc_DATA = kmplotui.rc
messages: rc.cpp
$(EXTRACTRC) *.ui >> rc.cpp
LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
if test -n "$$LIST"; then \
$(XGETTEXT) $$LIST -o $(podir)/kmplot.pot; \
fi
#########################################################################
# KPART SECTION
#########################################################################
kde_module_LTLIBRARIES = libkmplotpart.la
# the Part's source, library search path, and link libraries
libkmplotpart_la_SOURCES = FktDlgData.ui parser.cpp xparser.cpp diagr.cpp View.cpp MainDlg.cpp FktDlg.cpp kprinterdlg.cpp settings.kcfgc settingspagecolor.ui kconstanteditor.cpp qparametereditor.ui kparametereditor.cpp settingspagecoords.ui settingspagefonts.ui settingspagescaling.ui settingspageprecision.ui qeditparametric.ui keditparametric.cpp qeditpolar.ui keditpolar.cpp editfunctionpage.ui editderivativespage.ui editintegralpage.ui editfunction.cpp qeditconstant.ui qminmax