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

Barth Netterfield netterfield at astro.utoronto.ca
Sat Aug 6 03:40:18 UTC 2011


SVN commit 1245205 by netterfield:

BUG:
Fix Z-order bugs - now things can be properly raised and lowered.
Fix creation drawing of boxes, ellipses, and circles.
Change drawing circles to a more traditional 'center, radius' type.



 M  +0 -12     devel-docs/Kst2Specs/Bugs  
 M  +6 -6      src/libkstapp/circleitem.cpp  
 M  +7 -0      src/libkstapp/lineitem.cpp  
 M  +25 -106   src/libkstapp/viewitem.cpp  
 M  +2 -3      src/libkstapp/viewitem.h  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Bugs #1245204:1245205
@@ -1,17 +1,5 @@
 More than one shared axis group.  Tied zoom doesn't work right.
 
------------------
-
-Draw a box and an arrow.  Drage the box.  Then the arrow.  Arrow starting location is way off from the mouse.
-
------------------
-
-Draw a box and an arrow.  Box can never be put over the arrow (it alway ends up behind.)
-
----------------------
-
-Draw an ellipse that spans many plots.  It ends up in the back, and can't be brought to the front.
-
 --------------------
 
 Curves are rendered slightly above where they should be.  Take a plot
--- branches/work/kst/portto4/kst/src/libkstapp/circleitem.cpp #1245204:1245205
@@ -59,18 +59,18 @@
     const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MousePress));
     setPos(poly.first().x(), poly.first().y());
     setViewRect(QRectF(0.0, 0.0, 0.0, sizeOfGrip().height()));
+    setRect(-2,-2,4,4);
     view()->scene()->addItem(this);
     return;
   }
 
   if (event == View::MouseMove) {
     const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseMove));
-    qreal size = (fabs(poly.last().x() - rect().x()) < fabs(poly.last().y() - rect().y())) ? fabs(poly.last().x() - rect().x()) : fabs(poly.last().y() - rect().y());
-    qreal width = (poly.last().x() - rect().x()) < 0 ? size * -1.0 : size;
-    qreal height = (poly.last().y() - rect().y()) < 0 ? size * -1.0 : size;
-    QRectF newRect(rect().x(), rect().y(),
-                   width,
-                   height);
+    qreal dx = poly.last().x();
+    qreal dy = poly.last().y();
+    qreal r = qMax(2.0,sqrt(dx*dx + dy*dy));
+
+    QRectF newRect(-r, -r, 2.0*r, 2.0*r);
     setViewRect(newRect);
 
     return;
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #1245204:1245205
@@ -165,6 +165,13 @@
     return;
   }
 
+  if (!dragStartPosition.isNull() && event->buttons() & Qt::LeftButton) {
+    if (view()->mouseMode() == View::Move) {
+      startDragging(event->widget(), dragStartPosition.toPoint());
+      return;
+    }
+  }
+
   if (view()->mouseMode() == View::Default) {
     if (gripMode() == ViewItem::Move || activeGrip() == NoGrip) {
       view()->setMouseMode(View::Move);
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1245204:1245205
@@ -884,21 +884,23 @@
 
   if (event == View::MouseMove) {
     const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseMove));
-    QRectF newRect(rect().x(), rect().y(),
-                   poly.last().x() - rect().x(),
-                   poly.last().y() - rect().y());
+    double x0 = qMin(0.0, poly.last().x());
+    double y0 = qMin(0.0, poly.last().y());
+    QRectF newRect(x0, y0, fabs(poly.last().x()), fabs(poly.last().y()));
     setViewRect(newRect);
     return;
   }
 
   if (event == View::MouseRelease) {
     const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseRelease));
-    QRectF newRect(rect().x(), rect().y(),
-                   poly.last().x() - rect().x(),
-                   poly.last().y() - rect().y());
+    double x0 = qMin(0.0, poly.last().x());
+    double y0 = qMin(0.0, poly.last().y());
+    QRectF newRect(x0, y0, fabs(poly.last().x()), fabs(poly.last().y()));
 
     if (!newRect.isValid()) {
       newRect = newRect.normalized();
+      newRect.setWidth(qMax(3.0, newRect.width()));
+      newRect.setHeight(qMax(3.0, newRect.height()));
       setPos(pos() + newRect.topLeft());
 
       newRect.moveTopLeft(QPointF(0, 0));
@@ -915,7 +917,7 @@
 
     updateViewItemParent();
     _creationState = Completed;
-    setZValue(1);
+    setZValue(DRAWING_ZORDER);
     emit creationComplete();
     return;
   }
@@ -1557,18 +1559,16 @@
            << "topLevel:" << (topLevel ? "true" : "false")
            << "origin:" << origin
            << "rect:" << rect()
