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

Mike Fenton mike at staikos.net
Wed Jan 28 18:51:05 CET 2009


SVN commit 917877 by fenton:

Updates to SharedAxisBoxItem and Layout's.
 - Add parent lock to viewItems to prevent reparenting (used for plots in SharedAxisBox's).
 - Redo sizing for SharedAxisBoxItem to maximize to topLeft/bottomRight of plots being added.
 - Eliminate black border from created SharedAxisBoxItem's.
 - Add highlighting to plots that will be added to the to the SharedAxisBoxItem during creation.
 - Update Layout - Remove spacing between objects & reduce margin to minimum needed to select parent.
 - Fix Context Menu missing Raise/Lower/Layout options.
 - Update ViewItem::maybeParent to prevent ancestor bug and prevent inappropriate reparenting of children to top.


 M  +1 -0      plotitem.cpp  
 M  +79 -1     sharedaxisboxitem.cpp  
 M  +9 -0      sharedaxisboxitem.h  
 M  +2 -2      viewgridlayout.cpp  
 M  +13 -16    viewitem.cpp  
 M  +8 -0      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #917876:917877
@@ -993,6 +993,7 @@
 
 void PlotItem::setInSharedAxisBox(bool inSharedBox) {
   _isInSharedAxisBox = inSharedBox;
+  setLockParent(inSharedBox);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #917876:917877
@@ -17,6 +17,8 @@
 #include "gridlayouthelper.h"
 #include "viewgridlayout.h"
 
+#include "application.h"
+
 #include <debug.h>
 
 #include <QDebug>
@@ -26,7 +28,7 @@
 namespace Kst {
 
 SharedAxisBoxItem::SharedAxisBoxItem(View *parent)
-    : ViewItem(parent), _layout(0), _loaded(false) {
+    : ViewItem(parent), _layout(0), _loaded(false), _creationStarted(false) {
   setName("Shared Axis Box");
   setZValue(SHAREDAXISBOX_ZVALUE);
   setBrush(Qt::transparent);
@@ -67,6 +69,7 @@
     _loaded = true;
   }
 
+  QRectF maxSize(mapToParent(viewRect().topLeft()), mapToParent(viewRect().bottomRight()));
   ViewItem* child = 0;
   if (parentView()) {
     QList<QGraphicsItem*> list = parentView()->items();
@@ -90,15 +93,28 @@
         }
         plotItem->setSharedAxisBox(this);
         child = plotItem;
+        if (!maxSize.contains(plotItem->mapToParent(plotItem->viewRect().topLeft()))) {
+          maxSize.setTop(qMin(plotItem->mapToParent(plotItem->viewRect().topLeft()).y(), maxSize.top()));
+          maxSize.setLeft(qMin(plotItem->mapToParent(plotItem->viewRect().topLeft()).x(), maxSize.left()));
+        }
+        if (!maxSize.contains(plotItem->mapToParent(plotItem->viewRect().bottomRight()))) {
+          maxSize.setBottom(qMax(plotItem->mapToParent(plotItem->viewRect().bottomRight()).y(), maxSize.bottom()));
+          maxSize.setRight(qMax(plotItem->mapToParent(plotItem->viewRect().bottomRight()).x(), maxSize.right()));
+        }
       }
     }
     if (child) {
+      setPen(QPen(Qt::white));
       setBrush(Qt::white);
       ViewGridLayout::updateProjections(this);
       sharePlots();
       bReturn =  true;
     }
   }
+  if (maxSize != viewRect()) {
+    setPos(maxSize.topLeft());
+    setViewRect(QRectF(mapFromParent(maxSize.topLeft()), mapFromParent(maxSize.bottomRight())));
+  }
   return bReturn;
 }
 
@@ -138,6 +154,7 @@
     }
   }
   if (!list.isEmpty()) {
+    setPen(QPen(Qt::white));
     setBrush(Qt::white);
   }
 }
@@ -153,6 +170,65 @@
 }
 
 
