[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Thu May 14 16:06:17 CEST 2009
SVN commit 967950 by fenton:
Add saving of View size and resizing of ViewItem if View size does not match on reload.
M +14 -0 document.cpp
M +15 -1 view.cpp
M +1 -0 view.h
M +40 -16 viewitem.cpp
M +9 -2 viewitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #967949:967950
@@ -162,6 +162,7 @@
i--;
}
View *currentView = 0;
+ QRectF currentSceneRect;
QXmlStreamReader xml;
xml.setDevice(&f);
@@ -222,6 +223,16 @@
int idx = _win->tabWidget()->indexOf(currentView);
_win->tabWidget()->setTabText(idx, nm.toString());
}
+ qreal width, height;
+ QStringRef string = attrs.value("width");
+ if (!string.isNull()) {
+ width = string.toString().toDouble();
+ }
+ string = attrs.value("height");
+ if (!string.isNull()) {
+ height = string.toString().toDouble();
+ }
+ currentSceneRect = QRectF(QPointF(0, 0), QSizeF(width, height));
state = View;
} else {
malformed();
@@ -258,6 +269,9 @@
}
break;
} else if (n == "view") {
+ if (currentView->sceneRect() != currentSceneRect) {
+ currentView->forceChildResize(currentSceneRect, currentView->sceneRect());
+ }
state = Graphics;
} else if (n == "data") {
state = Unknown;
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #967949:967950
@@ -128,7 +128,8 @@
void View::save(QXmlStreamWriter &xml) {
QList<QGraphicsItem*> items = scene()->items();
-
+ xml.writeAttribute("width", QVariant(sceneRect().width()).toString());
+ xml.writeAttribute("height", QVariant(sceneRect().height()).toString());
foreach(QGraphicsItem* viewItem, items) {
if (!viewItem->parentItem()) {
qgraphicsitem_cast<ViewItem*>(viewItem)->save(xml);
@@ -364,6 +365,19 @@
}
+void View::forceChildResize(QRectF oldRect, QRectF newRect) {
+ foreach (QGraphicsItem *item, items()) {
+ if (item->parentItem())
+ continue;
+
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
+ Q_ASSERT(viewItem);
+
+ viewItem->updateChildGeometry(oldRect, newRect);
+ }
+}
+
+
void View::updateBrush() {
if (!ApplicationSettings::self()->gradientStops().empty()) {
QLinearGradient l(0.0, height() - 4.0, 0.0, 0.0);
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #967949:967950
@@ -109,6 +109,7 @@
void appendToLayout(CurvePlacement::Layout layout, ViewItem* item, int columns = 0);
void createCustomLayout();
void viewChanged();
+ void forceChildResize(QRectF oldRect, QRectF newRect);
protected:
bool event(QEvent *event);
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #967949:967950
@@ -127,6 +127,14 @@
xml.writeAttribute("width", QVariant(viewRect().width()).toString());
xml.writeAttribute("height", QVariant(viewRect().height()).toString());
xml.writeEndElement();
+ xml.writeStartElement("relativesize");
+ xml.writeAttribute("width", QVariant(_parentRelativeWidth).toString());
+ xml.writeAttribute("height", QVariant(_parentRelativeHeight).toString());
+ xml.writeAttribute("centerx", QVariant(_parentRelativeCenter.x()).toString());
+ xml.writeAttribute("centery", QVariant(_parentRelativeCenter.y()).toString());
+ xml.writeAttribute("posx", QVariant(_parentRelativePosition.x()).toString());
+ xml.writeAttribute("posy", QVariant(_parentRelativePosition.y()).toString());
+ xml.writeEndElement();
xml.writeStartElement("transform");
xml.writeAttribute("m11", QVariant(transform().m11()).toString());
xml.writeAttribute("m12", QVariant(transform().m12()).toString());
@@ -289,7 +297,38 @@
if (!av.isNull()) {
y = av.toString().toDouble();
}
- setViewRect(QRectF(QPointF(x, y), QSizeF(w, h)));
+ setViewRect(QRectF(QPointF(x, y), QSizeF(w, h)));
+ } else if (xml.name().toString() == "relativesize") {
+ knownTag = true;
+ double width = 0, height = 0, centerx = 0, centery = 0, posx = 0, posy = 0;
+ av = attrs.value("width");
+ if (!av.isNull()) {
+ width = av.toString().toDouble();
+ }
+ av = attrs.value("height");
+ if (!av.isNull()) {
+ height = av.toString().toDouble();
+ }
+ av = attrs.value("centerx");
+ if (!av.isNull()) {
+ centerx = av.toString().toDouble();
+ }
+ av = attrs.value("centery");
+ if (!av.isNull()) {
+ centery = av.toString().toDouble();
+ }
+ av = attrs.value("posx");
+ if (!av.isNull()) {
+ posx = av.toString().toDouble();
+ }
+ av = attrs.value("posy");
+ if (!av.isNull()) {
+ posy = av.toString().toDouble();
+ }
+ setRelativeWidth(width);
+ setRelativeHeight(height);
+ setRelativeCenter(QPointF(centerx, centery));
+ setRelativePosition(QPointF(posx, posy));
} else if (xml.name().toString() == "transform") {
knownTag = true;
double m11 = 1.0, m12 = 0, m13 = 0, m21 = 0, m22 = 1.0, m23 = 0, m31 = 0, m32= 0, m33 = 1.0;
@@ -1462,21 +1501,6 @@
}
-QPointF ViewItem::relativeCenter() const {
- QPointF c;
- if (parentViewItem()) {
- c = mapToParent(rect().center()) - parentViewItem()->rect().topLeft();
- c = QPointF(c.x() / parentViewItem()->width(), c.y() / parentViewItem()->height());
- } else if (parentView()) {
- c = mapToParent(rect().center()) - parentView()->rect().topLeft();
- c = QPointF(c.x() / parentView()->width(), c.y() / parentView()->height());
- } else {
- c = QPointF(0, 0);
- }
- return c;
-}
-
-
void ViewItem::updateChildGeometry(const QRectF &oldParentRect, const QRectF &newParentRect) {
#if DEBUG_CHILD_GEOMETRY
qDebug() << "ViewItem::updateChildGeometry" << this << oldParentRect << newParentRect << endl;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #967949:967950
@@ -74,10 +74,17 @@
ViewItem *parentViewItem() const;
void setParent(ViewItem *parent);
virtual void updateRelativeSize();
+
qreal relativeHeight() const { return _parentRelativeHeight; }
+ void setRelativeHeight(const qreal height) { _parentRelativeHeight = height; }
qreal relativeWidth() const { return _parentRelativeWidth; }
- QPointF relativeCenter() const;
- QPointF relativePosition() const;
+ void setRelativeWidth(const qreal width) { _parentRelativeWidth = width; }
+
+ QPointF relativeCenter() const { return _parentRelativeCenter; }
+ void setRelativeCenter(const QPointF center) { _parentRelativeCenter = center; }
+ QPointF relativePosition() const { return _parentRelativePosition; }
+ void setRelativePosition(const QPointF pos) { _parentRelativePosition = pos; }
+
qreal rotationAngle() const;
GripMode gripMode() const;
More information about the Kst
mailing list