Commit b2c812c9 authored by Oliver Bock's avatar Oliver Bock
Browse files

Fixed component label item editing

* Using focus events only (in/out, new flag)
* Removed mouse (double) clicks for item selection (not needed anymore)
* Making it truely selectable whould have made deleting items from the scene (clearWorkbench) more complicated
* Also: moved label to top layer (like nodes)


git-svn-id: https://svn.origo.ethz.ch/fidelity@31 53d1999f-d1a8-4366-aa61-588fded17473
parent 89c82b5a
......@@ -25,39 +25,25 @@
Fidelity::GUI::ComponentLabelItem::ComponentLabelItem(QString& label, QGraphicsItem* parent) : QGraphicsTextItem(label, parent)
{
centerPosition();
setFlag(QGraphicsItem::ItemIsFocusable);
// Make sure label is on top of things
setZValue(1);
}
// Event handlers
void Fidelity::GUI::ComponentLabelItem::focusOutEvent(QFocusEvent* event)
void Fidelity::GUI::ComponentLabelItem::focusInEvent(QFocusEvent* event)
{
setTextInteractionFlags(Qt::NoTextInteraction);
setTextInteractionFlags(Qt::TextEditorInteraction);
QGraphicsTextItem::focusOutEvent(event);
}
void Fidelity::GUI::ComponentLabelItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
scene()->clearSelection();
QGraphicsTextItem::mousePressEvent(event);
setSelected(true);
}
void Fidelity::GUI::ComponentLabelItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
void Fidelity::GUI::ComponentLabelItem::focusOutEvent(QFocusEvent* event)
{
setTextInteractionFlags(Qt::TextEditorInteraction);
// Capture double click and forward as a single click (hence editing only occurs for double clicks)
QGraphicsSceneMouseEvent *mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress);
mouseEvent->setAccepted(true);
mouseEvent->setPos(event->pos());
mouseEvent->setScenePos(event->scenePos());
mouseEvent->setScreenPos(event->screenPos());
mouseEvent->setButtonDownPos(Qt::LeftButton, event->buttonDownPos(Qt::LeftButton));
mouseEvent->setButtonDownScreenPos(Qt::LeftButton, event->buttonDownScreenPos(Qt::LeftButton));
mouseEvent->setButtonDownScenePos(Qt::LeftButton, event->buttonDownScenePos(Qt::LeftButton));
mouseEvent->setWidget(event->widget());
QGraphicsTextItem::mousePressEvent(mouseEvent);
delete mouseEvent;
// TODO: any selected text should be "deselected", but how?!
setTextInteractionFlags(Qt::NoTextInteraction);
QGraphicsTextItem::focusOutEvent(event);
}
void Fidelity::GUI::ComponentLabelItem::keyPressEvent(QKeyEvent* event)
......
......@@ -60,22 +60,16 @@ signals:
protected:
/**
* Reimplementation of QGraphicsTextItem::focusOutEvent().<br>
* We override this method to inactivate the label for editing when loosing focus.
*/
void focusOutEvent(QFocusEvent* event);
/**
* Reimplementation of QGraphicsTextItem::mousePressEvent().<br>
* We override this method to properly/visually select the label.
*/
void mousePressEvent(QGraphicsSceneMouseEvent* event);
* Reimplementation of QGraphicsTextItem::focusInEvent().<br>
* We override this method to activate the label for editing when getting the focus.
*/
void focusInEvent(QFocusEvent* event);
/**
* Reimplementation of QGraphicsTextItem::mouseDoubleClickEvent().<br>
* We override this method to activate the label for editing on double click only.
* Reimplementation of QGraphicsTextItem::focusOutEvent().<br>
* We override this method to deactivate the label for editing when loosing the focus.
*/
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
void focusOutEvent(QFocusEvent* event);
/**
* Reimplementation of QGraphicsTextItem::keyPressEvent().<br>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment