1 #ifndef GRAPH_ANALYSIS_GUI_ITEMS_EDGELABEL_HPP
2 #define GRAPH_ANALYSIS_GUI_ITEMS_EDGELABEL_HPP
4 #include <QGraphicsTextItem>
6 #include <base-logging/Logging.hpp>
26 EdgeLabel(
const std::string& label, QGraphicsItem* item)
27 : QGraphicsTextItem(QString(label.c_str()), item)
29 setFlags(QGraphicsTextItem::ItemIsSelectable | ItemIsFocusable);
30 setTextInteractionFlags(Qt::NoTextInteraction);
31 setAcceptDrops(
false);
41 if(on && textInteractionFlags() == Qt::NoTextInteraction)
43 setTextInteractionFlags(Qt::TextEditorInteraction);
44 setFocus(Qt::MouseFocusReason);
48 QTextCursor c = textCursor();
49 c.select(QTextCursor::Document);
53 }
else if(!on && textInteractionFlags() == Qt::TextEditorInteraction)
55 setTextInteractionFlags(Qt::NoTextInteraction);
56 QTextCursor c = this->textCursor();
58 this->setTextCursor(c);
72 QVariant
itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant& value)
74 if(change == QGraphicsItem::ItemSelectedChange)
76 LOG_DEBUG_S <<
"itemChange ' " << this->toPlainText().toStdString()
77 <<
"', selected: '" << value.toString().toStdString() <<
"'";
79 if(change == QGraphicsItem::ItemSelectedChange && textInteractionFlags() != Qt::NoTextInteraction && !value.toBool())
84 return QGraphicsTextItem::itemChange(change, value);
91 #endif // GRAPH_ANALYSIS_GUI_ITEMS_EDGELABEL_HPP