[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Thu Jun 7 19:25:36 CEST 2007
SVN commit 672618 by treat:
* Provide a context menu and three new item
based actions/commands: remove, z-order up, z-order down
M +65 -0 viewitem.cpp
M +53 -3 viewitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #672617:672618
@@ -13,8 +13,10 @@
#include "kstapplication.h"
#include "tabwidget.h"
+#include <QMenu>
#include <QDebug>
#include <QGraphicsScene>
+#include <QGraphicsSceneContextMenuEvent>
namespace Kst {
@@ -40,6 +42,24 @@
}
+void ViewItem::removeItem() {
+ RemoveCommand *remove = new RemoveCommand(this);
+ remove->redo();
+}
+
+
+void ViewItem::zOrderUp() {
+ ZOrderUpCommand *up = new ZOrderUpCommand(this);
+ up->redo();
+}
+
+
+void ViewItem::zOrderDown() {
+ ZOrderDownCommand *down = new ZOrderDownCommand(this);
+ down->redo();
+}
+
+
void ViewItem::creationPolygonChanged(View::CreationEvent event) {
if (event == View::MousePress) {
const QPolygonF poly = mapFromScene(parentView()->creationPolygon(View::MousePress));
@@ -71,6 +91,22 @@
}
+void ViewItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
+ QMenu menu;
+
+ QAction *removeAction = menu.addAction(tr("Remove Object"));
+ connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));
+
+ QAction *zUpAction = menu.addAction(tr("Z Order Up"));
+ connect(zUpAction, SIGNAL(triggered()), this, SLOT(zOrderUp()));
+
+ QAction *zDownAction = menu.addAction(tr("Z Order Down"));
+ connect(zDownAction, SIGNAL(triggered()), this, SLOT(zOrderDown()));
+
+ menu.exec(event->screenPos());
+}
+
+
void ViewItem::mouseModeChanged() {
if (parentView()->mouseMode() == View::Move)
_originalPosition = pos();
@@ -140,8 +176,37 @@
}
+void RemoveCommand::undo() {
+ _item->show();
}
+
+void RemoveCommand::redo() {
+ _item->hide();
+}
+
+
+void ZOrderUpCommand::undo() {
+ _item->setZValue(_item->zValue() - 1);
+}
+
+
+void ZOrderUpCommand::redo() {
+ _item->setZValue(_item->zValue() + 1);
+}
+
+
+void ZOrderDownCommand::undo() {
+ _item->setZValue(_item->zValue() +1);
+}
+
+
+void ZOrderDownCommand::redo() {
+ _item->setZValue(_item->zValue() - 1);
+}
+
+}
+
#include "viewitem.moc"
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #672617:672618
@@ -19,7 +19,7 @@
#include "viewcommand.h"
#include "view.h" //forward declare, but enums??
-#define DEBUG_GEOMETRY 1
+// #define DEBUG_GEOMETRY 1
namespace Kst {
@@ -35,9 +35,17 @@
Q_SIGNALS:
void creationComplete();
+public Q_SLOTS:
+ void removeItem();
+ void zOrderUp();
+ void zOrderDown();
+
protected Q_SLOTS:
virtual void creationPolygonChanged(View::CreationEvent event);
+protected:
+ virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+
private Q_SLOTS:
void mouseModeChanged();
@@ -80,11 +88,11 @@
{
public:
MoveCommand(QPointF originalPos, QPointF newPos)
- : ViewItemCommand(QObject::tr("Move Object")),
+ : ViewItemCommand(QObject::tr("Move Item")),
_originalPos(originalPos),
_newPos(newPos) {}
MoveCommand(ViewItem *item, QPointF originalPos, QPointF newPos)
- : ViewItemCommand(item, QObject::tr("Move Object")),
+ : ViewItemCommand(item, QObject::tr("Move Item")),
_originalPos(originalPos),
_newPos(newPos) {}
@@ -98,6 +106,48 @@
QPointF _newPos;
};
+class KST_EXPORT RemoveCommand : public ViewItemCommand
+{
+public:
+ RemoveCommand()
+ : ViewItemCommand(QObject::tr("Remove Item")) {}
+ RemoveCommand(ViewItem *item)
+ : ViewItemCommand(item, QObject::tr("Remove Item")) {}
+
+ virtual ~RemoveCommand() {}
+
+ virtual void undo();
+ virtual void redo();
+};
+
+class KST_EXPORT ZOrderUpCommand : public ViewItemCommand
+{
+public:
+ ZOrderUpCommand()
+ : ViewItemCommand(QObject::tr("Z-Order Up")) {}
+ ZOrderUpCommand(ViewItem *item)
+ : ViewItemCommand(item, QObject::tr("Z-Order Up")) {}
+
+ virtual ~ZOrderUpCommand() {}
+
+ virtual void undo();
+ virtual void redo();
+};
+
+class KST_EXPORT ZOrderDownCommand : public ViewItemCommand
+{
+public:
+ ZOrderDownCommand()
+ : ViewItemCommand(QObject::tr("Z-Order Down")) {}
+ ZOrderDownCommand(ViewItem *item)
+ : ViewItemCommand(item, QObject::tr("Z-Order Down")) {}
+
+ virtual ~ZOrderDownCommand() {}
+
+ virtual void undo();
+ virtual void redo();
+};
+
}
#endif
More information about the Kst
mailing list