Commit 56aa49d5 authored by David Saxton's avatar David Saxton

Improvements to the parameter list editor:

- Given icons to buttons.
- Added "move up" and "move down" actions to change ordering of parameters.
- Allow scrolling through the parameters with up/down keys.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=651733
parent e4c9ec32
......@@ -481,6 +481,13 @@ void EquationEditWidget::keyPressEvent( QKeyEvent * e )
}
else
{
// Still pass these keys to QTextEdit, in case the user has to scroll
// up/down the text
if ( e->key() == Qt::Key_Up )
emit m_parent->upPressed();
else if ( e->key() == Qt::Key_Down )
emit m_parent->downPressed();
QTextEdit::keyPressEvent( e );
}
}
......
......@@ -143,6 +143,8 @@ class EquationEdit : public QWidget
void textEdited( const QString & text );
void textChanged( const QString & text );
void returnPressed();
void upPressed();
void downPressed();
public Q_SLOTS:
void setText( const QString & text );
......
......@@ -26,6 +26,7 @@
#include <kdebug.h>
#include <kfiledialog.h>
#include <KIcon>
#include <kinputdialog.h>
#include <kio/netaccess.h>
#include <klocale.h>
......@@ -52,16 +53,28 @@ KParameterEditor::KParameterEditor( QList<Value> *l, QWidget *parent )
setButtons( Ok | Cancel );
m_mainWidget = new QParameterEditor( this );
m_mainWidget->layout()->setMargin( 0 );
setMainWidget( m_mainWidget );
setCaption( i18n("Parameter Editor") );
setButtons( Ok|Cancel );
m_mainWidget->cmdNew->setIcon( KIcon("document-new" ) );
m_mainWidget->cmdDelete->setIcon( KIcon("edit-delete" ) );
m_mainWidget->moveUp->setIcon( KIcon("go-up") );
m_mainWidget->moveDown->setIcon( KIcon("go-down") );
m_mainWidget->cmdImport->setIcon( KIcon("document-open") );
m_mainWidget->cmdExport->setIcon( KIcon("document-save") );
m_mainWidget->list->setFocusPolicy( Qt::NoFocus );
connect( m_mainWidget->value, SIGNAL(upPressed()), this, SLOT(prev()) );
connect( m_mainWidget->value, SIGNAL(downPressed()), this, SLOT(next()) );
foreach ( const Value &v, *m_parameter )
m_mainWidget->list->addItem( v.expression() );
connect( m_mainWidget->cmdNew, SIGNAL( clicked() ), this, SLOT( cmdNew_clicked() ));
connect( m_mainWidget->cmdDelete, SIGNAL( clicked() ), this, SLOT( cmdDelete_clicked() ));
connect( m_mainWidget->moveUp, SIGNAL(clicked()), this, SLOT(moveUp()) );
connect( m_mainWidget->moveDown, SIGNAL(clicked()), this, SLOT(moveDown()) );
connect( m_mainWidget->cmdImport, SIGNAL( clicked() ), this, SLOT( cmdImport_clicked() ));
connect( m_mainWidget->cmdExport, SIGNAL( clicked() ), this, SLOT( cmdExport_clicked() ));
connect( m_mainWidget->list, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem * )), this, SLOT(selectedConstantChanged( QListWidgetItem * )) );
......@@ -100,11 +113,55 @@ void KParameterEditor::accept()
}
void KParameterEditor::moveUp()
{
int current = m_mainWidget->list->currentRow();
if ( current == 0 )
return;
QListWidgetItem * item = m_mainWidget->list->takeItem( current-1 );
m_mainWidget->list->insertItem( current, item );
}
void KParameterEditor::moveDown()
{
int current = m_mainWidget->list->currentRow();
if ( current == m_mainWidget->list->count() - 1 )
return;
QListWidgetItem * item = m_mainWidget->list->takeItem( current+1 );
m_mainWidget->list->insertItem( current, item );
}
void KParameterEditor::cmdNew_clicked()
{
QListWidgetItem * item = new QListWidgetItem( m_mainWidget->list );
item->setText( "0" );
m_mainWidget->list->setCurrentItem( item );
m_mainWidget->value->setFocus();
m_mainWidget->value->selectAll();
}
void KParameterEditor::prev()
{
int current = m_mainWidget->list->currentRow();
if ( current > 0 )
m_mainWidget->list->setCurrentRow( current-1 );
}
void KParameterEditor::next()
{
int current = m_mainWidget->list->currentRow();
if ( current < m_mainWidget->list->count()-1 )
m_mainWidget->list->setCurrentRow( current+1 );
else
cmdNew_clicked();
}
......@@ -112,6 +169,7 @@ void KParameterEditor::selectedConstantChanged( QListWidgetItem * current )
{
m_mainWidget->cmdDelete->setEnabled( current != 0 );
m_mainWidget->value->setText( current ? current->text() : QString::null );
m_mainWidget->value->selectAll();
}
......
......@@ -47,6 +47,10 @@ public:
~KParameterEditor();
public slots:
void moveUp();
void moveDown();
void prev();
void next();
void cmdNew_clicked();
void cmdDelete_clicked();
void cmdImport_clicked();
......
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>QParameterEditor</class>
<widget class="QWidget" name="QParameterEditor" >
<property name="geometry" >
......@@ -9,19 +6,16 @@
<x>0</x>
<y>0</y>
<width>381</width>
<height>482</height>
<height>488</height>
</rect>
</property>
<property name="windowTitle" >
<string>Parameter Editor</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="EquationEdit" name="value" />
</item>
<item row="0" column="1" >
<widget class="QLabel" name="valueInvalidLabel" >
<property name="toolTip" >
......@@ -32,8 +26,12 @@
</property>
</widget>
</item>
<item rowspan="6" row="1" column="0" >
<widget class="QListWidget" name="list" />
<item rowspan="9" row="1" column="0" >
<widget class="QListWidget" name="list" >
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KPushButton" name="cmdNew" >
......@@ -81,6 +79,36 @@
</spacer>
</item>
<item row="4" column="1" >
<widget class="QPushButton" name="moveUp" >
<property name="text" >
<string>Move Up</string>
</property>
</widget>
</item>
<item row="5" column="1" >
<widget class="QPushButton" name="moveDown" >
<property name="text" >
<string>Move Down</string>
</property>
</widget>
</item>
<item row="6" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" >
<size>
<width>51</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1" >
<widget class="KPushButton" name="cmdImport" >
<property name="enabled" >
<bool>true</bool>
......@@ -96,7 +124,7 @@
</property>
</widget>
</item>
<item row="5" column="1" >
<item row="8" column="1" >
<widget class="KPushButton" name="cmdExport" >
<property name="enabled" >
<bool>true</bool>
......@@ -112,46 +140,31 @@
</property>
</widget>
</item>
<item row="6" column="1" >
<item row="9" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>71</width>
<height>281</height>
<width>102</width>
<height>121</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<widget class="EquationEdit" name="value" />
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>EquationEdit</class>
<extends>KLineEdit</extends>
<header>equationedit.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends></extends>
<header>klineedit.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends></extends>
<header>kpushbutton.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
</customwidgets>
<resources/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment