in hint mode the whole node bg is changed, not just the text's

master
Denes Matetelki 14 years ago
parent eb19562c6e
commit e8731a8e14

@ -15,7 +15,7 @@ GraphWidget::GraphWidget(QWidget *parent) :
m_parent(parent), m_parent(parent),
m_activeNode(0), m_activeNode(0),
m_showingNodeNumbers(false), m_showingNodeNumbers(false),
m_followNode(0), m_hintNode(0),
m_editingNode(false) m_editingNode(false)
{ {
m_scene = new QGraphicsScene(this); m_scene = new QGraphicsScene(this);
@ -182,17 +182,17 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
scaleView(1 / qreal(1.2)); scaleView(1 / qreal(1.2));
break; break;
// follow: select a node vimperator style // Hint mode: select a node vimperator style
case Qt::Key_F: case Qt::Key_F:
m_showingNodeNumbers = !m_showingNodeNumbers; m_showingNodeNumbers = !m_showingNodeNumbers;
if (m_showingNodeNumbers) if (m_showingNodeNumbers)
m_followNumber.clear(); m_hintNumber.clear();
showingAllNodeNumbers(m_showingNodeNumbers); showingAllNodeNumbers(m_showingNodeNumbers);
if (m_showingNodeNumbers) if (m_showingNodeNumbers)
{ {
m_nodeList.first()->showNumber(0,true,true); m_nodeList.first()->showNumber(0,true,true);
m_followNode = m_nodeList.first(); m_hintNode = m_nodeList.first();
} }
break; break;
@ -225,9 +225,9 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
if (!m_showingNodeNumbers) if (!m_showingNodeNumbers)
break; break;
m_followNumber.append(QString::number(event->key()-48)); m_hintNumber.append(QString::number(event->key()-48));
showingAllNodeNumbers(false); showingAllNodeNumbers(false);
showingNodeNumbersBeginWithNumber(m_followNumber.toInt(), true); showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true);
break; break;
@ -236,19 +236,19 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
if (!m_showingNodeNumbers) if (!m_showingNodeNumbers)
break; break;
if (!m_followNumber.isEmpty()) if (!m_hintNumber.isEmpty())
{ {
m_followNumber.remove(m_followNumber.length()-1,1); m_hintNumber.remove(m_hintNumber.length()-1,1);
if (m_followNumber.isEmpty()) if (m_hintNumber.isEmpty())
{ {
showingAllNodeNumbers(true); showingAllNodeNumbers(true);
m_nodeList.first()->showNumber(0,true,true); m_nodeList.first()->showNumber(0,true,true);
m_followNode = m_nodeList.first(); m_hintNode = m_nodeList.first();
} }
else else
{ {
showingAllNodeNumbers(false); showingAllNodeNumbers(false);
showingNodeNumbersBeginWithNumber(m_followNumber.toInt(), true); showingNodeNumbersBeginWithNumber(m_hintNumber.toInt(), true);
} }
} }
break; break;
@ -257,12 +257,12 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
case Qt::Key_Return: case Qt::Key_Return:
case Qt::Key_Enter: case Qt::Key_Enter:
if (m_followNode && m_showingNodeNumbers) if (m_hintNode && m_showingNodeNumbers)
{ {
showingAllNodeNumbers(false); showingAllNodeNumbers(false);
if (m_activeNode) if (m_activeNode)
m_activeNode->setActive(false); m_activeNode->setActive(false);
m_activeNode = m_followNode; m_activeNode = m_hintNode;
m_activeNode->setActive(); m_activeNode->setActive();
m_showingNodeNumbers = false; m_showingNodeNumbers = false;
} }
@ -290,8 +290,8 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
if (m_activeNode) if (m_activeNode)
{ {
if (m_followNode==m_activeNode) if (m_hintNode==m_activeNode)
m_followNode=0; m_hintNode=0;
m_nodeList.removeAll(m_activeNode); m_nodeList.removeAll(m_activeNode);
delete m_activeNode; delete m_activeNode;
@ -310,6 +310,22 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
5000); // millisec 5000); // millisec
} }
// add edge to active node
case Qt::Key_A:
if (m_activeNode)
{
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Add node: select destination node"),
5000); // millisec
}
else
{
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("No active node."),
5000); // millisec
}
break; break;
default: default:
@ -402,7 +418,7 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number,
{ {
hit++; hit++;
dynamic_cast<Node*>(*it)->showNumber(i,show,true); dynamic_cast<Node*>(*it)->showNumber(i,show,true);
m_followNode = dynamic_cast<Node*>(*it); m_hintNode = dynamic_cast<Node*>(*it);
continue; continue;
} }
if (numberStartsWithNumber(i, number)) if (numberStartsWithNumber(i, number))
@ -417,7 +433,7 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number,
if (m_activeNode) if (m_activeNode)
m_activeNode->setActive(false); m_activeNode->setActive(false);
m_activeNode = m_followNode; m_activeNode = m_hintNode;
m_activeNode->setActive(); m_activeNode->setActive();
m_showingNodeNumbers = false; m_showingNodeNumbers = false;
} }

@ -42,8 +42,8 @@ private:
Node *m_activeNode; Node *m_activeNode;
QGraphicsScene *m_scene; QGraphicsScene *m_scene;
bool m_showingNodeNumbers; bool m_showingNodeNumbers;
QString m_followNumber; QString m_hintNumber;
Node *m_followNode; Node *m_hintNode;
bool m_editingNode; bool m_editingNode;
}; };

@ -84,10 +84,15 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) 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) if (m_number != -1)
{ {
painter->setBackground(m_numberIsSpecial ? Qt::green : Qt::yellow); painter->setPen(Qt::transparent);
painter->setBackgroundMode(Qt::OpaqueMode); 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); QGraphicsTextItem::paint(painter, option, w);
@ -109,6 +114,8 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
} }
} }
void Node::setActive(const bool &active) void Node::setActive(const bool &active)
{ {
m_isActive = active; m_isActive = active;
@ -223,14 +230,12 @@ void Node::setEditable(const bool &editable)
void Node::keyPressEvent(QKeyEvent *event) void Node::keyPressEvent(QKeyEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__;
// cursor movements // cursor movements
switch (event->key()) { switch (event->key()) {
case Qt::Key_Left: case Qt::Key_Left:
{ {
QTextCursor c = textCursor(); QTextCursor c = textCursor(); // textcursor() return just a copy
c.movePosition( c.movePosition(
event->modifiers() == Qt::ControlModifier ? event->modifiers() == Qt::ControlModifier ?
QTextCursor::PreviousWord : QTextCursor::PreviousWord :
@ -265,7 +270,10 @@ void Node::keyPressEvent(QKeyEvent *event)
default: default:
// not cursor movement
QGraphicsTextItem::keyPressEvent(event); QGraphicsTextItem::keyPressEvent(event);
foreach (EdgeElement element, m_edgeList) element.edge->adjust(); foreach (EdgeElement element, m_edgeList) element.edge->adjust();
} }
///@note leaving editing mode is done with esc, handled by graphwidget
} }

Loading…
Cancel
Save