Commit 05cfd206 authored by David Saxton's avatar David Saxton

Ported Slider dialogs to Qt4 and merged into one dialog.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=522266
parent db23a409
......@@ -253,17 +253,8 @@ void MainDlg::setupActions()
m_quickEditAction = new QuickEditAction( actionCollection(), "quickedit" );
connect( m_quickEditAction, SIGNAL( completed( const QString& ) ), this, SLOT( slotQuickEdit( const QString& ) ) );
view->mnuSliders[0] = new KToggleAction( i18n( "Show Slider 1" ), actionCollection(), QString( "options_configure_show_slider_0" ).latin1() );
connect( view->mnuSliders[0], SIGNAL(triggered(bool)), this, SLOT( toggleShowSlider0() ) );
view->mnuSliders[1] = new KToggleAction( i18n( "Show Slider 2" ), actionCollection(), QString( "options_configure_show_slider_1" ).latin1() );
connect( view->mnuSliders[1], SIGNAL(triggered(bool)), this, SLOT( toggleShowSlider1() ) );
view->mnuSliders[2] = new KToggleAction( i18n( "Show Slider 3" ), actionCollection(), QString( "options_configure_show_slider_2" ).latin1() );
connect( view->mnuSliders[2], SIGNAL(triggered(bool)), this, SLOT( toggleShowSlider2() ) );
view->mnuSliders[3] = new KToggleAction( i18n( "Show Slider 4" ), actionCollection(), QString( "options_configure_show_slider_3" ).latin1() );
connect( view->mnuSliders[3], SIGNAL(triggered(bool)), this, SLOT( toggleShowSlider3() ) );
view->m_menuSliderAction = new KToggleAction( i18n( "Show Sliders" ), actionCollection(), "options_configure_show_sliders" );
connect( view->m_menuSliderAction, SIGNAL(triggered(bool)), this, SLOT( toggleShowSliders() ) );
// Popup menu
......@@ -773,39 +764,19 @@ void MainDlg::graphArea()
minmaxdlg->show();
}
void MainDlg::toggleShowSlider0()
{
toggleShowSlider(0);
}
void MainDlg::toggleShowSlider1()
{
toggleShowSlider(1);
}
void MainDlg::toggleShowSlider2()
{
toggleShowSlider(2);
}
void MainDlg::toggleShowSlider3()
{
toggleShowSlider(3);
}
void MainDlg::toggleShowSlider(int const num)
void MainDlg::toggleShowSliders()
{
// create the slider if it not exists already
if ( view->sliders[ num ] == 0 )
if ( !view->m_sliderWindow )
{
view->sliders[ num ] = new KSliderWindow( view, num, actionCollection());
connect( view->sliders[num]->slider, SIGNAL( valueChanged( int ) ), view, SLOT( drawPlot() ) );
connect( view->sliders[num], SIGNAL( windowClosed( int ) ), view, SLOT( sliderWindowClosed(int) ) );
view->m_sliderWindow = new KSliderWindow( view, actionCollection());
connect( view->m_sliderWindow, SIGNAL( valueChanged() ), view, SLOT( drawPlot() ) );
connect( view->m_sliderWindow, SIGNAL( windowClosed() ), view, SLOT( slidersWindowClosed() ) );
}
if ( !view->sliders[ num ]->isShown() )
view->sliders[ num ]->show();
if ( !view->m_sliderWindow->isShown() )
view->m_sliderWindow->show();
else
view->sliders[ num ]->hide();
view->m_sliderWindow->hide();
}
void MainDlg::setReadOnlyStatusBarText(const QString &text)
......
......@@ -109,11 +109,8 @@ public slots:
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();
/// Toggle whether the sliders window is shown
void toggleShowSliders();
// ///I'm not sure it a delete-all-functions command is necessary
// void slotCleanWindow();
......@@ -155,8 +152,6 @@ private:
void saveConstants();
/// Returns true if any changes are done
bool isModified(){return m_modified;}
/// Toggle the slider with index num
void toggleShowSlider(int const num);
/// Cached dialog to edit all functions
FktDlg *fdlg;
......
......@@ -44,10 +44,7 @@ k_dcop:
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 toggleShowSliders() = 0;
virtual void slotSave() = 0;
virtual void slotSaveas() = 0;
virtual void slotEditPlots() = 0;
......
......@@ -114,8 +114,7 @@ View::View(bool const r, bool &mo, KMenu *p, QWidget* parent, KActionCollection
invertColor(backgroundcolor,inverted_backgroundcolor);
setBackgroundColor(backgroundcolor);
setMouseTracking(TRUE);
for( int number = 0; number < SLIDER_COUNT; number++ )
sliders[ number ] = 0;
m_sliderWindow = 0;
updateSliders();
m_popupmenu->addTitle( "");
}
......@@ -316,8 +315,8 @@ void View::plotfkt(Ufkt *ufkt, QPainter *pDC)
}
else
{
if ( KSliderWindow * sw = sliders[ ufkt->use_slider ] )
ufkt->setParameter( sw->slider->value() );
if ( m_sliderWindow )
ufkt->setParameter( m_sliderWindow->value( ufkt->use_slider ) );
}
mflg=2;
......@@ -803,7 +802,10 @@ void View::mouseMoveEvent(QMouseEvent *e)
it->setParameter( it->parameters[csparam].value );
}
else
it->setParameter(sliders[ it->use_slider ]->slider->value() );
{
if ( m_sliderWindow )
it->setParameter( m_sliderWindow->value( it->use_slider ) );
}
if ( cstype == 0)
ptl.setY(dgr.TransyToPixel(csypos=m_parser->fkt( it, csxpos=dgr.TransxToReal(ptl.x()))));
......@@ -999,8 +1001,8 @@ void View::mousePressEvent(QMouseEvent *e)
}
else
{
if ( KSliderWindow * sw = sliders[ it->use_slider ] )
it->setParameter( sw->slider->value() );
if ( m_sliderWindow )
it->setParameter( m_sliderWindow->value( it->use_slider ) );
}
if ( function_type=='x' && fabs(csxpos-m_parser->fkt(it, csxpos))< g && it->fstr.contains('t')==1) //parametric plot
......@@ -1115,8 +1117,8 @@ void View::mousePressEvent(QMouseEvent *e)
}
else
{
if ( KSliderWindow * sw = sliders[ it->use_slider ] )
it->setParameter( sw->slider->value() );
if ( m_sliderWindow )
it->setParameter( m_sliderWindow->value( it->use_slider ) );
}
if(fabs(csypos-m_parser->fkt(it, csxpos))< g && it->f_mode)
......@@ -1932,29 +1934,26 @@ bool View::isCalculationStopped()
void View::updateSliders()
{
for( int number = 0; number < SLIDER_COUNT; number++)
if ( m_sliderWindow )
{
if (sliders[ number ])
{
sliders[ number ]->hide();
mnuSliders[ number ]->setChecked(false); //uncheck the slider-item in the menu
}
m_sliderWindow->hide();
m_menuSliderAction->setChecked( false ); //uncheck the slider-item in the menu
}
// do we need to show any sliders?
for(QVector<Ufkt>::iterator it=m_parser->ufkt.begin(); it!=m_parser->ufkt.end(); ++it)
{
if (it->fname.isEmpty() ) continue;
if( it->use_slider > -1 && (it->f_mode || it->f1_mode || it->f2_mode || it->integral_mode))
{
// create the slider if it not exists already
if ( sliders[ it->use_slider ] == 0 )
if ( !m_sliderWindow )
{
sliders[ it->use_slider ] = new KSliderWindow( this, it->use_slider, m_ac);
connect( sliders[ it->use_slider ]->slider, SIGNAL( valueChanged( int ) ), this, SLOT( drawPlot() ) );
connect( sliders[ it->use_slider ], SIGNAL( windowClosed( int ) ), this , SLOT( sliderWindowClosed(int) ) );
mnuSliders[ it->use_slider ]->setChecked(true); //set the slider-item in the menu
m_sliderWindow = new KSliderWindow( this, m_ac );
connect( m_sliderWindow, SIGNAL( valueChanged() ), this, SLOT( drawPlot() ) );
connect( m_sliderWindow, SIGNAL( windowClosed() ), this, SLOT( sliderWindowClosed() ) );
}
sliders[ it->use_slider ]->show();
m_sliderWindow->show();
m_menuSliderAction->setChecked( false ); //set the slider-item in the menu
}
}
}
......@@ -2293,7 +2292,7 @@ void View::increaseProgressBar()
m_dcop_client->send(m_dcop_client->appId(), "KmPlotShell","increaseProgressBar()", QByteArray());
}
void View::sliderWindowClosed(int num)
void View::slidersWindowClosed()
{
mnuSliders[num]->setChecked(false);
m_menuSliderAction->setChecked(false);
}
......@@ -108,9 +108,9 @@ public:
QString areaParameter;
/// Slider controlling parameter values
QPointer<KSliderWindow> sliders[ SLIDER_COUNT ];
QPointer<KSliderWindow> m_sliderWindow;
/// Menu actions for the sliders
KToggleAction *mnuSliders[ SLIDER_COUNT ];
KToggleAction * m_menuSliderAction;
void updateSliders(); /// show only needed sliders
/// Convert a width in mm to a suitable QPen width for drawing
......@@ -120,7 +120,7 @@ public slots:
/// Called when the user want to cancel the drawing
void stopDrawing();
/// A slider window has been closed
void sliderWindowClosed(int);
void slidersWindowClosed();
/// Called when the graph should be updated
void drawPlot();
......
<!DOCTYPE kpartgui>
<kpartgui name="kmplot" version="6">
<kpartgui name="kmplot" version="7">
<MenuBar>
<Menu name="file">
<Action name="file_openrecent"/>
......@@ -44,12 +44,7 @@
<Menu name="settings"><text>&amp;Settings</text>
<Separator />
<Separator />
<Menu name="ShowSliders"><text>Show S&amp;liders</text>
<Action name="options_configure_show_slider_0"/>
<Action name="options_configure_show_slider_1"/>
<Action name="options_configure_show_slider_2"/>
<Action name="options_configure_show_slider_3"/>
</Menu>
<Action name="options_configure_show_sliders"/>
<Separator/>
<Action name="options_configure_keybinding"/>
<Action name="options_configure_toolbars"/>
......
<!DOCTYPE kpartgui>
<kpartgui name="kmplot" version="1">
<kpartgui name="kmplot" version="2">
<MenuBar>
<Menu name="file">
<Action name="file_save_as"/>
......@@ -7,10 +7,8 @@
<Action name="export"/>
</Menu>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="editcolors"/>
<Action name="editaxes"/>
<Action name="editscaling"/>
<Action name="editfonts"/>
<Separator />
<Action name="coord_i"/>
<Action name="coord_ii"/>
......@@ -31,13 +29,8 @@
<Action name="maximumvalue"/>
<Action name="grapharea"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Menu name="ShowSliders"><text>Show S&amp;liders</text>
<Action name="options_configure_show_slider_0"/>
<Action name="options_configure_show_slider_1"/>
<Action name="options_configure_show_slider_2"/>
<Action name="options_configure_show_slider_3"/>
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="options_configure_show_sliders"/>
<Separator/>
<Action name="options_configure"/>
</Menu>
......
......@@ -38,30 +38,47 @@
#include <kinputdialog.h>
#include <klocale.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
// local includes
#include "ksliderwindow.h"
#include "xparser.h"
KSliderWindow::KSliderWindow(QWidget* parent, int num, KActionCollection *ac ) :
SliderWindow( parent, "", false, (Qt::WFlags)(Qt::WStyle_Tool-Qt::WStyle_Maximize) ), m_num(num)
KSliderWindow::KSliderWindow( QWidget * parent, KActionCollection * ac ) :
KDialog( parent, i18n("Sliders") )
{
setCaption(i18n( "Slider %1" ).arg( num+1 ) );
slider->setToolTip( i18n( "Slider no. %1" ).arg( num+1 ));
this->setWhatsThis( i18n( "Move slider to change the parameter of the function plot connected to this slider." ) );
m_clickedOnSlider = 0l;
// load the min and max value + the current value
KConfig config( "kmplotrc" );
config.setGroup( "slider" + QString::number(num) );
slider->setMinimum( config.readEntry( "min", 0) );
slider->setMaximum( config.readEntry( "max", 100) );
slider->setValue( config.readEntry( "value", 50) );
slider->setPageStep( (int)ceil((abs(slider->minValue()) + abs(slider->maxValue()))/10.) );
setModal( false );
m_mainWidget = new SliderWindow( this );
setMainWidget( m_mainWidget );
m_sliders[0] = m_mainWidget->slider0;
m_sliders[1] = m_mainWidget->slider1;
m_sliders[2] = m_mainWidget->slider2;
m_sliders[3] = m_mainWidget->slider3;
assert( SLIDER_COUNT == 4 );
slider->installEventFilter(this);
installEventFilter(this);
KConfig config( "kmplotrc" );
for ( unsigned i = 0; i < SLIDER_COUNT; ++i )
{
m_sliders[i]->setToolTip( i18n( "Slider no. %1" ).arg( i+1 ));
setWhatsThis( i18n( "Move slider to change the parameter of the function plot connected to this slider." ) );
// load the min and max value + the current value
config.setGroup( "slider" + QString::number(i) );
m_sliders[i]->setMinimum( config.readEntry( "min", 0) );
m_sliders[i]->setMaximum( config.readEntry( "max", 100) );
m_sliders[i]->setValue( config.readEntry( "value", 50) );
m_sliders[i]->setPageStep( (int)ceil((abs(m_sliders[i]->minValue()) + abs(m_sliders[i]->maxValue()))/10.) );
m_sliders[i]->installEventFilter(this);
connect( m_sliders[i], SIGNAL( valueChanged( int ) ), this, SIGNAL( valueChanged() ) );
}
m_popupmenu = new KMenu(this);
KAction *mnuMinValue = new KAction(i18n("&Change Minimum Value") ,0,this, SLOT( mnuMinValue_clicked() ),ac, "");
......@@ -74,50 +91,71 @@ KSliderWindow::~KSliderWindow()
{
// save the min and max value + the current value
KConfig config( "kmplotrc" );
config.setGroup( "slider" + QString::number(m_num) );
config.writeEntry( "min", slider->minValue() );
config.writeEntry( "max", slider->maxValue() );
config.writeEntry( "value", slider->value() );
for ( unsigned i = 0; i < SLIDER_COUNT; ++i )
{
config.setGroup( "slider" + QString::number(i) );
config.writeEntry( "min", m_sliders[i]->minValue() );
config.writeEntry( "max", m_sliders[i]->maxValue() );
config.writeEntry( "value", m_sliders[i]->value() );
}
}
int KSliderWindow::value( int slider )
{
assert( (slider>=0) && (slider < SLIDER_COUNT) );
return m_sliders[slider]->value();
}
bool KSliderWindow::eventFilter( QObject *obj, QEvent *ev )
{
if (ev->type() == QEvent::MouseButtonPress)
QMouseEvent * mouseEvent = 0l;
if ( ev->type() == QEvent::MouseButtonPress )
mouseEvent = static_cast<QMouseEvent*>(ev);
if ( mouseEvent &&
(mouseEvent->button() == Qt::RightButton) &&
(obj->metaObject()->className() == "QSlider") )
{
QMouseEvent *e = (QMouseEvent *)ev;
if (e->button() != Qt::RightButton)
return SliderWindow::eventFilter( obj, ev );
m_clickedOnSlider = static_cast<QSlider*>(obj);
m_popupmenu->exec(QCursor::pos());
return true;
}
return SliderWindow::eventFilter( obj, ev );
return KDialog::eventFilter( obj, ev );
}
void KSliderWindow::closeEvent( QCloseEvent * e)
{
emit windowClosed(m_num);
emit windowClosed();
e->accept();
}
void KSliderWindow::mnuMinValue_clicked()
{
assert( m_clickedOnSlider );
bool ok;
int const result = KInputDialog::getInteger(i18n("Change Minimum Value"), i18n("Type a new minimum value for the slider:"), slider->minValue(), INT_MIN, INT_MAX, 1, 10, &ok);
int const result = KInputDialog::getInteger(i18n("Change Minimum Value"), i18n("Type a new minimum value for the slider:"), m_clickedOnSlider->minValue(), INT_MIN, INT_MAX, 1, 10, &ok);
if (!ok)
return;
slider->setMinimum(result);
slider->setPageStep( (int)ceil((abs(slider->maxValue()) + abs(result))/10.) );
m_clickedOnSlider->setMinimum(result);
m_clickedOnSlider->setPageStep( (int)ceil((abs(m_clickedOnSlider->maxValue()) + abs(result))/10.) );
setFocus();
}
void KSliderWindow::mnuMaxValue_clicked()
{
assert( m_clickedOnSlider );
bool ok;
int const result = KInputDialog::getInteger(i18n("Change Maximum Value"), i18n("Type a new maximum value for the slider:"), slider->maxValue(), INT_MIN, INT_MAX, 1, 10, &ok);
int const result = KInputDialog::getInteger(i18n("Change Maximum Value"), i18n("Type a new maximum value for the slider:"), m_clickedOnSlider->maxValue(), INT_MIN, INT_MAX, 1, 10, &ok);
if (!ok)
return;
slider->setMaximum(result);
slider->setPageStep( (int)ceil((abs(slider->minValue()) + abs(result))/10.) );
m_clickedOnSlider->setMaximum(result);
m_clickedOnSlider->setPageStep( (int)ceil((abs(m_clickedOnSlider->minValue()) + abs(result))/10.) );
setFocus();
}
......
......@@ -33,16 +33,20 @@
#include <QEvent>
#include <QCloseEvent>
class SliderWindow;
/** @short Slider window for changing a parameter value */
class KSliderWindow : public SliderWindow
class KSliderWindow : public KDialog
{
Q_OBJECT
public:
/// @param parent points to the parent widget.
/// @param num number of this instance.
/// @param ac KActionCollection to add KActions
KSliderWindow(QWidget* parent, int num, KActionCollection *ac );
KSliderWindow(QWidget* parent, KActionCollection *ac );
virtual ~KSliderWindow();
int value( int slider );
private slots:
void mnuMinValue_clicked();
......@@ -50,13 +54,29 @@ class KSliderWindow : public SliderWindow
signals:
/// emitted when the window has been closed
void windowClosed(int);
void windowClosed();
/// emitted when a slider value changes
void valueChanged();
private:
bool eventFilter( QObject *obj, QEvent *ev );
void closeEvent( QCloseEvent * );
KMenu *m_popupmenu;
int m_num;
KMenu * m_popupmenu;
QSlider * m_sliders[4];
SliderWindow * m_mainWidget;
/// this is set to the clicked-on slider when right-clicking on a slider
QSlider * m_clickedOnSlider;
};
class SliderWindow : public QWidget, public Ui::SliderWindow
{
public:
SliderWindow( QWidget * parent = 0 )
: QWidget( parent )
{ setupUi(this); }
};
#endif
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>SliderWindow</class>
<widget class="QDialog">
<property name="name">
<cstring>SliderWindow</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>273</width>
<height>51</height>
</rect>
</property>
<property name="windowTitle">
<string>Slider</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QSlider" row="0" column="0">
<property name="name">
<cstring>slider</cstring>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="cursor">
<cursor>13</cursor>
</property>
<property name="focusPolicy">
<enum>StrongFocus</enum>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="tickmarks">
<enum>Below</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
<widget class="QLabel" row="0" column="1">
<property name="name">
<cstring>value</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>45</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>AlignVCenter|AlignRight</set>
</property>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>slider</sender>
<signal>valueChanged(int)</signal>
<receiver>value</receiver>
<slot>setNum(int)</slot>
</connection>
</connections>
<layoutdefaults spacing="6" margin="11"/>
</UI>
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>SliderWindow</class>
<widget class="QWidget" name="SliderWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>138</height>
</rect>
</property>
<property name="windowTitle" >
<string>Slider</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="QSlider" name="slider0" >
<property name="minimumSize" >
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="cursor" >