[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Thu Sep 13 19:57:16 CEST 2007
SVN commit 712130 by treat:
* Add gridlayouthelper classes adapted from qt designer.
* Hook up the gridlayouthelper so that our items are now
automatically placed in a grid characterized by their relative
positions and geometries.
A gridlayouthelper.cpp [License: GPL (v2+)]
A gridlayouthelper.h [License: GPL (v2+)]
M +2 -0 libkstapp.pro
M +42 -6 viewitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #712129:712130
@@ -35,6 +35,7 @@
exportgraphicsdialog.cpp \
filltab.cpp \
graphicsfactory.cpp \
+ gridlayouthelper.cpp \
labelitem.cpp \
labelrenderer.cpp \
layouttab.cpp \
@@ -79,6 +80,7 @@
exportgraphicsdialog.h \
filltab.h \
graphicsfactory.h \
+ gridlayouthelper.h \
labelitem.h \
labelrenderer.h \
layouttab.h \
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #712129:712130
@@ -15,6 +15,8 @@
#include "viewitemdialog.h"
#include "viewgridlayout.h"
+#include "gridlayouthelper.h"
+
#include <math.h>
#include <QMenu>
@@ -1232,15 +1234,32 @@
void LayoutCommand::redo() {
ViewGridLayout *layout = new ViewGridLayout(_item);
- int column = 0;
-
+ QList<ViewItem*> viewItems;
QList<QGraphicsItem*> list = _item->QGraphicsItem::children();
foreach (QGraphicsItem *item, list) {
ViewItem *viewItem = dynamic_cast<ViewItem*>(item);
if (!viewItem)
continue;
- layout->addViewItem(viewItem, 0, column++);
+ viewItems.append(viewItem);
}
+
+ Grid *grid = Grid::buildGrid(viewItems);
+
+ Q_ASSERT(grid);
+
+ foreach (ViewItem *v, viewItems) {
+ int r = 0, c = 0, rs = 0, cs = 0;
+ if (grid->locateWidget(v, r, c, rs, cs)) {
+ if (rs * cs == 1) {
+ layout->addViewItem(v, r, c, 1, 1);
+ } else {
+ layout->addViewItem(v, r, c, rs, cs);
+ }
+ } else {
+ qDebug() << "ooops, viewItem does not fit in layout" << endl;
+ }
+ }
+
layout->update();
}
@@ -1248,15 +1267,32 @@
void BreakLayoutCommand::undo() {
ViewGridLayout *layout = new ViewGridLayout(_item);
- int column = 0;
-
+ QList<ViewItem*> viewItems;
QList<QGraphicsItem*> list = _item->QGraphicsItem::children();
foreach (QGraphicsItem *item, list) {
ViewItem *viewItem = dynamic_cast<ViewItem*>(item);
if (!viewItem)
continue;
- layout->addViewItem(viewItem, 0, column++);
+ viewItems.append(viewItem);
}
+
+ Grid *grid = Grid::buildGrid(viewItems);
+
+ Q_ASSERT(grid);
+
+ foreach (ViewItem *v, viewItems) {
+ int r = 0, c = 0, rs = 0, cs = 0;
+ if (grid->locateWidget(v, r, c, rs, cs)) {
+ if (rs * cs == 1) {
+ layout->addViewItem(v, r, c, 1, 1);
+ } else {
+ layout->addViewItem(v, r, c, rs, cs);
+ }
+ } else {
+ qDebug() << "ooops, viewItem does not fit in layout" << endl;
+ }
+ }
+
layout->update();
}
More information about the Kst
mailing list