node losts focus during editing mode, jet remaining in editing mode bugfix

master
Denes Matetelki 14 years ago
parent 03b184fc1f
commit 919ec7fbe5

@ -220,15 +220,12 @@ void GraphWidget::insertPicture(const QString &picture)
void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::keyPressEvent(QKeyEvent *event)
{ {
// esc leaves node editing mode if (event->key() == Qt::Key_Escape)
if (event->key() == Qt::Key_Escape && m_editingNode)
{ {
m_activeNode->setEditable(false); nodeLostFocus();
m_editingNode = false;
return; return;
} }
// in node editing mode forward every key (except esc) to node if (m_editingNode)
else if (m_editingNode)
{ {
m_activeNode->keyPressEvent(event); m_activeNode->keyPressEvent(event);
return; return;
@ -257,28 +254,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Escape:
if (m_edgeAdding)
{
m_edgeAdding = false;
m_parent->statusBarMsg(tr("Edge adding cancelled."));
}
else if (m_edgeDeleting)
{
m_edgeDeleting = false;
m_parent->statusBarMsg(tr("Edge deleting cancelled."));
}
else if(m_showingNodeNumbers)
{
m_hintNumber.clear();
showingAllNodeNumbers(false);
m_showingNodeNumbers = false;
}
break;
// move sceve, or move node if modkey is ctrl // move sceve, or move node if modkey is ctrl
case Qt::Key_Up: case Qt::Key_Up:
case Qt::Key_Down: case Qt::Key_Down:
@ -703,6 +678,32 @@ void GraphWidget::nodeMoved(QGraphicsSceneMouseEvent *event)
node->setPos(node->pos() + event->scenePos() - event->lastScenePos()); node->setPos(node->pos() + event->scenePos() - event->lastScenePos());
} }
void GraphWidget::nodeLostFocus()
{
if (m_editingNode)
{
m_editingNode = false;
m_activeNode->setEditable(false);
m_activeNode->update();
}
else if (m_edgeAdding)
{
m_edgeAdding = false;
m_parent->statusBarMsg(tr("Edge adding cancelled."));
}
else if (m_edgeDeleting)
{
m_edgeDeleting = false;
m_parent->statusBarMsg(tr("Edge deleting cancelled."));
}
else if(m_showingNodeNumbers)
{
m_hintNumber.clear();
showingAllNodeNumbers(false);
m_showingNodeNumbers = false;
}
}
void GraphWidget::addEdge(Node *source, Node *destination) void GraphWidget::addEdge(Node *source, Node *destination)
{ {
if (destination == m_nodeList.first()) if (destination == m_nodeList.first())

@ -22,6 +22,7 @@ public:
void setActiveNodeEditable(); void setActiveNodeEditable();
void nodeSelected(Node *node); void nodeSelected(Node *node);
void nodeMoved(QGraphicsSceneMouseEvent *event); void nodeMoved(QGraphicsSceneMouseEvent *event);
void nodeLostFocus();
QList<Edge *> edges() const; QList<Edge *> edges() const;
void contentChanged(const bool &changed = true); void contentChanged(const bool &changed = true);

@ -476,6 +476,12 @@ QPainterPath Node::shape () const
return path; return path;
} }
void Node::focusOutEvent(QFocusEvent *event)
{
Q_UNUSED(event);
m_graph->nodeLostFocus();
}
double Node::doubleModulo(const double &devided, const double &devisor) double Node::doubleModulo(const double &devided, const double &devisor)
{ {
return devided - static_cast<double>(devisor * static_cast<int>(devided return devided - static_cast<double>(devisor * static_cast<int>(devided

@ -56,6 +56,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
QPainterPath shape () const; QPainterPath shape () const;
void focusOutEvent(QFocusEvent *event);
private: private:

Loading…
Cancel
Save