[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Fri Sep 14 17:56:11 CEST 2007
SVN commit 712508 by treat:
* Try to reparent at the end of the creation mode.
M +1 -0 lineitem.cpp
M +68 -65 viewitem.cpp
M +1 -3 viewitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #712507:712508
@@ -134,6 +134,7 @@
parentView()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself
parentView()->disconnect(this, SLOT(creationPolygonChanged(View::CreationEvent)));
parentView()->setMouseMode(View::Default);
+ maybeReparent();
emit creationComplete();
return;
}
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #712507:712508
@@ -470,6 +470,7 @@
parentView()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself
parentView()->disconnect(this, SLOT(creationPolygonChanged(View::CreationEvent)));
parentView()->setMouseMode(View::Default);
+ maybeReparent();
emit creationComplete();
return;
}
@@ -935,6 +936,72 @@
}
+bool ViewItem::maybeReparent() {
+ //First get a list of all items that collide with this one
+ QList<QGraphicsItem*> collisions = collidingItems(Qt::IntersectsItemShape);
+
+ bool topLevel = !parentItem();
+ QPointF scenePos = topLevel ? pos() : parentItem()->mapToScene(pos());
+
+#ifdef DEBUG_REPARENT
+ qDebug() << "maybeReparent" << this
+ << "topLevel:" << (topLevel ? "true" : "false")
+ << "scenePos:" << scenePos
+ << endl;
+#endif
+
+ //Doesn't collide then reparent to top-level
+ if (collisions.isEmpty() && !topLevel) {
+#ifdef DEBUG_REPARENT
+ qDebug() << "reparent to topLevel" << endl;
+#endif
+ setParentItem(0);
+ setPos(scenePos);
+ return true;
+ }
+
+ //Look for collisions that completely contain us
+ foreach (QGraphicsItem *item, collisions) {
+ ViewItem *viewItem = dynamic_cast<ViewItem*>(item);
+
+ if (!viewItem) /*bah*/
+ continue;
+
+ if (!viewItem->collidesWithItem(this, Qt::ContainsItemShape)) /*doesn't contain*/
+ continue;
+
+ if (parentItem() == viewItem) { /*already done*/
+#ifdef DEBUG_REPARENT
+ qDebug() << "already in containing parent" << endl;
+#endif
+ return false;
+ }
+
+ if (viewItem->layout()) /*don't crash existing layout*/
+ continue;
+
+#ifdef DEBUG_REPARENT
+ qDebug() << "reparent to" << viewItem << endl;
+#endif
+ setParentItem(viewItem);
+ setPos(viewItem->mapFromScene(scenePos));
+ return true;
+ }
+
+ //No suitable collisions then reparent to top-level
+ if (!topLevel) {
+#ifdef DEBUG_REPARENT
+ qDebug() << "reparent to topLevel" << endl;
+#endif
+ setParentItem(0);
+ setPos(scenePos);
+ return true;
+ }
+
+ return false;
+}
+
+
void ViewItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
if (parentView()->viewMode() == View::Data) {
event->ignore();
@@ -1073,71 +1140,6 @@
}
-bool ViewItem::maybeReparent() {
- //First get a list of all items that collide with this one
- QList<QGraphicsItem*> collisions = collidingItems(Qt::IntersectsItemShape);
-
- bool topLevel = !parentItem();
- QPointF scenePos = topLevel ? pos() : parentItem()->mapToScene(pos());
-
-#ifdef DEBUG_REPARENT
- qDebug() << "maybeReparent" << this
- << "topLevel:" << (topLevel ? "true" : "false")
- << "scenePos:" << scenePos
- << endl;
-#endif
-
- //Doesn't collide then reparent to top-level
- if (collisions.isEmpty() && !topLevel) {
-#ifdef DEBUG_REPARENT
- qDebug() << "reparent to topLevel" << endl;
-#endif
- setParentItem(0);
- setPos(scenePos);
- return true;
- }
-
- //Look for collisions that completely contain us
- foreach (QGraphicsItem *item, collisions) {
- ViewItem *viewItem = dynamic_cast<ViewItem*>(item);
-
- if (!viewItem) /*bah*/
- continue;
-
- if (!viewItem->collidesWithItem(this, Qt::ContainsItemShape)) /*doesn't contain*/
- continue;
-
- if (parentItem() == viewItem) { /*already done*/
-#ifdef DEBUG_REPARENT
- qDebug() << "already in containing parent" << endl;
-#endif
- return false;
- }
-
- if (viewItem->layout()) /*don't crash existing layout*/
- continue;
-
-#ifdef DEBUG_REPARENT
- qDebug() << "reparent to" << viewItem << endl;
-#endif
- setParentItem(viewItem);
- setPos(viewItem->mapFromScene(scenePos));
- return true;
- }
-
- //No suitable collisions then reparent to top-level
- if (!topLevel) {
-#ifdef DEBUG_REPARENT
- qDebug() << "reparent to topLevel" << endl;
-#endif
- setParentItem(0);
- setPos(scenePos);
- return true;
- }
-
- return false;
-}
-
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, ViewItem *viewItem) {
dbg.nospace() << viewItem->name();
@@ -1145,6 +1147,7 @@
}
#endif
+
ViewItemCommand::ViewItemCommand(const QString &text, bool addToStack, QUndoCommand *parent)
: QUndoCommand(text, parent), _item(kstApp->mainWindow()->tabWidget()->currentView()->currentViewItem()) {
if (addToStack)
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #712507:712508
@@ -126,6 +126,7 @@
bool transformToRect(const QPolygonF &from, const QPolygonF &to);
void rotateTowards(const QPointF &corner, const QPointF &point);
QPointF lockOffset(const QPointF &offset, qreal ratio, bool oddCorner) const;
+ bool maybeReparent();
protected Q_SLOTS:
virtual void creationPolygonChanged(View::CreationEvent event);
@@ -145,9 +146,6 @@
void viewMouseModeChanged(View::MouseMode oldMode);
private:
- bool maybeReparent();
-
-private:
MouseMode _mouseMode;
bool _hovering;
bool _lockAspectRatio;
More information about the Kst
mailing list