+void SharedAxisBoxItem::creationPolygonChanged(View::CreationEvent event) {
+  if (event == View::MousePress) {
+    ViewItem::creationPolygonChanged(event);
+    _creationStarted = true;
+    return;
+  }
+
+  if (event == View::MouseMove) {
+    ViewItem::creationPolygonChanged(event);
+    if (!_creationStarted) {
+      return;
+    }
+
+    QList<PlotItem*> plots;
+    if (parentView()) {
+      QList<QGraphicsItem*> list = parentView()->items();
+      foreach (QGraphicsItem *item, list) {
+        ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
+        if (!viewItem || !viewItem->isVisible() || viewItem == this ||  viewItem == parentItem() || !collidesWithItem(viewItem, Qt::IntersectsItemBoundingRect)) {
+          continue;
+        }
+        if (PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem)) {
+          plots.append(plotItem);
+        }
+      }
+      highlightPlots(plots);
+    }
+    return;
+  }
+
+  if (event == View::EscapeEvent || event == View::MouseRelease) {
+    ViewItem::creationPolygonChanged(event);
+    highlightPlots(QList<PlotItem*>());
+    return;
+  }
+}
+
+
+void SharedAxisBoxItem::highlightPlots(QList<PlotItem*> plots) {
+  QList<PlotItem*> currentlyHighlighted = _highlightedPlots;
+  _highlightedPlots.clear();
+
+  foreach(PlotItem *plotItem, plots) {
+    _highlightedPlots.append(plotItem);
+    if (!currentlyHighlighted.contains(plotItem)) {
+      plotItem->setHighlighted(true);
+      plotItem->update();
+    }
+  }
+
+  foreach(PlotItem* plotItem, currentlyHighlighted) {
+    if (!_highlightedPlots.contains(plotItem)) {
+      plotItem->setHighlighted(false);
+      plotItem->update();
+    }
+  }
+}
+
+
 void CreateSharedAxisBoxCommand::createItem() {
   _item = new SharedAxisBoxItem(_view);
   _view->setCursor(Qt::CrossCursor);
@@ -191,6 +267,8 @@
       CreateCommand::creationComplete();
     } else {
       delete _item;
+      deleteLater();
+      kstApp->mainWindow()->clearDrawingMarker();
     }
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.h #917876:917877
@@ -17,6 +17,8 @@
 
 namespace Kst {
 
+class PlotItem;
+
 class SharedAxisBoxItem : public ViewItem
 {
   Q_OBJECT
@@ -38,10 +40,17 @@
     bool acceptItems();
     void lockItems();
 
+  protected Q_SLOTS:
+    virtual void creationPolygonChanged(View::CreationEvent event);
+
   private:
+    void highlightPlots(QList<PlotItem*> plots);
+
     QAction *_breakAction;
     QPointer<ViewGridLayout> _layout;
+    QList<PlotItem*> _highlightedPlots;
     bool _loaded;
+    bool _creationStarted;
 };
 
 class KST_EXPORT CreateSharedAxisBoxCommand : public CreateCommand
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #917876:917877
@@ -24,7 +24,7 @@
 #define DEBUG_PLOT_STANDARDIZATION 0
 #define DEBUG_SHAREDAXIS 0
 
-static qreal DEFAULT_STRUT = 20.0;
+static qreal DEFAULT_STRUT = 5.0;
 
 namespace Kst {
 
@@ -35,7 +35,7 @@
     _columnCount(0),
     _shareX(false),
     _shareY(false),
-    _spacing(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)),
+    _spacing(QSizeF(0.0, 0.0)),
     _margin(QSizeF(DEFAULT_STRUT,DEFAULT_STRUT)) {
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #917876:917877
@@ -15,7 +15,7 @@
 #include "tabwidget.h"
 #include "viewitemdialog.h"
 #include "viewgridlayout.h"
-#include "sharedaxisboxitem.h"
+#include "plotitem.h"
 
 #include "layoutboxitem.h"
 
@@ -49,11 +49,13 @@
     _lockAspectRatio(false),
     _lockAspectRatioFixed(false),
     _hasStaticGeometry(false),
+    _lockParent(false),
     _allowsLayout(true),
     _hovering(false),
     _acceptsChildItems(true),
     _acceptsContextMenuEvents(true),
     _updatingLayout(false),
+    _highlighted(false),
     _activeGrip(NoGrip),
     _allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
                   TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip),
@@ -643,6 +645,9 @@
         painter->fillPath(grips(), Qt::red);
       else if (_gripMode == Move)
         painter->fillPath(grips(), Qt::transparent);
+    } else if (isHighlighted()) {
+      QColor highlightColor(QColor(255, 255, 0, 120));
+      painter->fillPath(shape(), highlightColor);
     }
 
 #ifdef DEBUG_GEOMETRY
