diff --git a/graphwidget.cpp b/graphwidget.cpp index 36c2da4..11ee2b0 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -15,7 +15,7 @@ GraphWidget::GraphWidget(QWidget *parent) : m_parent(parent), m_activeNode(0), m_showingNodeNumbers(false), - m_followNode(0), + m_hintNode(0), m_editingNode(false) { m_scene = new QGraphicsScene(this); @@ -182,17 +182,17 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) scaleView(1 / qreal(1.2)); break; - // follow: select a node vimperator style + // Hint mode: select a node vimperator style case Qt::Key_F: m_showingNodeNumbers = !m_showingNodeNumbers; if (m_showingNodeNumbers) - m_followNumber.clear(); + m_hintNumber.clear(); showingAllNodeNumbers(m_showingNodeNumbers); if (m_showingNodeNumbers) { m_nodeList.first()->showNumber(0,true,true); - m_followNode = m_nodeList.first(); + m_hintNode = m_nodeList.first(); } break; @@ -225,9 +225,9 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) if (!m_showingNodeNumbers) break; - m_followNumber.append(QString::number(event->key()-48)); + m_hintNumber.append(QString::number(event->key()-48)); showingAllNodeNumbers(false); - showingNodeNumbersBeginWithNumber(m_followNumber.toInt(), true); + showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true); break; @@ -236,19 +236,19 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) if (!m_showingNodeNumbers) break; - if (!m_followNumber.isEmpty()) + if (!m_hintNumber.isEmpty()) { - m_followNumber.remove(m_followNumber.length()-1,1); - if (m_followNumber.isEmpty()) + m_hintNumber.remove(m_hintNumber.length()-1,1); + if (m_hintNumber.isEmpty()) { showingAllNodeNumbers(true); m_nodeList.first()->showNumber(0,true,true); - m_followNode = m_nodeList.first(); + m_hintNode = m_nodeList.first(); } else { showingAllNodeNumbers(false); - showingNodeNumbersBeginWithNumber(m_followNumber.toInt(), true); + showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true); } } break; @@ -257,12 +257,12 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Return: case Qt::Key_Enter: - if (m_followNode && m_showingNodeNumbers) + if (m_hintNode && m_showingNodeNumbers) { showingAllNodeNumbers(false); if (m_activeNode) m_activeNode->setActive(false); - m_activeNode = m_followNode; + m_activeNode = m_hintNode; m_activeNode->setActive(); m_showingNodeNumbers = false; } @@ -290,8 +290,8 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) if (m_activeNode) { - if (m_followNode==m_activeNode) - m_followNode=0; + if (m_hintNode==m_activeNode) + m_hintNode=0; m_nodeList.removeAll(m_activeNode); delete m_activeNode; @@ -310,6 +310,22 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) 5000); // millisec } + // add edge to active node + case Qt::Key_A: + + if (m_activeNode) + { + dynamic_cast(m_parent)->getStatusBar()->showMessage( + tr("Add node: select destination node"), + 5000); // millisec + } + else + { + dynamic_cast(m_parent)->getStatusBar()->showMessage( + tr("No active node."), + 5000); // millisec + } + break; default: @@ -402,7 +418,7 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number, { hit++; dynamic_cast(*it)->showNumber(i,show,true); - m_followNode = dynamic_cast(*it); + m_hintNode = dynamic_cast(*it); continue; } if (numberStartsWithNumber(i, number)) @@ -417,7 +433,7 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number, if (m_activeNode) m_activeNode->setActive(false); - m_activeNode = m_followNode; + m_activeNode = m_hintNode; m_activeNode->setActive(); m_showingNodeNumbers = false; } diff --git a/graphwidget.h b/graphwidget.h index c5743a6..90cbe92 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -42,8 +42,8 @@ private: Node *m_activeNode; QGraphicsScene *m_scene; bool m_showingNodeNumbers; - QString m_followNumber; - Node *m_followNode; + QString m_hintNumber; + Node *m_hintNode; bool m_editingNode; }; diff --git a/node.cpp b/node.cpp index ad219c7..57da608 100644 --- a/node.cpp +++ b/node.cpp @@ -84,10 +84,15 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) { + // draw background in hint mode + /// @bug is there a 1pixel wide yellow line at the bottom of borderless item? if (m_number != -1) { - painter->setBackground(m_numberIsSpecial ? Qt::green : Qt::yellow); - painter->setBackgroundMode(Qt::OpaqueMode); + painter->setPen(Qt::transparent); + painter->setBrush(m_numberIsSpecial ? Qt::green : Qt::yellow); + painter->drawRect(QRect(boundingRect().topLeft().toPoint(), + boundingRect().bottomRight().toPoint())); + painter->setBrush(Qt::NoBrush); } QGraphicsTextItem::paint(painter, option, w); @@ -109,6 +114,8 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid } } + + void Node::setActive(const bool &active) { m_isActive = active; @@ -223,14 +230,12 @@ void Node::setEditable(const bool &editable) void Node::keyPressEvent(QKeyEvent *event) { - qDebug() << __PRETTY_FUNCTION__; - // cursor movements switch (event->key()) { case Qt::Key_Left: { - QTextCursor c = textCursor(); + QTextCursor c = textCursor(); // textcursor() return just a copy c.movePosition( event->modifiers() == Qt::ControlModifier ? QTextCursor::PreviousWord : @@ -265,7 +270,10 @@ void Node::keyPressEvent(QKeyEvent *event) default: + // not cursor movement QGraphicsTextItem::keyPressEvent(event); foreach (EdgeElement element, m_edgeList) element.edge->adjust(); } + + ///@note leaving editing mode is done with esc, handled by graphwidget }