Commit 6489fa60 authored by Thomas Zander's avatar Thomas Zander

* make the object respond directly to spinbox changes, not only when loosing focus.

* Group move commands in one undo.
* Honor locked state of a shape.
* cleanup the ui file

svn path=/trunk/koffice/; revision=743755
parent d941a3c8
......@@ -35,7 +35,8 @@
#include <QtGui/QLabel>
DefaultToolWidget::DefaultToolWidget( KoInteractionTool* tool,
QWidget* parent ) : QTabWidget( parent )
QWidget* parent ) : QTabWidget( parent ),
m_moveCommand(0)
{
m_tool = tool;
......@@ -45,15 +46,14 @@ DefaultToolWidget::DefaultToolWidget( KoInteractionTool* tool,
connect( positionSelector, SIGNAL( positionSelected(KoFlake::Position) ), this, SLOT( updatePosition() ) );
connect( positionXSpinBox, SIGNAL( editingFinished() ), this, SLOT( positionHasChanged() ) );
connect( positionYSpinBox, SIGNAL( editingFinished() ), this, SLOT( positionHasChanged() ) );
connect( positionXSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( positionHasChanged() ) );
connect( positionYSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( positionHasChanged() ) );
connect( widthSpinBox, SIGNAL( editingFinished() ), this, SLOT( sizeHasChanged() ) );
connect( heightSpinBox, SIGNAL( editingFinished() ), this, SLOT( sizeHasChanged() ) );
KoSelection * selection = m_tool->canvas()->shapeManager()->selection();
connect( selection, SIGNAL( selectionChanged() ), this, SLOT( updatePosition() ) );
connect( selection, SIGNAL( selectionChanged() ), this, SLOT( updateSize() ) );
connect( selection, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
KoShapeManager * manager = m_tool->canvas()->shapeManager();
connect( manager, SIGNAL( selectionContentChanged() ), this, SLOT( updatePosition() ) );
connect( manager, SIGNAL( selectionContentChanged() ), this, SLOT( updateSize() ) );
......@@ -84,11 +84,11 @@ void DefaultToolWidget::updatePosition()
KoFlake::Position position = positionSelector->position();
KoSelection * selection = m_tool->canvas()->shapeManager()->selection();
if( selection->count() )
if( m_shapesToModify.count() )
selPosition = selection->absolutePosition( position );
positionXSpinBox->setEnabled( selection->count() );
positionYSpinBox->setEnabled( selection->count() );
positionXSpinBox->setEnabled( m_shapesToModify.count() );
positionYSpinBox->setEnabled( m_shapesToModify.count() );
positionXSpinBox->blockSignals(true);
positionYSpinBox->blockSignals(true);
......@@ -103,7 +103,7 @@ void DefaultToolWidget::updatePosition()
void DefaultToolWidget::positionHasChanged()
{
KoSelection * selection = m_tool->canvas()->shapeManager()->selection();
if( ! selection->count() )
if( ! m_shapesToModify.count() )
return;
KoFlake::Position position = positionSelector->position();
......@@ -112,25 +112,46 @@ void DefaultToolWidget::positionHasChanged()
if( oldPos == newPos )
return;
QList<KoShape*> selectedShapes = selection->selectedShapes( KoFlake::TopLevelSelection );
QPointF moveBy = newPos - oldPos;
QList<QPointF> oldPositions;
QList<QPointF> newPositions;
foreach( KoShape* shape, selectedShapes )
foreach( KoShape* shape, m_shapesToModify )
{
oldPositions.append( shape->position() );
newPositions.append( shape->position() + moveBy );
}
selection->setPosition( selection->position() + moveBy );
m_tool->canvas()->addCommand( new KoShapeMoveCommand( selectedShapes, oldPositions, newPositions ) );
QTime now = QTime::currentTime();
if (m_moveCommand ==0 || now > m_commandExpire) {
m_moveCommand = new KoShapeMoveCommand( m_shapesToModify, oldPositions, newPositions );
m_tool->canvas()->addCommand( m_moveCommand );
}
else {
m_moveCommand->setNewPositions(newPositions);
m_moveCommand->redo();
}
m_commandExpire = now.addMSecs(4000);
updatePosition();
}
void DefaultToolWidget::selectionChanged()
{
m_moveCommand = 0;
m_shapesToModify.clear();
KoSelection * selection = m_tool->canvas()->shapeManager()->selection();
foreach(KoShape *shape, selection->selectedShapes( KoFlake::TopLevelSelection) ) {
if (shape->isEditable())
m_shapesToModify.append(shape);
}
updatePosition();
updateSize();
}
void DefaultToolWidget::updateSize()
{
QSizeF selSize( 0, 0 );
KoSelection * selection = m_tool->canvas()->shapeManager()->selection();
uint selectionCount = selection->count();
uint selectionCount = m_shapesToModify.count();
if( selectionCount )
selSize = selection->boundingRect().size();
......@@ -169,12 +190,11 @@ void DefaultToolWidget::sizeHasChanged()
resizeMatrix.scale( newSize.width() / rect.width(), newSize.height() / rect.height() );
resizeMatrix.translate( -rect.x(), -rect.y() );
QList<KoShape*> selectedShapes = selection->selectedShapes( KoFlake::TopLevelSelection );
QList<QSizeF> oldSizes, newSizes;
QList<QMatrix> oldState;
QList<QMatrix> newState;
foreach( KoShape* shape, selectedShapes )
foreach( KoShape* shape, m_shapesToModify )
{
QSizeF oldSize = shape->size();
oldState << shape->transformation();
......@@ -201,8 +221,8 @@ void DefaultToolWidget::sizeHasChanged()
m_tool->repaintDecorations();
selection->applyAbsoluteTransformation( resizeMatrix );
QUndoCommand * cmd = new QUndoCommand(i18n("Resize"));
new KoShapeSizeCommand( selectedShapes, oldSizes, newSizes, cmd );
new KoShapeTransformCommand( selectedShapes, oldState, newState, cmd );
new KoShapeSizeCommand( m_shapesToModify, oldSizes, newSizes, cmd );
new KoShapeTransformCommand( m_shapesToModify, oldState, newState, cmd );
m_tool->canvas()->addCommand( cmd );
updateSize();
updatePosition();
......@@ -218,7 +238,7 @@ void DefaultToolWidget::setUnit( const KoUnit &unit )
heightSpinBox->setUnit( unit );
}
void DefaultToolWidget::resourceChanged( int key, const QVariant & res )
void DefaultToolWidget::resourceChanged( int key, const QVariant &)
{
if( key == KoCanvasResource::Unit )
setUnit( m_tool->canvas()->unit() );
......
......@@ -24,9 +24,13 @@
#include <KoFlake.h>
#include <QTabWidget>
#include <QTime>
#include <QList>
class KoInteractionTool;
class QRadioButton;
class KoShapeMoveCommand;
class KoShape;
class DefaultToolWidget : public QTabWidget, Ui::DefaultToolWidget {
Q_OBJECT
......@@ -45,9 +49,13 @@ private slots:
void updateSize();
void sizeHasChanged();
void resourceChanged( int key, const QVariant & res );
void selectionChanged();
private:
KoInteractionTool* m_tool;
KoShapeMoveCommand *m_moveCommand;
QTime m_commandExpire;
QList<KoShape *> m_shapesToModify;
};
#endif
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