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

Adam Treat treat at kde.org
Tue Sep 4 17:47:01 CEST 2007


SVN commit 708350 by treat:

* Get ready for testing layouts more extensively


 M  +1 -1      viewgridlayout.cpp  
 M  +36 -8     viewitem.cpp  
 M  +3 -2      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #708349:708350
@@ -72,7 +72,7 @@
 
   //For now we divide up equally... can do stretch factors and such later...
   qreal itemWidth = parentItem()->width() / columnCount();
-  qreal itemHeight = parentItem()->width() / rowCount();
+  qreal itemHeight = parentItem()->height() / rowCount();
 
 //   qDebug() << "layouting" << _items.count()
 //            << "itemWidth:" << itemWidth
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #708349:708350
@@ -13,6 +13,7 @@
 #include "kstapplication.h"
 #include "tabwidget.h"
 #include "viewitemdialog.h"
+#include "viewgridlayout.h"
 
 #include <QMenu>
 #include <QDebug>
@@ -358,12 +359,38 @@
 }
 
 
-void ViewItem::remove() {
-  RemoveCommand *remove = new RemoveCommand(this);
-  remove->redo();
+void ViewItem::edit() {
+
+  QList<QGraphicsItem*> list = scene()->selectedItems();
+  if (!list.isEmpty())
+    ViewItemDialog::self()->show(list);
 }
 
 
+void ViewItem::layout() {
+
+  ViewItem *viewItem = new ViewItem(parentView());
+  parentView()->scene()->addItem(viewItem);
+  viewItem->setZValue(1);
+
+  ViewGridLayout *layout = new ViewGridLayout(viewItem);
+
+  QRectF itemRect;
+
+  int column = 0;
+
+  QList<QGraphicsItem*> list = scene()->selectedItems();
+  foreach (QGraphicsItem *item, list) {
+    item->setParentItem(viewItem);
+    layout->addViewItem(static_cast<ViewItem*>(item), 0, column++);
+    itemRect = itemRect.united(item->boundingRect());
+  }
+
+  viewItem->setPos(itemRect.topLeft());
+  viewItem->setViewRect(QRectF(QPointF(0, 0), itemRect.size()));
+}
+
+
 void ViewItem::raise() {
   RaiseCommand *up = new RaiseCommand(this);
   up->redo();
@@ -376,11 +403,9 @@
 }
 
 
-void ViewItem::edit() {
-
-  QList<QGraphicsItem*> list = scene()->selectedItems();
-  if (!list.isEmpty())
-    ViewItemDialog::self()->show(list);
+void ViewItem::remove() {
+  RemoveCommand *remove = new RemoveCommand(this);
+  remove->redo();
 }
 
 
@@ -421,6 +446,9 @@
   QAction *editAction = menu.addAction(tr("Edit"));
   connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
 
+  QAction *layoutAction = menu.addAction(tr("Layout"));
+  connect(layoutAction, SIGNAL(triggered()), this, SLOT(layout()));
+
   QAction *raiseAction = menu.addAction(tr("Raise"));
   connect(raiseAction, SIGNAL(triggered()), this, SLOT(raise()));
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #708349:708350
@@ -91,10 +91,11 @@
 
 /*FIXME these should be made private for only undo commands to access*/
 public Q_SLOTS:
-  void remove();
+  void edit();
+  void layout();
   void raise();
   void lower();
-  void edit();
+  void remove();
   void resizeTopLeft(const QPointF &offset);
   void resizeTopRight(const QPointF &offset);
   void resizeBottomLeft(const QPointF &offset);


More information about the Kst mailing list