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

Adam Treat treat at kde.org
Wed Aug 29 17:12:12 CEST 2007


SVN commit 706158 by treat:

* New grid layout and other fixes


 M  +2 -2      libkstapp.pro  
 M  +13 -8     mainwindow.cpp  
 M  +0 -3      plotitem.h  
 D             plotlayoutitem.cpp  
 D             plotlayoutitem.h  
 A             viewgridlayout.cpp   [License: GPL (v2+)]
 A             viewgridlayout.h   [License: GPL (v2+)]
 M  +15 -5     viewitem.cpp  
 M  +11 -0     viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #706157:706158
@@ -39,7 +39,6 @@
     memorywidget.cpp \
     pictureitem.cpp \
     plotitem.cpp \
-    plotlayoutitem.cpp \
     plotrenderitem.cpp \
     qgetoptions.cpp \
     vectorcurverenderitem.cpp \
@@ -51,6 +50,7 @@
     vectortablemodel.cpp \
     viewcommand.cpp \
     view.cpp \
+    viewgridlayout.cpp \
     viewitem.cpp \
     viewitemdialog.cpp \
     viewmanager.cpp
@@ -77,7 +77,6 @@
     memorywidget.h \
     pictureitem.h \
     plotitem.h \
-    plotlayoutitem.h \
     plotrenderitem.h \
     qgetoptions.h \
     vectorcurverenderitem.h \
@@ -89,6 +88,7 @@
     vectortablemodel.h \
     viewcommand.h \
     view.h \
+    viewgridlayout.h \
     viewitemdialog.h \
     viewitem.h \
     viewmanager.h
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #706157:706158
@@ -39,7 +39,7 @@
 #include "kstdataobjectcollection.h"
 #include "kstequation.h"
 
-#include "plotlayoutitem.h"
+#include "viewgridlayout.h"
 
 namespace Kst {
 
@@ -310,17 +310,22 @@
 void MainWindow::demoPlotLayout() {
 
   View *v = tabWidget()->currentView();
-  PlotLayoutItem *layout = new PlotLayoutItem(v);
-  v->scene()->addItem(layout);
-  layout->setZValue(1);
+
+  ViewItem *viewItem = new ViewItem(v);
+  v->scene()->addItem(viewItem);
+  viewItem->setZValue(1);
+
+  ViewGridLayout *layout = new ViewGridLayout(viewItem);
+
+  int r = 0; int c = 0;
   foreach (QGraphicsItem *item, v->items()) {
-    if (PlotItem *plot = qgraphicsitem_cast<PlotItem*>(item)) {
-      plot->setParentItem(layout);
+    if (PlotItem *plotItem = qgraphicsitem_cast<PlotItem*>(item)) {
+      plotItem->setParentItem(viewItem);
+      layout->addViewItem(plotItem, r++, c++);
     }
   }
 
-  layout->setViewRect(QRectF(0,0,300,300));
-
+  viewItem->setViewRect(QRectF(0,0,300,300));
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #706157:706158
@@ -36,9 +36,6 @@
 
     void paint(QPainter *painter);
 
-    qreal width() const { return viewRect().normalized().width(); }
-    qreal height() const { return viewRect().normalized().height(); }
-
     qreal marginWidth() const;
     void setMarginWidth(qreal marginWidth);
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #706157:706158
@@ -23,7 +23,7 @@
 namespace Kst {
 
 ViewItem::ViewItem(View *parent)
-  : QObject(parent), _mouseMode(Default), _activeGrip(NoGrip) {
+  : QObject(parent), _mouseMode(Default), _layout(0), _activeGrip(NoGrip) {
   setAcceptsHoverEvents(true);
   setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
   connect(parent, SIGNAL(mouseModeChanged(View::MouseMode)),
@@ -51,6 +51,16 @@
 }
 
 
+ViewGridLayout *ViewItem::layout() const {
+  return _layout;
+}
+
+
+void ViewItem::setLayout(ViewGridLayout *layout) {
+  _layout = layout;
+}
+
+
 QRectF ViewItem::viewRect() const {
   return rect();
 }
@@ -390,7 +400,7 @@
 
 void ViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (ViewItem *item = qgraphicsitem_cast<ViewItem*>(parentItem())) {
+  if (qgraphicsitem_cast<ViewItem*>(parentItem())) {
     event->ignore();
     return;
   }
@@ -647,7 +657,7 @@
 
 void ViewItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (ViewItem *item = qgraphicsitem_cast<ViewItem*>(parentItem())) {
+  if (qgraphicsitem_cast<ViewItem*>(parentItem())) {
     event->ignore();
     return;
   }
@@ -658,7 +668,7 @@
 
 void ViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (ViewItem *item = qgraphicsitem_cast<ViewItem*>(parentItem())) {
+  if (qgraphicsitem_cast<ViewItem*>(parentItem())) {
     event->ignore();
     return;
   }
@@ -690,7 +700,7 @@
 
 void ViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (ViewItem *item = qgraphicsitem_cast<ViewItem*>(parentItem())) {
+  if (qgraphicsitem_cast<ViewItem*>(parentItem())) {
     event->ignore();
     return;
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #706157:706158
@@ -23,6 +23,8 @@
 
 namespace Kst {
 
+class ViewGridLayout;
+
 class KST_EXPORT ViewItem : public QObject, public QGraphicsRectItem
 {
   Q_OBJECT
@@ -45,11 +47,19 @@
   MouseMode mouseMode() const;
   void setMouseMode(MouseMode mode);
 
+  //NOTE We can change this to a generic abstract class once we have
+  //more layouts besides grid layout...
+  ViewGridLayout *layout() const;
+  void setLayout(ViewGridLayout *layout);
+
   //NOTE This should be used in place of QGraphicsRectItem::setRect()...
   QRectF viewRect() const;
   void setViewRect(const QRectF &viewRect);
   void setViewRect(qreal x, qreal y, qreal width, qreal height);
 
+  qreal width() const { return viewRect().normalized().width(); }
+  qreal height() const { return viewRect().normalized().height(); }
+
   QSize sizeOfGrip() const;
   QPainterPath topLeftGrip() const;
   QPainterPath topRightGrip() const;
@@ -115,6 +125,7 @@
 
 private:
   MouseMode _mouseMode;
+  ViewGridLayout *_layout;
   QPointF _originalPosition;
   QTransform _originalTransform;
   QLineF _normalLine;


More information about the Kst mailing list