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

Adam Treat treat at kde.org
Wed Jun 13 19:55:06 CEST 2007


SVN commit 675086 by treat:

* Better


 M  +3 -3      labelitem.cpp  
 M  +76 -34    viewitem.cpp  
 M  +2 -1      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #675085:675086
@@ -54,10 +54,10 @@
     painter->restore();
   }
 
-  QPen p = pen();
-  setPen(Qt::NoPen);
+//   QPen p = pen();
+//   setPen(Qt::NoPen);
   ViewItem::paint(painter, option, widget);
-  setPen(p);
+//   setPen(p);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #675085:675086
@@ -257,7 +257,7 @@
   }
 
 #ifdef DEBUG_GEOMETRY
-//   painter->fillRect(selectBoundingRect(), Qt::blue);
+//  painter->fillRect(selectBoundingRect(), Qt::blue);
   QColor semiRed(QColor(255, 0, 0, 50));
   painter->fillPath(shape(), semiRed);
 
@@ -413,92 +413,134 @@
 void ViewItem::setTopLeft(const QPointF &point) {
 //   qDebug() << "setTopLeft" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setTopLeft(point);
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setTopLeft(point);
+  from.moveBottomRight(transform().map(rect().bottomRight()));
+  to.moveBottomRight(transform().map(rect().bottomRight()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setTopRight(const QPointF &point) {
 //   qDebug() << "setTopRight" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setTopRight(point);
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setTopRight(point);
+  from.moveBottomLeft(transform().map(rect().bottomLeft()));
+  to.moveBottomLeft(transform().map(rect().bottomLeft()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setBottomLeft(const QPointF &point) {
 //   qDebug() << "setBottomLeft" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setBottomLeft(point);
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setBottomLeft(point);
+  from.moveTopRight(transform().map(rect().topRight()));
+  to.moveTopRight(transform().map(rect().topRight()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setBottomRight(const QPointF &point) {
 //   qDebug() << "setBottomRight" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setBottomRight(point);
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setBottomRight(point);
+  from.moveTopLeft(transform().map(rect().topLeft()));
+  to.moveTopLeft(transform().map(rect().topLeft()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setTop(const QPointF &point) {
 //   qDebug() << "setTop" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setTop(point.y());
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setTop(point.y());
+  from.moveBottomLeft(transform().map(rect().bottomLeft()));
+  to.moveBottomLeft(transform().map(rect().bottomLeft()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setBottom(const QPointF &point) {
 //   qDebug() << "setBottom" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setBottom(point.y());
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setBottom(point.y());
+  from.moveTopLeft(transform().map(rect().topLeft()));
+  to.moveTopLeft(transform().map(rect().topLeft()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setLeft(const QPointF &point) {
 //   qDebug() << "setLeft" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setLeft(point.x());
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+
+  to.setLeft(point.x());
+  from.moveTopRight(transform().map(rect().topRight()));
+  to.moveTopRight(transform().map(rect().topRight()));
+  transformToRect(from, to);
 }
 
 
 void ViewItem::setRight(const QPointF &point) {
 //   qDebug() << "setRight" << point << endl;
 
-  QRectF transformed = selectBoundingRect();
-  transformed.setRight(point.x());
-  transformToRect(transformed);
+  QRectF from = selectBoundingRect();
+  QRectF to = from;
+  to.setRight(point.x());
+
+  from.moveBottomLeft(transform().map(rect().bottomLeft()));
+  to.moveBottomLeft(transform().map(rect().bottomLeft()));
+  transformToRect(from, to);
 }
 
 
-bool ViewItem::transformToRect(const QRectF &newRect) {
+bool ViewItem::transformToRect(const QRectF &from, const QRectF &to) {
   //Not sure how to handle yet
-  if (!newRect.isValid()) {
+  if (!to.isValid()) {
     return false;
   }
 
+  qDebug() << "Mapping from " << from << "to" << to << endl;
+  qDebug() << "Pos is " << pos() << endl;
+  qDebug() << "ScenePos is " << scenePos() << endl;
+  qDebug() << "ItemShape is " << itemShape().controlPointRect() << endl;
+  qDebug() << "BoundingRect is " << QGraphicsRectItem::boundingRect() << endl;
+  qDebug() << "Rect is " << rect() << endl;
+
+  QPolygonF from_(from);
+  from_.pop_back(); //get rid of last closed point
+  QPolygonF to_(to);
+  to_.pop_back(); //get rid of last closed point
+  return transformToRect(from_, to_);
+}
+
+bool ViewItem::transformToRect(const QPolygonF &from, const QPolygonF &to) {
+
   QTransform t;
-  QPolygonF one(selectBoundingRect());
-  one.pop_back(); //get rid of last closed point
-  QPolygonF two(newRect);
-  two.pop_back(); //get rid of last closed point
-  bool success = QTransform::quadToQuad(one, two, t);
+  bool success = QTransform::quadToQuad(from, to, t);
 
   t = transform() * t;
 
-//   qDebug() << t << endl;
-
   if (success) setTransform(t, false);
   return success;
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #675085:675086
@@ -79,7 +79,8 @@
   void setBottom(const QPointF &point);
   void setLeft(const QPointF &point);
   void setRight(const QPointF &point);
-  bool transformToRect(const QRectF &newRect);
+  bool transformToRect(const QRectF &from, const QRectF &to);
+  bool transformToRect(const QPolygonF &from, const QPolygonF &to);
   void rotateTowards(const QPointF &corner, const QPointF &point);
 
 protected Q_SLOTS:


More information about the Kst mailing list