first commit of scaleUp/Down as an undo-able command

master
Denes Matetelki 14 years ago
parent 24b4d965e0
commit 9195dba565

@ -23,6 +23,7 @@ struct UndoContext
qreal m_x;
qreal m_y;
bool m_subtree;
qreal m_scale;
UndoContext(GraphLogic *graphLogic = 0,
Node *activeNode = 0,
@ -35,7 +36,8 @@ struct UndoContext
bool secondary = false,
qreal x = 0,
qreal y = 0,
bool subtree = false)
bool subtree = false,
qreal scale = 0)
: m_graphLogic(graphLogic)
, m_activeNode(activeNode)
, m_hintNode(hintNode)
@ -48,6 +50,7 @@ struct UndoContext
, m_x(x)
, m_y(y)
, m_subtree(subtree)
, m_scale(scale)
{};
};
@ -180,5 +183,20 @@ private:
QMap<Node*, QColor> m_colorMap;
};
class ScaleNodeCommand : public BaseUndoClass
{
public:
ScaleNodeCommand(UndoContext context);
void undo();
void redo();
private:
QMap<Node*, qreal> m_scaleMap;
};
#endif // COMMANDS_H

@ -44,13 +44,13 @@ public:
public slots:
// commands from toolbars:
void insertNode(); // undo command
void removeNode(); // undo command
void nodeEdited(); /// @todo Rewrite as an undo action
void scaleUp(); /// @todo Rewrite as an undo action
void scaleDown(); /// @todo Rewrite as an undo action
void nodeColor(); // undo command
void nodeTextColor();
void insertNode(); // undo command
void removeNode(); // undo command
void nodeEdited(); /// @todo Rewrite as an undo action
void scaleUp(); // undo command
void scaleDown(); // undo command
void nodeColor(); // undo command
void nodeTextColor(); // undo command
void addEdge();
void removeEdge();
void hintMode();

@ -363,3 +363,32 @@ void NodeTextColorCommand::redo()
m_context.m_graphLogic->setActiveNode(m_activeNode);
}
ScaleNodeCommand::ScaleNodeCommand(UndoContext context)
: BaseUndoClass(context)
{
setText(QObject::tr("Changing scale of node: \"").append(
m_context.m_activeNode == m_context.m_nodeList->first() ?
QObject::tr("Base node") :
m_context.m_activeNode->toPlainText()).append("\"").
append(m_subtree ? QObject::tr(" with subtree") : QString("")));
foreach(Node *node, m_nodeList)
m_scaleMap[node] = node->scale();
}
void ScaleNodeCommand::undo()
{
foreach(Node *node, m_nodeList)
node->setScale(m_scaleMap[node], m_context.m_graphLogic->graphWidget()->sceneRect());
m_context.m_graphLogic->setActiveNode(m_activeNode);
}
void ScaleNodeCommand::redo()
{
foreach(Node *node, m_nodeList)
node->setScale(m_context.m_scale, m_context.m_graphLogic->graphWidget()->sceneRect());
m_context.m_graphLogic->setActiveNode(m_activeNode);
}

@ -416,17 +416,30 @@ void GraphLogic::scaleUp()
return;
}
if (QApplication::keyboardModifiers() & Qt::ControlModifier &&
QApplication::keyboardModifiers() & Qt::ShiftModifier)
{
QList <Node *> nodeList = m_activeNode->subtree();
foreach(Node *node, nodeList)
node->setScale(qreal(1.2), m_graphWidget->sceneRect());
}
else
{
m_activeNode->setScale(qreal(1.2),m_graphWidget->sceneRect());
}
bool subtree(QApplication::keyboardModifiers() & Qt::ControlModifier &&
QApplication::keyboardModifiers() & Qt::ShiftModifier);
UndoContext context;
context.m_graphLogic = this;
context.m_nodeList = &m_nodeList;
context.m_activeNode = m_activeNode;
context.m_scale = qreal(1.2);
context.m_subtree = subtree;
QUndoCommand *scaleNodeCommand = new ScaleNodeCommand(context);
m_undoStack->push(scaleNodeCommand);
// if (QApplication::keyboardModifiers() & Qt::ControlModifier &&
// QApplication::keyboardModifiers() & Qt::ShiftModifier)
// {
// QList <Node *> nodeList = m_activeNode->subtree();
// foreach(Node *node, nodeList)
// node->setScale(qreal(1.2), m_graphWidget->sceneRect());
// }
// else
// {
// m_activeNode->setScale(qreal(1.2),m_graphWidget->sceneRect());
// }
}
void GraphLogic::scaleDown()
@ -437,17 +450,31 @@ void GraphLogic::scaleDown()
return;
}
if (QApplication::keyboardModifiers() & Qt::ControlModifier &&
QApplication::keyboardModifiers() & Qt::ShiftModifier)
{
QList <Node *> nodeList = m_activeNode->subtree();
foreach(Node *node, nodeList)
node->setScale(qreal(1 / 1.2),m_graphWidget->sceneRect());
}
else
{
m_activeNode->setScale(qreal(1 / 1.2),m_graphWidget->sceneRect());
}
bool subtree(QApplication::keyboardModifiers() & Qt::ControlModifier &&
QApplication::keyboardModifiers() & Qt::ShiftModifier);
UndoContext context;
context.m_graphLogic = this;
context.m_nodeList = &m_nodeList;
context.m_activeNode = m_activeNode;
context.m_scale = qreal(1 / 1.2);
context.m_subtree = subtree;
QUndoCommand *scaleNodeCommand = new ScaleNodeCommand(context);
m_undoStack->push(scaleNodeCommand);
// if (QApplication::keyboardModifiers() & Qt::ControlModifier &&
// QApplication::keyboardModifiers() & Qt::ShiftModifier)
// {
// QList <Node *> nodeList = m_activeNode->subtree();
// foreach(Node *node, nodeList)
// node->setScale(qreal(1 / 1.2),m_graphWidget->sceneRect());
// }
// else
// {
// m_activeNode->setScale(qreal(1 / 1.2),m_graphWidget->sceneRect());
// }
}
void GraphLogic::nodeColor()

@ -221,9 +221,9 @@ QColor Node::textColor() const
void Node::setScale(const qreal &factor,const QRectF &sceneRect)
{
// limit scale to a reasonable size
if (factor * scale() < 0.4 ||
factor * scale() > 4 )
return;
// if (factor * scale() < 0.4 ||
// factor * scale() > 4 )
// return;
// cannot scale out the Node from the scene
if (!sceneRect.contains(pos() +

Loading…
Cancel
Save