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

Barth Netterfield netterfield at astro.utoronto.ca
Fri May 20 18:50:12 CEST 2011


SVN commit 1232866 by netterfield:

CCBUG: 254922
BUG: 255274

Draw lines around all objects in layout mode, so the boundries are obvious.
  -The bug suggested that the plot be made fully transparent, but dragging with the boundry clear
  seems to solve the problem, at least for me.  It would be easy to make the plots transparent, so
  the bug can be re-opened if people want more discussion about it.

Allow for rotated plots to be dragged and dropped in layout mode.
  -Dragging rotated plots which have been resized after rotation still have issues which I haven't
  been able to track down.




 M  +7 -1      plotitem.cpp  
 M  +4 -1      scene.cpp  
 M  +43 -5     viewitem.cpp  
 M  +1 -0      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1232865:1232866
@@ -885,13 +885,19 @@
     if (_plotPixmapDirty && rect().isValid()) {
       updatePlotPixmap();
     }
-
     painter->save();
     painter->setPen(Qt::NoPen);
     painter->drawRect(rect());
     painter->restore();
     painter->drawPixmap(rect().topLeft(), _plotPixmap);
+    if (view()->viewMode() == View::Layout) {
+      painter->save();
+      painter->setPen(pen());
+      painter->setBrush(Qt::NoBrush);
+      painter->drawRect(rect());
+      painter->restore();
   }
+  }
 #if BENCHMARK
   int i = bench_time.elapsed();
   qDebug() << "Total Time to paint " << (void *)this << ": " << i << "ms" << endl;
--- branches/work/kst/portto4/kst/src/libkstapp/scene.cpp #1232865:1232866
@@ -96,7 +96,10 @@
     }
     m->item->show();
     QPointF viewpos = view->mapFromScene(event->scenePos());
-    m->item->moveTo(viewpos - m->hotSpot);
+    //qDebug() << "viewpos: " << viewpos << " scenepos: " << event->scenePos();
+    //qDebug() << "m hotspot: " << m->hotSpot << " rect: " << m->item->rect() <<
+    //            " drop hot spot" << m->item->dropHotSpot << " topleft:" << m->item->rect().topLeft();
+    m->item->moveTo(viewpos - m->item->rect().center() - m->item->dropHotSpot.toPoint());
     event->acceptProposedAction();
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1232865:1232866
@@ -963,13 +963,43 @@
   mimeData->hotSpot = hotspot;
   drag->setMimeData(mimeData);
 
-  QPixmap pixmap(sceneBoundingRect().size().toSize());
-  pixmap.fill(Qt::white);
+  //QPixmap pixmap(sceneBoundingRect().size().toSize());
+  qreal theta = rotationAngle()*ONE_PI/180.0;
+  qreal w = fabs(rect().width()*cos(theta)) + fabs(rect().height()*sin(theta));
+  qreal h = fabs(rect().width()*sin(theta)) + fabs(rect().height()*cos(theta));
+
+  QPixmap pixmap(w+2, h+2);
+  //pixmap.fill(brush().color());
   // Qt::transparent is maybe too expensive, and when 
   // not moving a plot it also has no transparent background
-  //pixmap.fill(Qt::transparent);
+  pixmap.fill(Qt::transparent);
   QPainter painter(&pixmap);
+
+  //painter.translate(centerOfRotation().x(), centerOfRotation().y());
+  qreal x1 = -rect().height()*sin(theta);
+  qreal x3 = rect().width()*cos(theta);
+  qreal x2 = x1+x3;
+  qreal dx;
+
+  dx = qMin(0.0, x1);
+  dx = qMin(x2,dx);
+  dx = qMin(x3,dx);
+
+  qreal y1 = rect().height()*cos(theta);
+  qreal y3 = rect().width()*sin(theta);
+  qreal y2 = y1+y3;
+  qreal dy;
+
+  dy = qMin(0.0, y1);
+  dy = qMin(y2,dy);
+  dy = qMin(y3,dy);
+
+  painter.translate(-dx,-dy);
+  painter.rotate(rotationAngle());
   painter.translate(-rect().left(), -rect().top());
+
+  painter.setPen(pen());
+  painter.setBrush(brush());
   paint(&painter); // TODO also paint annotations
   QList<QGraphicsItem*> children = childItems();
   foreach(QGraphicsItem* child, children) {
@@ -981,8 +1011,17 @@
   painter.end();
 
   drag->setPixmap(pixmap);
-  drag->setHotSpot(hotspot.toPoint()- rect().topLeft().toPoint());
 
+  //drag->setHotSpot(hotspot.toPoint()- rect().topLeft().toPoint());
+  qreal hx = hotspot.toPoint().x()-rect().left();
+  qreal hy = hotspot.toPoint().y()-rect().top();
+  qreal hx_r = hx * cos(theta) - hy * sin(theta);
+  qreal hy_r = hy * cos(theta) + hx * sin(theta);
+  drag->setHotSpot(QPoint(hx_r-dx,hy_r-dy));
+
+  dropHotSpot = QPoint(hx_r-dx-w/2-1,hy_r-dy-h/2-1);
+  //dropHotSpot = hotspot;// + rect().topLeft();
+
   hide();
   Qt::DropActions dact = Qt::MoveAction;
   Qt::DropAction dropAction = drag->exec(dact);
@@ -1824,7 +1863,6 @@
 
 void ViewItem::moveTo(const QPointF& pos)
 {
-
   QPointF newpos = view()->snapPoint(pos);
 
   if (parentViewItem()) {
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #1232865:1232866
@@ -211,6 +211,7 @@
     }
 
     virtual bool isMaximized();
+    QPointF dropHotSpot;
 
   Q_SIGNALS:
     void geometryChanged();


More information about the Kst mailing list