[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Fri May 25 20:54:50 CEST 2007
SVN commit 668263 by treat:
* Employ a new strategy for drawing item creation
M +22 -10 kstplotitems.cpp
M +3 -2 kstplotitems.h
M +38 -25 kstplotview.cpp
M +13 -6 kstplotview.h
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.cpp #668262:668263
@@ -10,7 +10,6 @@
***************************************************************************/
#include "kstplotitems.h"
-#include "kstplotview.h"
#include <assert.h>
@@ -76,9 +75,9 @@
LineItem::LineItem(KstPlotView *parent)
: KstPlotItem(parent) {
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
- parent->setMouseMode(KstPlotView::CreateClosedPath);
- connect(parent, SIGNAL(creationPolygonChanged()),
- this, SLOT(creationPolygonChanged()));
+ parent->setMouseMode(KstPlotView::Create);
+ connect(parent, SIGNAL(creationPolygonChanged(KstPlotView::CreationEvent)),
+ this, SLOT(creationPolygonChanged(KstPlotView::CreationEvent)));
}
@@ -86,15 +85,28 @@
}
-void LineItem::creationPolygonChanged() {
- const QPolygonF poly = mapFromScene(parentView()->creationPolygon());
- if (poly.count() > 1) {
- setLine(QLineF(poly[0], poly[1]));
+void LineItem::creationPolygonChanged(KstPlotView::CreationEvent event) {
+ if (event == KstPlotView::MousePress) {
+ const QPolygonF poly = mapFromScene(parentView()->creationPolygon(KstPlotView::MousePress));
+ setLine(QLineF(poly[0], poly[0])); //start and end
parentView()->scene()->addItem(this);
- parentView()->setMouseMode(KstPlotView::Default);
- parentView()->disconnect(this, SLOT(creationPolygonChanged()));
setZValue(1);
+ return;
+ }
+
+ if (event == KstPlotView::MouseMove) {
+ const QPolygonF poly = mapFromScene(parentView()->creationPolygon(KstPlotView::MouseMove));
+ setLine(QLineF(line().p1(), poly.last())); //start and end
+ return;
+ }
+
+ if (event == KstPlotView::MouseRelease) {
+ const QPolygonF poly = mapFromScene(parentView()->creationPolygon(KstPlotView::MouseRelease));
+ setLine(QLineF(line().p1(), poly.last())); //start and end
updateAspectFromGeometry();
+ parentView()->setMouseMode(KstPlotView::Default);
+ parentView()->disconnect(this, SLOT(creationPolygonChanged(KstPlotView::CreationEvent)));
+ return;
}
}
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.h #668262:668263
@@ -18,8 +18,9 @@
#include "kst_export.h"
+#include "kstplotview.h" //forward declare, but enums??
+
class QGraphicsItem;
-class KstPlotView;
class KST_EXPORT KstPlotItem : public QObject
{
@@ -61,7 +62,7 @@
virtual QGraphicsItem *graphicsItem() { return this; }
private Q_SLOTS:
- void creationPolygonChanged();
+ void creationPolygonChanged(KstPlotView::CreationEvent event);
};
#endif
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.cpp #668262:668263
@@ -52,50 +52,63 @@
void KstPlotView::setMouseMode(MouseMode mode) {
- if (isMouseCreateMode()) {
- _creationPolygon.clear();
+ if (_mouseMode == Create) {
+ _creationPolygonPress.clear();
+ _creationPolygonRelease.clear();
+ _creationPolygonMove.clear();
}
_mouseMode = mode;
}
-bool KstPlotView::isMouseCreateMode() const {
- switch (_mouseMode) {
- case CreateRubberBand:
- case CreateClosedPath:
- case CreateOpenPath:
- case CreatePoints:
- return true;
- case Default:
- case Move:
- default:
- return false;
- }
+QPolygonF KstPlotView::creationPolygon(CreationEvents events) const {
+#if 0
+ QPolygonF resultSet;
+ if (events & KstPlotView::MousePress)
+ resultSet = resultSet.united(_creationPolygonPress);
+ if (events & KstPlotView::MouseRelease)
+ resultSet = resultSet.united(_creationPolygonRelease);
+ if (events & KstPlotView::MouseMove)
+ resultSet = resultSet.united(_creationPolygonMove);
+ return resultSet;
+#endif
+ if (events == KstPlotView::MousePress)
+ return _creationPolygonPress;
+ if (events == KstPlotView::MouseRelease)
+ return _creationPolygonRelease;
+ if (events == KstPlotView::MouseMove)
+ return _creationPolygonMove;
+ return QPolygonF();
}
-QPolygonF KstPlotView::creationPolygon() const {
- return _creationPolygon;
-}
-
-
bool KstPlotView::eventFilter(QObject *obj, QEvent *event) {
- if (obj != scene())
+ if (obj != scene() || _mouseMode != Create)
return QGraphicsView::eventFilter(obj, event);
switch (event->type()) {
case QEvent::GraphicsSceneMousePress:
{
QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
- if (isMouseCreateMode()) {
- _creationPolygon << e->buttonDownScenePos(Qt::LeftButton);
- emit creationPolygonChanged();
- return false;
- }
+ _creationPolygonPress << e->buttonDownScenePos(Qt::LeftButton);
+ emit creationPolygonChanged(MousePress);
+ return false;
}
case QEvent::GraphicsSceneMouseRelease:
+ {
+ QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
+ _creationPolygonRelease << e->scenePos();
+ emit creationPolygonChanged(MouseRelease);
+ return false;
+ }
case QEvent::GraphicsSceneMouseMove:
+ {
+ QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
+ _creationPolygonMove << e->scenePos();
+ emit creationPolygonChanged(MouseMove);
+ return false;
+ }
default:
return QGraphicsView::eventFilter(obj, event);
}
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.h #668262:668263
@@ -23,7 +23,14 @@
{
Q_OBJECT
public:
- enum MouseMode { Default, Move, CreateRubberBand, CreateClosedPath, CreateOpenPath, CreatePoints };
+ enum MouseMode { Default, Move, Create };
+ enum CreationEvent {
+ MousePress = 0x0,
+ MouseRelease =0x1,
+ MouseMove = 0x2
+ };
+ Q_DECLARE_FLAGS(CreationEvents, CreationEvent)
+
KstPlotView();
virtual ~KstPlotView();
@@ -33,12 +40,10 @@
MouseMode mouseMode() const;
void setMouseMode(MouseMode mode);
- bool isMouseCreateMode() const;
+ QPolygonF creationPolygon(CreationEvents events) const;
- QPolygonF creationPolygon() const;
-
Q_SIGNALS:
- void creationPolygonChanged();
+ void creationPolygonChanged(KstPlotView::CreationEvent event);
void resized();
protected:
@@ -49,7 +54,9 @@
QUndoStack *_undoStack;
KstPlotItem *_currentPlotItem;
MouseMode _mouseMode;
- QPolygonF _creationPolygon;
+ QPolygonF _creationPolygonPress;
+ QPolygonF _creationPolygonMove;
+ QPolygonF _creationPolygonRelease;
};
#endif
More information about the Kst
mailing list