cursor is movable with ctrl,cursor keys when editing a node

master
Denes Matetelki 14 years ago
parent 74ec242dd6
commit eb19562c6e

@ -129,7 +129,6 @@ QGraphicsScene *GraphWidget::getScene()
void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::keyPressEvent(QKeyEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
qDebug() << event->key();
// esc leaves node editing mode // esc leaves node editing mode
if (event->key() == Qt::Key_Escape && m_editingNode) if (event->key() == Qt::Key_Escape && m_editingNode)

@ -4,6 +4,7 @@
#include <QStyleOption> #include <QStyleOption>
#include <QDebug> #include <QDebug>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QTextDocument>
static const double Pi = 3.14159265358979323846264338327950288419717; static const double Pi = 3.14159265358979323846264338327950288419717;
@ -15,21 +16,12 @@ Node::Node(GraphWidget *parent) :
m_numberIsSpecial(false) m_numberIsSpecial(false)
{ {
setFlag(ItemIsMovable); setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges); setFlag(ItemSendsGeometryChanges);
// setTextInteractionFlags(Qt::TextBrowserInteraction);
// setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
// setZValue(1);
// shall I use system colors? // shall I use system colors?
setDefaultTextColor(QColor(0,0,0)); setDefaultTextColor(QColor(0,0,0));
// shall I set it after some spec key?
// setTextInteractionFlags(Qt::TextEditorInteraction);
setOpenExternalLinks(true);
} }
Node::~Node() Node::~Node()
@ -124,7 +116,6 @@ void Node::setActive(const bool &active)
} }
/// @note who shall set active: press or release?
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
m_graph->setActiveNode(this); m_graph->setActiveNode(this);
@ -224,15 +215,57 @@ void Node::setEditable(const bool &editable)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
//setFocusPolicy(Qt::StrongFocus); setTextInteractionFlags(
setTextInteractionFlags(editable ? Qt::TextEditable : Qt::NoTextInteraction); editable ?
Qt::TextEditable :
Qt::NoTextInteraction);
} }
void Node::keyPressEvent(QKeyEvent *event) void Node::keyPressEvent(QKeyEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
QGraphicsTextItem::keyPressEvent(event); // cursor movements
switch (event->key()) {
case Qt::Key_Left:
{
QTextCursor c = textCursor();
c.movePosition(
event->modifiers() == Qt::ControlModifier ?
QTextCursor::PreviousWord :
QTextCursor::PreviousCharacter);
setTextCursor(c);
break;
}
case Qt::Key_Right:
{
QTextCursor c = textCursor();
c.movePosition(
event->modifiers() == Qt::ControlModifier ?
QTextCursor::NextWord :
QTextCursor::NextCharacter);
setTextCursor(c);
break;
}
case Qt::Key_Up:
{
QTextCursor c = textCursor();
c.movePosition(QTextCursor::Up);
setTextCursor(c);
break;
}
case Qt::Key_Down:
{
QTextCursor c = textCursor();
c.movePosition(QTextCursor::Down);
setTextCursor(c);
break;
}
default:
foreach (EdgeElement element, m_edgeList) element.edge->adjust(); QGraphicsTextItem::keyPressEvent(event);
foreach (EdgeElement element, m_edgeList) element.edge->adjust();
}
} }

@ -2,6 +2,7 @@
#define NODE_H #define NODE_H
#include <QGraphicsTextItem> #include <QGraphicsTextItem>
#include <QTextCursor>
#include "edge.h" #include "edge.h"
#include "graphwidget.h" #include "graphwidget.h"
@ -55,6 +56,8 @@ private:
int m_number; int m_number;
bool m_hasBorder; bool m_hasBorder;
bool m_numberIsSpecial; bool m_numberIsSpecial;
// QTextCursor m_cursor;
}; };
#endif // NODE_H #endif // NODE_H

Loading…
Cancel
Save