node kept inside the scene done

master
Denes Matetelki 14 years ago
parent 28528963a8
commit c10b56fe63

@ -59,6 +59,7 @@ GraphWidget::GraphWidget(QWidget *parent) :
m_activeNode = node1;
m_activeNode->setFocus();
}
QGraphicsScene *GraphWidget::getScene()

@ -35,46 +35,36 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
qDebug() << __PRETTY_FUNCTION__;
switch (change) {
case ItemPositionHasChanged:
foreach (Edge *edge, m_edgeList) edge->adjust();
break;
default:
break;
case ItemPositionChange:
if (change == ItemPositionChange && scene()) {
// value is the new position.
QPointF newPos = value.toPointF();
QRectF rect (scene()->sceneRect().topLeft(),
scene()->sceneRect().bottomRight()-boundingRect().bottomRight());
if (!rect.contains(newPos))
{
// Keep the item inside the scene rect.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
return newPos;
}
}
break;
case ItemPositionHasChanged:
foreach (Edge *edge, m_edgeList) edge->adjust();
break;
default:
break;
};
return QGraphicsItem::itemChange(change, value);
}
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
prevpt = event->pos();
update();
QGraphicsTextItem::mousePressEvent(event);
}
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
if (!scene()->sceneRect().contains(sceneBoundingRect()))
{
setPos(prevpt);
}
update();
QGraphicsTextItem::mouseReleaseEvent(event);
}
void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
QGraphicsTextItem::mouseMoveEvent(event);
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
{
qDebug() << __PRETTY_FUNCTION__;
@ -85,6 +75,4 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
painter->drawRect(QRect(boundingRect().topLeft().toPoint(),
boundingRect().bottomRight().toPoint() -
QPoint(1,1)));
prevpt = pos();
}

@ -11,23 +11,21 @@ class GraphWidget;
class Node : public QGraphicsTextItem
{
public:
Node(GraphWidget *graphWidget = 0);
void addEdge(Edge *edge);
QList<Edge *> edges() const;
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QList<Edge *> m_edgeList;
GraphWidget *m_graph;
QPointF prevpt;
};
#endif // NODE_H

@ -182,7 +182,7 @@
<value key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QString"></value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">qtmindmap.pro</value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">true</value>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value>
<valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
<value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
<value key="RunConfiguration.QmlDebugServerPort" type="uint">3768</value>

Loading…
Cancel
Save