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

George Staikos staikos at kde.org
Fri May 25 08:22:59 CEST 2007


SVN commit 668120 by staikos:

adding some interaction and aspect ratio support, though for some reason my
slot never gets called


 M  +36 -1     kstplotitems.cpp  
 M  +8 -0      kstplotitems.h  
 M  +3 -1      kstplotview.cpp  
 M  +1 -0      kstplotview.h  


--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.cpp #668119:668120
@@ -12,12 +12,18 @@
 #include "kstplotitems.h"
 #include "kstplotview.h"
 
+#include <assert.h>
+
 #include <QDebug>
 #include <QGraphicsItem>
 #include <QGraphicsScene>
 
 KstPlotItem::KstPlotItem(KstPlotView *parent)
     : QObject(parent) {
+  _aspectPos = QPointF(50, 50);
+  _aspectSize = QSizeF(50, 50);
+  qDebug() << "CONNECT";
+  connect(parent, SIGNAL(resized()), this, SLOT(updateGeometry()));
 }
 
 
@@ -30,8 +36,36 @@
 }
 
 
+void KstPlotItem::updateAspectFromGeometry() {
+  KstPlotView *v = parentView();
+  assert(v);
+  QGraphicsItem *i = graphicsItem();
+  assert(i);
+  _aspectPos = QPointF(100.0 * i->scenePos().x() / v->width(), 100.0 * i->scenePos().y() / v->height());
+  _aspectSize = QSizeF(100.0 * i->boundingRect().width() / v->width(), 100.0 * i->boundingRect().height() / v->height());
+  qDebug() << "update aspect to" << _aspectPos << _aspectSize;
+}
+
+
+void KstPlotItem::updateGeometry() {
+  qDebug("RESIZE");
+  //prepareGeometryChange();
+  KstPlotView *v = parentView();
+  assert(v);
+  QGraphicsItem *i = graphicsItem();
+  assert(i);
+  qDebug() << "Pos was" << i->scenePos();
+  i->setPos(_aspectPos.x() * v->width() / 100.0, _aspectPos.y() * v->height() / 100.0);
+  i->scale(_aspectSize.width() * v->width() / (i->boundingRect().width() * 100.0), _aspectSize.height() * v->height() / (i->boundingRect().height() * 100.0));
+  qDebug() << "Pos is now" << i->scenePos();
+  i->update();
+}
+
+
 LabelItem::LabelItem(const QString &text, KstPlotView *parent)
     : KstPlotItem(parent), QGraphicsSimpleTextItem(text) {
+  updateAspectFromGeometry();
+  setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
 }
 
 
@@ -41,7 +75,7 @@
 
 LineItem::LineItem(KstPlotView *parent)
     : KstPlotItem(parent) {
-
+  setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
   parent->setMouseMode(KstPlotView::Create);
   connect(parent, SIGNAL(creationPolygonChanged()),
           this, SLOT(creationPolygonChanged()));
@@ -60,6 +94,7 @@
     parentView()->setMouseMode(KstPlotView::Default);
     parentView()->disconnect(this);
     setZValue(1);
+    updateAspectFromGeometry();
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.h #668119:668120
@@ -31,6 +31,14 @@
   KstPlotView *parentView() const;
 
   virtual QGraphicsItem *graphicsItem() = 0;
+
+public Q_SLOTS:
+  void updateAspectFromGeometry();
+  void updateGeometry();
+
+private:
+  QPointF _aspectPos;   // In % from 0.0 to 100.0
+  QSizeF _aspectSize;   // In % from 0.0 to 100.0
 };
 
 class LabelItem : public KstPlotItem, public QGraphicsSimpleTextItem
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.cpp #668119:668120
@@ -26,7 +26,7 @@
   _undoStack = new QUndoStack(this);
   setScene(new QGraphicsScene(this));
   scene()->installEventFilter(this);
-
+  setInteractive(true);
   setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
 }
 
@@ -95,6 +95,8 @@
   l.setColorAt(0, Qt::white);
   l.setColorAt(1, Qt::lightGray);
   setBackgroundBrush(l);
+
+  emit resized();
 }
 
 #include "kstplotview.moc"
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.h #668119:668120
@@ -37,6 +37,7 @@
 
 Q_SIGNALS:
   void creationPolygonChanged();
+  void resized();
 
 protected:
   bool eventFilter(QObject *obj, QEvent *event);


More information about the Kst mailing list