Commit 73af1509 authored by David Saxton's avatar David Saxton

Implemented new KmPlot UI, as mentioned on kde-edu ml. All the plot dialogs

have been removed, and their functionality has been put into a QDockWidget in
the main view.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=524074
parent 7402f5db
......@@ -11,48 +11,48 @@
</ignoreparts>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description></description>
<description/>
<secondaryLanguages>
<language>C++</language>
</secondaryLanguages>
<versioncontrol></versioncontrol>
<versioncontrol/>
</general>
<kdevcustomproject>
<run>
<mainprogram>kmplot/kmplot</mainprogram>
<directoryradio>executable</directoryradio>
<customdirectory>/</customdirectory>
<programargs></programargs>
<programargs/>
<terminal>false</terminal>
<autocompile>true</autocompile>
<envvars/>
</run>
<build>
<buildtool>make</buildtool>
<builddir></builddir>
<builddir/>
</build>
<make>
<abortonerror>false</abortonerror>
<numberofjobs>1</numberofjobs>
<dontact>false</dontact>
<makebin></makebin>
<makebin/>
<selectedenvironment>default</selectedenvironment>
<environments>
<default/>
</environments>
<makeoptions></makeoptions>
<makeoptions/>
<prio>0</prio>
<defaulttarget></defaulttarget>
<defaulttarget/>
</make>
</kdevcustomproject>
<kdevdebugger>
<general>
<dbgshell></dbgshell>
<programargs></programargs>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<dbgshell/>
<programargs/>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
......@@ -141,10 +141,10 @@
<qt>
<used>false</used>
<version>3</version>
<root></root>
<root/>
</qt>
<creategettersetter>
<prefixGet></prefixGet>
<prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
......@@ -153,7 +153,10 @@
</creategettersetter>
</kdevcppsupport>
<kdevfileview>
<groups/>
<groups>
<hidenonprojectfiles>false</hidenonprojectfiles>
<hidenonlocation>false</hidenonlocation>
</groups>
<tree>
<hidepatterns>*.o,*.lo,CVS,*.moc,*~</hidepatterns>
<hidenonprojectfiles>false</hidenonprojectfiles>
......@@ -167,8 +170,8 @@
</cppsupportpart>
<kdevvisualadvance>
<emulator>VisualBoyAdvance</emulator>
<binary></binary>
<addOptions></addOptions>
<binary/>
<addOptions/>
<terminal>false</terminal>
<fullscreen>false</fullscreen>
<graphicFilter>-f0</graphicFilter>
......@@ -176,13 +179,13 @@
</kdevvisualadvance>
<kdevdocumentation>
<projectdoc>
<docsystem></docsystem>
<docurl></docurl>
<usermanualurl></usermanualurl>
<docsystem/>
<docurl/>
<usermanualurl/>
</projectdoc>
</kdevdocumentation>
<ctagspart>
<customArguments></customArguments>
<customTagfilePath></customTagfilePath>
<customArguments/>
<customTagfilePath/>
</ctagspart>
</kdevelop>
......@@ -87,3 +87,5 @@ kmplot/keditpolar.cpp
kmplot/keditpolar.h
kmplot/qeditparametric.ui
kmplot/qeditpolar.ui
/functioneditor.h
/functioneditor.cpp
......@@ -6,18 +6,15 @@ include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_D
########### next target ###############
set(kmplotpart_PART_SRCS
functioneditor.cpp
parser.cpp
xparser.cpp
diagr.cpp
View.cpp
MainDlg.cpp
FktDlg.cpp
kprinterdlg.cpp
kconstanteditor.cpp
kparametereditor.cpp
keditparametric.cpp
keditpolar.cpp
editfunction.cpp
kminmax.cpp
kmplotio.cpp
ksliderwindow.cpp
......@@ -26,14 +23,9 @@ set(kmplotpart_PART_SRCS
kde4_automoc(${kmplotpart_PART_SRCS})
kde4_add_ui_files(kmplotpart_PART_SRCS
functioneditorwidget.ui
editcoords.ui
editderivativespage.ui
editfunctionpage.ui
editintegralpage.ui
editscaling.ui
FktDlgData.ui
qeditparametric.ui
qeditpolar.ui
qminmax.ui
qparametereditor.ui
settingspagecolor.ui
......
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter M�ler
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
// Qt includes
// #include <qpushbutton.h>
// #include <qpopupmenu.h>
// KDE includes
#include <kapplication.h>
#include <k3listview.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <qcursor.h>
#include <qtimer.h>
#include <QShowEvent>
// locale includes
#include "FktDlg.h"
#include "FktDlg.moc"
#include "editfunction.h"
#include "keditparametric.h"
#include "keditpolar.h"
#include "MainDlg.h"
#include "parseriface.h"
#include "xparser.h"
#include <kdebug.h>
#include <ktoolinvocation.h>
FktDlg::FktDlg( QWidget* parent, View *view )
: KDialog( parent, i18n("Edit Plots"), Ok|Cancel|Help ),
m_view(view)
{
m_mainWidget = new FktDlgData( this );
setMainWidget( m_mainWidget );
connect( m_mainWidget->cmdCopyFunction, SIGNAL( clicked() ), this, SLOT( slotCopyFunction()) );
connect( m_mainWidget->cmdMoveFunction, SIGNAL( clicked() ), this, SLOT( slotMoveFunction()) );
connect( m_mainWidget->lb_fktliste, SIGNAL( itemDoubleClicked(QListWidgetItem *)), this, SLOT(lb_fktliste_doubleClicked(QListWidgetItem *)) );
connect( m_mainWidget->lb_fktliste, SIGNAL( itemClicked(QListWidgetItem *)), this, SLOT(lb_fktliste_clicked(QListWidgetItem *)));
connect(m_mainWidget->PushButtonDel, SIGNAL(clicked()), this, SLOT(slotDelete()));
connect(m_mainWidget->lb_fktliste, SIGNAL(itemSelectionChanged()), this, SLOT(slotHasSelection()));
// connect(PushButtonOk, SIGNAL(clicked()), this, SLOT(accept()));
// connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_mainWidget->PushButtonEdit, SIGNAL(clicked()), this, SLOT(slotEdit()));
connect(m_mainWidget->PushButtonNewFunction, SIGNAL(clicked()), this, SLOT(slotNewFunction()));
connect(m_mainWidget->PushButtonNewParametric, SIGNAL(clicked()), this, SLOT(slotNewParametric()));
connect(m_mainWidget->PushButtonNewPolar, SIGNAL(clicked()), this, SLOT(slotNewPolar()));
// connect(pushButtonHelp, SIGNAL(clicked()), this, SLOT(slotHelp()));
}
FktDlg::~FktDlg()
{
}
void FktDlg::slotDelete()
{
if ( m_mainWidget->lb_fktliste->currentItem() == 0)
return;
QListWidgetItem *currentItem = m_mainWidget->lb_fktliste->currentItem();
if( currentItem->text()[0] == 'x' )
{
// Delete pair of parametric function
int const id = getParamId( currentItem->text());
if ( id == -1)
return;
if ( !m_view->parser()->delfkt(id))
return;
}
else
{
// only one function to be deleted
if (!m_view->parser()->delfkt( getId( currentItem->text()) ) )
return;
}
m_mainWidget->lb_fktliste->takeItem( m_mainWidget->lb_fktliste->currentRow() );
changed = true;
updateView();
slotHasSelection();
}
void FktDlg::lb_fktliste_doubleClicked( QListWidgetItem * )
{
slotEdit();
}
void FktDlg::lb_fktliste_clicked( QListWidgetItem * )
{
// use a single shot as the check state of the item isn't updated before emitting the clicked signal
QTimer::singleShot( 0, this, SLOT( checkCurrentItemCheckState() ) );
}
void FktDlg::checkCurrentItemCheckState()
{
QListWidgetItem * item = m_mainWidget->lb_fktliste->currentItem();
int id;
if ( item->text()[0] == 'x' )
id = getParamId(item->text());
else
id = getId(item->text());
Ufkt *function = &m_view->parser()->ufkt[ m_view->parser()->ixValue(id) ];
if ( id==-1 )
return;
function->f_mode = (item->checkState() & Qt::Checked);
updateView();
}
void FktDlg::slotEdit()
{
QListWidgetItem * currentItem = m_mainWidget->lb_fktliste->currentItem();
if ( currentItem == 0 )
{
m_mainWidget->PushButtonEdit->setEnabled(false);
return;
}
int const id = getId( currentItem->text().section( ";", 0, 0) ) ;
// find out the function type
QChar prefix = m_view->parser()->ufkt[ m_view->parser()->ixValue(id) ].fstr[0];
if ( prefix == 'r')
slotEditPolar( id );
else if ( prefix == 'x')
slotEditParametric( id, m_view->parser()->ixValue(getId( currentItem->text().section( ";", 1, 1) )));
else
slotEditFunction( id );
}
int FktDlg::getId( const QString &f_str )
{
for( QVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fstr == f_str )
return it->id;
}
return -1;
}
int FktDlg::getParamId( const QString &f_str)
{
QString const fname = f_str.section( "(", 0, 0 );
for( QVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fname == fname )
return it->id;
}
return -1;
}
void FktDlg::updateView()
{
m_view->drawPlot();
}
void FktDlg::slotHasSelection()
{
bool const has_selection = !m_mainWidget->lb_fktliste->selectedItems().isEmpty();
m_mainWidget->PushButtonEdit->setEnabled( has_selection );
m_mainWidget->PushButtonDel->setEnabled( has_selection );
m_mainWidget->cmdCopyFunction->setEnabled( has_selection );
m_mainWidget->cmdMoveFunction->setEnabled( has_selection );
}
void FktDlg::slotEditFunction( int id )
{
EditFunction* editFunction = new EditFunction( m_view->parser(), this );
if ( id==-1 ) editFunction->setCaption(i18n( "New Function Plot" ));
else editFunction->setCaption(i18n( "Edit Function Plot" ));
editFunction->initDialog( id );
if( editFunction->exec() == QDialog::Accepted )
{
Ufkt *function = editFunction->functionItem();
QListWidgetItem *item;
if( id == -1 ) //a new function
item = new QListWidgetItem( function->fstr, m_mainWidget->lb_fktliste ); //a new function
else //change a function
{
item = m_mainWidget->lb_fktliste->currentItem();
item->setText( function->fstr );
}
item->setCheckState( function->f_mode ? Qt::Checked : Qt::Unchecked );
m_mainWidget->lb_fktliste->sortItems();
changed = true;
updateView();
}
}
void FktDlg::slotEditParametric( int x_id, int y_id)
{
KEditParametric* editParametric = new KEditParametric( m_view->parser(), this );
if ( x_id==-1 && y_id==-1)
editParametric->setCaption(i18n( "New Parametric Plot" ));
editParametric->initDialog( x_id, y_id );
if( editParametric->exec() == QDialog::Accepted )
{
Ufkt *function_y = editParametric->functionItem();
Ufkt *function_x = &m_view->parser()->ufkt[m_view->parser()->ixValue(function_y->id - 1)]; //get the x-function
QListWidgetItem *item;
if( x_id == -1 ) //a new function
{
item = new QListWidgetItem( function_x->fstr+";"+function_y->fstr, m_mainWidget->lb_fktliste );
}
else //change a function
{
item = m_mainWidget->lb_fktliste->currentItem();
item->setText( function_x->fstr+";"+function_y->fstr );
}
item->setCheckState( function_y->f_mode ? Qt::Checked : Qt::Unchecked );
m_mainWidget->lb_fktliste->sortItems();
changed = true;
updateView();
}
}
void FktDlg::slotEditPolar( int id )
{
KEditPolar* editPolar = new KEditPolar( m_view->parser(), this );
if ( id==-1) editPolar->setCaption(i18n( "New Polar Plot" ));
editPolar->initDialog( id );
if( editPolar->exec() == QDialog::Accepted )
{
Ufkt *function = editPolar->functionItem();
QListWidgetItem *item;
if( id == -1 ) // a new function
{
item = new QListWidgetItem( function->fstr, m_mainWidget->lb_fktliste );
}
else //change a function
{
item = m_mainWidget->lb_fktliste->currentItem();
item->setText( function->fstr );
}
item->setCheckState( function->f_mode ? Qt::Checked : Qt::Unchecked );
m_mainWidget->lb_fktliste->sortItems();
changed = true;
updateView();
}
}
void FktDlg::slotNewFunction()
{
slotEditFunction();
}
void FktDlg::slotNewParametric()
{
slotEditParametric();
}
void FktDlg::slotNewPolar()
{
slotEditPolar();
}
void FktDlg::getPlots()
{
m_mainWidget->lb_fktliste->clear();
// adding all yet added functions
for( QVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if( it->fname.isEmpty() || it->fstr[0] == 'y' ) continue;
QListWidgetItem *item;
if( it->fstr[0] == 'x' )
{
QString y = it->fstr;
++it;
item = new QListWidgetItem( y + ";" + it->fstr, m_mainWidget->lb_fktliste );
}
else
item = new QListWidgetItem( it->fstr, m_mainWidget->lb_fktliste );
item->setCheckState( it->f_mode ? Qt::Checked : Qt::Unchecked );
}
m_mainWidget->lb_fktliste->sortItems();
}
void FktDlg::slotHelp()
{
KToolInvocation::invokeHelp( "", "kmplot" );
}
bool FktDlg::isChanged()
{
return changed;
}
void FktDlg::showEvent ( QShowEvent * )
{
changed = false;
}
void FktDlg::slotCopyFunction()
{
if ( m_mainWidget->lb_fktliste->currentItem() == 0)
{
m_mainWidget->cmdCopyFunction->setEnabled(false);
return;
}
QListWidgetItem *currentItem = m_mainWidget->lb_fktliste->currentItem();
QString const fstr = currentItem->text();
m_view->parser()->sendFunction(getId(fstr));
}
void FktDlg::slotMoveFunction()
{
if ( m_mainWidget->lb_fktliste->currentItem() == 0)
{
m_mainWidget->cmdCopyFunction->setEnabled(false);
return;
}
QListWidgetItem *currentItem = m_mainWidget->lb_fktliste->currentItem();
QString const fstr = currentItem->text();
if ( !m_view->parser()->sendFunction(getId( currentItem->text()) ) )
return;
slotDelete();
}
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 1998, 1999 Klaus-Dieter M�ler
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/** @file FktDlg.h
* @brief Contains the FktDlg class. Entering and editing functions equation and attributes.
*/
#ifndef FktDlg_included
#define FktDlg_included
// locale includes
#include "FktDlgData.h"
#include "View.h"
#include <kdialog.h>
#include <QShowEvent>
class FktDlgData;
class XParser;
/** @short This widget class handles the users function input.
*
* The list of stored plots is shown. The entries can be edited and/or removed.
* New plots can be entered calling special dialog windows.
* @see KEditFunction, KEditParametric, KEditPolar
*/
class FktDlg : public KDialog
{
Q_OBJECT
public:
/**
* The constructor gets the current parser instance
* @param parent Parent widget.
* @param view points to the current view instance.
*/
FktDlg( QWidget* parent, View* view );
/// Empty destructor.
virtual ~FktDlg();
/// Fill the widgets with plots contained in the parser instance.
void getPlots();
/// Returns true if a function was changed
bool isChanged();
public slots:
/// Pressed on the "Copy Function.." button
void slotCopyFunction();
/// Pressed on the "Move Function.." button
void slotMoveFunction();
protected slots:
/// Delete selected plot
void slotDelete();
/// Edit selected Plot
void slotEdit();
/// Enables/disables actions if the list has a/no selection.
void slotHasSelection();
void lb_fktliste_doubleClicked(QListWidgetItem *);
void lb_fktliste_clicked(QListWidgetItem * item);
/// called after item is clicked on to check the check state
void checkCurrentItemCheckState();
/// Edit a function plot.
/// @param id Id of the function plot to edit
/// @see KEditFunction
void slotEditFunction( int id = -1 );
/// Edit a parametric plot.
/// @param x_id Function index to edit
/// @param y_id Function index to edit
/// @see KEditParametric
void slotEditParametric( int x_id = -1, int y_id = -1 );
/// Edit a polar plot.
/// @param id Function index of the parser instance.
/// @see KEditPolar
void slotEditPolar( int id = -1 );
/// Edit a new function plot.
void slotNewFunction();
/// Edit a new parametric plot.
void slotNewParametric();
/// Edit a new polar plot.
void slotNewPolar();
/// Invoke Help
void slotHelp();
private:
/// Looks up the id of \a f_str in the parser instance.
int getId( const QString &f_str );
/// Looks up the indices of the parametric pair of function.
int getParamId( const QString &f_str );
/// Update the view of the main window.
void updateView();
/// Called when the dialog is showed
void showEvent ( QShowEvent * );
// /// Send a function to an other instance of Kmplot. Returns true if it success, otherwise false
// bool sendFunction();
/// Ponts to the parser instance.
View* m_view;
/// indicates if a function is changed/added/removed
bool changed;
/// pointer to the main widget (FktDlgData) in this dialog
FktDlgData * m_mainWidget;
};
class FktDlgData : public QWidget, public Ui::FktDlgData
{
public:
FktDlgData( QWidget * parent = 0 )
: QWidget( parent )
{ setupUi(this); }
};
#endif // FktDlg_included
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>FktDlgData</class>