[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Fri Jun 8 23:14:16 CEST 2007
SVN commit 673059 by treat:
* Make rotate commands for undo/redo
M +14 -10 viewitem.cpp
M +32 -7 viewitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #673058:673059
@@ -135,6 +135,9 @@
} else if (mouseMode() == ViewItem::Resize) {
parentView()->setMouseMode(View::Resize);
parentView()->undoStack()->beginMacro(tr("Resize"));
+ } else if (mouseMode() == ViewItem::Rotate) {
+ parentView()->setMouseMode(View::Rotate);
+ parentView()->undoStack()->beginMacro(tr("Rotate"));
}
}
@@ -279,14 +282,13 @@
qreal angle = normal.angle(rotated);
angle = (clockWise ? angle : -angle);
- QTransform t = transform();
-
+ QTransform t;
t.translate(origin.x(), origin.y());
t.rotate(angle);
t.translate(-origin.x(), -origin.y());
// qDebug() << "rotateTowards" << corner << point << angle << endl;
- setTransform(t, false);
+ setTransform(t, true);
}
@@ -382,22 +384,26 @@
void ViewItem::keyPressEvent(QKeyEvent *event) {
QGraphicsRectItem::keyPressEvent(event);
- if (_mouseMode == ViewItem::Resize && event->modifiers() & Qt::ShiftModifier)
+ if (_mouseMode == ViewItem::Resize && event->modifiers() & Qt::ShiftModifier) {
setMouseMode(ViewItem::Rotate);
- else if (_mouseMode == ViewItem::Rotate && event->modifiers() & Qt::ShiftModifier)
+ } else if (_mouseMode == ViewItem::Rotate && event->modifiers() & Qt::ShiftModifier) {
setMouseMode(ViewItem::Resize);
+ }
}
void ViewItem::viewMouseModeChanged(View::MouseMode oldMode) {
if (parentView()->mouseMode() == View::Move) {
_originalPosition = pos();
- } else if (parentView()->mouseMode() == View::Resize) {
+ } else if (parentView()->mouseMode() == View::Resize ||
+ parentView()->mouseMode() == View::Rotate) {
_originalTransform = transform();
} else if (oldMode == View::Move) {
new MoveCommand(this, _originalPosition, pos());
} else if (oldMode == View::Resize) {
new ResizeCommand(this, _originalTransform, transform());
+ } else if (oldMode == View::Rotate) {
+ new RotateCommand(this, _originalTransform, transform());
}
}
@@ -510,14 +516,12 @@
}
-void ResizeCommand::undo() {
- /*FIXME Not combining this transform with previous ... undoes to much.
- * OTOH, combining it means we don't really undo...*/
+void TransformCommand::undo() {
_item->setTransform(_originalTransform);
}
-void ResizeCommand::redo() {
+void TransformCommand::redo() {
_item->setTransform(_newTransform);
}
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #673058:673059
@@ -172,18 +172,19 @@
virtual void redo();
};
-class KST_EXPORT ResizeCommand : public ViewItemCommand
+class KST_EXPORT TransformCommand : public ViewItemCommand
{
public:
- ResizeCommand(const QTransform &originalTransform, const QTransform &newTransform)
- : ViewItemCommand(QObject::tr("Resize")),
- _originalTransform(originalTransform), _newTransform(newTransform) {}
+ TransformCommand(const QTransform &originalTransform, const QTransform &newTransform,
+ const QString &text)
+ : ViewItemCommand(text), _originalTransform(originalTransform), _newTransform(newTransform) {}
- ResizeCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
- : ViewItemCommand(item, QObject::tr("Resize")),
+ TransformCommand(ViewItem *item, const QTransform &originalTransform,
+ const QTransform &newTransform, const QString &text)
+ : ViewItemCommand(item, text),
_originalTransform(originalTransform), _newTransform(newTransform) {}
- virtual ~ResizeCommand() {}
+ virtual ~TransformCommand() {}
virtual void undo();
virtual void redo();
@@ -193,6 +194,30 @@
QTransform _newTransform;
};
+class KST_EXPORT ResizeCommand : public TransformCommand
+{
+public:
+ ResizeCommand(const QTransform &originalTransform, const QTransform &newTransform)
+ : TransformCommand(originalTransform, newTransform, QObject::tr("Resize")) {}
+
+ ResizeCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
+ : TransformCommand(item, originalTransform, newTransform, QObject::tr("Resize")) {}
+
+ virtual ~ResizeCommand() {}
+};
+
+class KST_EXPORT RotateCommand : public TransformCommand
+{
+public:
+ RotateCommand(const QTransform &originalTransform, const QTransform &newTransform)
+ : TransformCommand(originalTransform, newTransform, QObject::tr("Rotate")) {}
+
+ RotateCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
+ : TransformCommand(item, originalTransform, newTransform, QObject::tr("Rotate")) {}
+
+ virtual ~RotateCommand() {}
+};
+
}
#endif
More information about the Kst
mailing list