@@ -799,18 +804,11 @@
 
   menu.addAction(_editAction);
 
-  bool inSharedBox = false;
-  if (parentItem()) {
-    if (SharedAxisBoxItem *sharedBox = qgraphicsitem_cast<SharedAxisBoxItem*>(parentItem())) {
-      inSharedBox = true;
-    }
-  }
-
-  if (!inSharedBox) {
+  QMenu layoutMenu;
+  if (!lockParent()) {
     menu.addAction(_raiseAction);
     menu.addAction(_lowerAction);
 
-    QMenu layoutMenu;
     layoutMenu.setTitle(tr("Cleanup Layout"));
     layoutMenu.addAction(_autoLayoutAction);
     layoutMenu.addAction(_customLayoutAction);
@@ -1270,8 +1268,11 @@
 
 
 bool ViewItem::maybeReparent() {
+  if (lockParent()) {
+    return false;
+  }
   //First get a list of all items that collide with this one
-  QList<QGraphicsItem*> collisions = collidingItems(Qt::ContainsItemShape);
+  QList<QGraphicsItem*> collisions = collidingItems(Qt::IntersectsItemShape);
 
   bool topLevel = !parentItem();
   QPointF origin = mapToScene(QPointF(0,0));
@@ -1321,7 +1322,7 @@
   foreach (QGraphicsItem *item, collisions) {
     ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
 
-    if (!viewItem || !viewItem->acceptsChildItems()) /*bah*/
+    if (!viewItem || !viewItem->acceptsChildItems() || isAncestorOf(viewItem) || !collidesWithItem(viewItem, Qt::ContainsItemShape))
       continue;
 
     if (parentItem() == viewItem) { /*already done*/
@@ -1848,8 +1849,6 @@
   }
 
   if (qobject_cast<LayoutBoxItem*>(_item)) {
-    _layout->setMargin((_item->sizeOfGrip() / 2.0));
-    _layout->setSpacing((_item->sizeOfGrip() / 2.0));
     QObject::connect(_layout, SIGNAL(enabledChanged(bool)),
                      _item, SLOT(setEnabled(bool)));
   }
@@ -1934,8 +1933,6 @@
     }
 
     if (qobject_cast<LayoutBoxItem*>(_item)) {
-      _layout->setMargin((_item->sizeOfGrip() / 2.0));
-      _layout->setSpacing((_item->sizeOfGrip() / 2.0));
       QObject::connect(_layout, SIGNAL(enabledChanged(bool)),
                       _item, SLOT(setEnabled(bool)));
     }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #917876:917877
@@ -90,9 +90,15 @@
     bool hasStaticGeometry() const { return _hasStaticGeometry; }
     void setHasStaticGeometry(bool hasStaticGeometry ) { _hasStaticGeometry = hasStaticGeometry; }
 
+    bool lockParent() const { return _lockParent; }
+    void setLockParent(bool lockParent ) { _lockParent = lockParent; }
+
     bool allowsLayout() const { return _allowsLayout; }
     void setAllowsLayout(bool allowsLayout ) { _allowsLayout = allowsLayout; }
 
+    bool isHighlighted() const { return _highlighted; }
+    void setHighlighted(bool highlighted ) { _highlighted = highlighted; }
+
     //NOTE This should be used in place of QGraphicsRectItem::setRect()...
     QRectF viewRect() const;
     void setViewRect(const QRectF &viewRect, bool automaticChange = false);
@@ -225,12 +231,14 @@
     bool _lockAspectRatio;
     bool _lockAspectRatioFixed;
     bool _hasStaticGeometry;
+    bool _lockParent;
     bool _allowsLayout;
     bool _hovering;
     bool _acceptsChildItems;
     bool _acceptsContextMenuEvents;
     bool _shareAxis;
     bool _updatingLayout;
+    bool _highlighted;
     QPointF _originalPosition;
     QPointF _parentRelativeCenter;
     QPointF _parentRelativePosition;


More information about the Kst mailing list