[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Thu Sep 6 19:09:21 CEST 2007


SVN commit 709158 by treat:

* Create a data/layout mode for views.
* When in layout mode, you can manipulate the viewobjects
* When in data mode, you can do zoom, etc.
* Adjust the render items so you can now select the parent
  plotitem when in layout mode as you'd expect.



 M  +17 -1     vectorcurverenderitem.cpp  
 M  +14 -1     view.cpp  
 M  +6 -0      view.h  
 M  +19 -0     viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.cpp #709157:709158
@@ -11,6 +11,8 @@
 
 #include "vectorcurverenderitem.h"
 
+#include "plotitem.h"
+
 #include <QDebug>
 #include <QGraphicsSceneMouseEvent>
 
@@ -98,18 +100,32 @@
 
 
 void VectorCurveRenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+  if (plotItem()->parentView()->viewMode() != View::Data) {
+    event->ignore();
+    return;
+  }
+
   _selectionRect.setBottomRight(event->pos());
   update(_selectionRect);
 }
 
 
 void VectorCurveRenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+  if (plotItem()->parentView()->viewMode() != View::Data) {
+    event->ignore();
+    return;
+  }
+
   _selectionRect = QRectF(event->pos(), QSizeF(0,0));
 }
 
 
 void VectorCurveRenderItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
-  Q_UNUSED(event);
+  if (plotItem()->parentView()->viewMode() != View::Data) {
+    event->ignore();
+    return;
+  }
+
   _selectionRect = QRectF();
   update();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #709157:709158
@@ -31,6 +31,7 @@
 View::View()
   : QGraphicsView(kstApp->mainWindow()),
     _currentViewItem(0),
+    _viewMode(Layout),
     _mouseMode(Default),
     _layoutBoxItem(0),
     _gridSpacing(QSizeF(20,20)),
@@ -63,6 +64,18 @@
 }
 
 
+View::ViewMode View::viewMode() const {
+  return _viewMode;
+}
+
+
+void View::setViewMode(ViewMode mode) {
+  ViewMode oldMode = _viewMode;
+  _viewMode = mode;
+  emit viewModeChanged(oldMode);
+}
+
+
 View::MouseMode View::mouseMode() const {
   return _mouseMode;
 }
@@ -71,7 +84,7 @@
 void View::setMouseMode(MouseMode mode) {
 
   //Clear the creation polygons if we're currently
-  //in Create mode.
+  //in Create mouse mode.
   MouseMode oldMode = _mouseMode;
 
   if (oldMode == Create) {
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #709157:709158
@@ -24,6 +24,7 @@
 {
   Q_OBJECT
 public:
+  enum ViewMode { Data, Layout };
   enum MouseMode { Default, Move, Create, Resize, Scale, Rotate };
   enum CreationEvent {
     MousePress = 0x0,
@@ -38,6 +39,9 @@
   QUndoStack *undoStack() const;
   ViewItem* currentViewItem() const;
 
+  ViewMode viewMode() const;
+  void setViewMode(ViewMode mode);
+
   MouseMode mouseMode() const;
   void setMouseMode(MouseMode mode);
 
@@ -67,6 +71,7 @@
   QPointF snapPoint(const QPointF &point);
 
 Q_SIGNALS:
+  void viewModeChanged(View::ViewMode oldMode);
   void mouseModeChanged(View::MouseMode oldMode);
   void creationPolygonChanged(View::CreationEvent event);
 
@@ -85,6 +90,7 @@
 private:
   QUndoStack *_undoStack;
   ViewItem *_currentViewItem;
+  ViewMode _viewMode;
   MouseMode _mouseMode;
   ViewItem *_layoutBoxItem;
   QPolygonF _creationPolygonPress;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #709157:709158
@@ -464,6 +464,11 @@
 
 void ViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
+  if (parentView()->viewMode() == View::Data) {
+    event->ignore();
+    return;
+  }
+
   if (parentView()->mouseMode() == View::Default) {
     if (mouseMode() == ViewItem::Default ||
         mouseMode() == ViewItem::Move ||
@@ -866,11 +871,20 @@
 
 
 void ViewItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+  if (parentView()->viewMode() == View::Data) {
+    event->ignore();
+    return;
+  }
 }
 
 
 void ViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
+  if (parentView()->viewMode() == View::Data) {
+    event->ignore();
+    return;
+  }
+
   QPointF p = event->pos();
   if (topLeftGrip().contains(p)) {
     setActiveGrip(TopLeftGrip);
@@ -898,6 +912,11 @@
 
 void ViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
 
+  if (parentView()->viewMode() == View::Data) {
+    event->ignore();
+    return;
+  }
+
   if (parentView()->mouseMode() != View::Default) {
     parentView()->setMouseMode(View::Default);
     parentView()->undoStack()->endMacro();


More information about the Kst mailing list