-           << "collision count:" << collisions.count()
-           << endl;
+           << "collision count:" << collisions.count();
 #endif
 
   //Doesn't collide then reparent to top-level
   if (collisions.isEmpty() && !topLevel) {
 #if DEBUG_REPARENT
-    qDebug() << "reparent to topLevel" << endl;
+    qDebug() << "reparent to topLevel";
 
     qDebug() << "before transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     /*bring the old parent's transform with us*/
@@ -1576,8 +1576,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     setParentViewItem(0);
@@ -1586,8 +1585,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after new parent"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     return true;
@@ -1599,24 +1597,24 @@
 
     if (!viewItem || !viewItem->acceptsChildItems() || isAncestorOf(viewItem) || !collidesWithItem(viewItem, Qt::ContainsItemBoundingRect)) {
 #if DEBUG_REPARENT
-     qDebug() << "rejecting collision" << viewItem << !viewItem->acceptsChildItems() << isAncestorOf(viewItem) << !collidesWithItem(viewItem, Qt::ContainsItemBoundingRect); 
+     qDebug() << "rejecting collision" << viewItem << !viewItem->acceptsChildItems() <<
+                 isAncestorOf(viewItem) << !collidesWithItem(viewItem, Qt::ContainsItemBoundingRect);
 #endif
       continue;
     }
 
     if (parentItem() == viewItem) { /*already done*/
 #if DEBUG_REPARENT
-      qDebug() << "already in containing parent" << endl;
+      qDebug() << "already in containing parent";
 #endif
       return false;
     }
 
 #if DEBUG_REPARENT
-    qDebug() << "reparent to" << viewItem << endl;
+    qDebug() << "reparent to" << viewItem;
 
     qDebug() << "before transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     if (!topLevel) { /*bring the old parent's transform with us*/
@@ -1628,8 +1626,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     setParentViewItem(viewItem);
@@ -1638,8 +1635,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after new parent"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     return true;
@@ -1648,11 +1644,10 @@
   //No suitable collisions then reparent to top-level
   if (!topLevel) {
 #if DEBUG_REPARENT
-    qDebug() << "reparent to topLevel" << endl;
+    qDebug() << "reparent to topLevel";
 
     qDebug() << "before transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     /*bring the old parent's transform with us*/
@@ -1660,8 +1655,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after transform"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     setParentViewItem(0);
@@ -1670,8 +1664,7 @@
 
 #if DEBUG_REPARENT
     qDebug() << "after new parent"
-             << "origin:" << mapToScene(QPointF(0,0))
-             << endl;
+             << "origin:" << mapToScene(QPointF(0,0));
 #endif
 
     return true;
@@ -2353,81 +2346,7 @@
   _item->view()->undoStack()->push(this);
 }
 
-#if 0
-void oldAppendLayout(CurvePlacement::Layout layout, ViewItem* item, int columns) {
-  Q_ASSERT(_item);
-  Q_ASSERT(_item->view());
-  Q_ASSERT(item);
 
-  _layout = new ViewGridLayout(_item);
-
-  QPointF center = _item->view()->sceneRect().center();
-  center -= QPointF(100.0, 100.0);
-
-  item->setPos(center);
-  item->setViewRect(0.0, 0.0, 200.0, 200.0);
-  _item->view()->scene()->addItem(item);
-
-  if (layout == CurvePlacement::Auto) {
-    columns = 0;
-  }
-
-  if (layout != CurvePlacement::Protect) {
-    QList<ViewItem*> viewItems;
-    QList<QGraphicsItem*> list = _item->QGraphicsItem::children();
-
-    foreach (QGraphicsItem *graphicsItem, list) {
-      ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(graphicsItem);
-      if (!viewItem || viewItem->hasStaticGeometry() || !viewItem->allowsLayout() || viewItem->parentItem() != _item || viewItem == item)
-        continue;
-      viewItems.append(viewItem);
-    }
-
-    bool appendRequired = true;
-    if (viewItems.isEmpty()) {
-      viewItems.append(item);
-      appendRequired = false;
-    }
-    if (layout == CurvePlacement::Auto) {
-      columns = (int)sqrt((double)viewItems.count()+1);
-    }
-
-    Grid *grid = Grid::buildGrid(viewItems, columns);
-    Q_ASSERT(grid);
-    grid->appendItem(item);
-
-    if (appendRequired) {
-      viewItems.append(item);
-    }
-
-    _layout = new ViewGridLayout(_item);
-
-    foreach (ViewItem *v, viewItems) {
-      int r = 0, c = 0, rs = 0, cs = 0;
-      if (grid->locateWidget(v, r, c, rs, cs)) {
-        if (rs * cs == 1) {
-          _layout->addViewItem(v, r, c, 1, 1);
-        } else {
-          _layout->addViewItem(v, r, c, rs, cs);
-        }
-      } else {
-        qDebug() << "ooops, viewItem does not fit in layout" << endl;
-      }
-    }
-    delete grid;
-
-    if (qobject_cast<LayoutBoxItem*>(_item)) {
-      QObject::connect(_layout, SIGNAL(enabledChanged(bool)),
-                      _item, SLOT(setEnabled(bool)));
-    }
-
-    _layout->apply();
-  }
-  _item->view()->undoStack()->push(this);
-}
-
-#endif
-
 void MoveCommand::undo() {
   Q_ASSERT(_item);
   _item->setPos(_originalPos);
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #1245204:1245205
@@ -319,6 +319,8 @@
   protected:
     virtual QString _automaticDescriptiveName() const;
     virtual void _initializeShortName();
+    QPointF dragStartPosition;
+    void startDragging(QWidget *widget, const QPointF& hotspot);
 
   private:
     GripMode _gripMode;
@@ -361,9 +363,6 @@
     // use setParentViewItem(ViewItem*)
     void setParentItem(QGraphicsItem*);
 
-    QPointF dragStartPosition;
-    void startDragging(QWidget *widget, const QPointF& hotspot);
-
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(ViewItem::GripModes)


More information about the Kst mailing list