65 QGraphicsItem* parent)
69 , m_dispatcher{m_context.commandStack}
71 setAcceptedMouseButtons(Qt::LeftButton);
72 setFlag(ItemHasNoContents,
true);
73 this->setAcceptHoverEvents(
true);
79 tr(
"Comment box\nPut the text you want in here by double-clicking !"));
81 connect(m_textItem->document(), &QTextDocument::contentsChanged,
this, [&]() {
82 this->prepareGeometryChange();
84 auto other = m_textItem->toHtml().toStdString();
85 if(auto v = value_inlet->value(); ossia::convert<std::string>(v) != other)
86 m_dispatcher.submit(*value_inlet, other);
88 QSizeF sz = m_textItem->boundingRect().size();
90 ((Process::ProcessModel&)m_process).setSize(sz);
91 }, Qt::QueuedConnection);
100 value_inlet, &Process::ControlInlet::executionValueChanged,
this,
101 [
this](
const ossia::value& v) { update(); });
103 value_inlet, &Process::ControlInlet::valueChanged,
this, &Layer::updateText);
104 updateText(value_inlet->value());
106 connect(m_textItem, &score::TextItem::focusOut,
this, &Layer::focusOut);
112 void updateText(
const ossia::value& v)
114 const auto& str = ossia::convert<std::string>(v);
115 const auto& qstr = QString::fromUtf8(str);
117 if(qstr != m_textItem->toHtml())
118 this->m_textItem->setHtml(qstr);
121 void reset() { update(); }
123 void paint_impl(QPainter* p)
const override { }
125 void mousePressEvent(QGraphicsSceneMouseEvent* event)
override
127 if(event->button() == Qt::MouseButton::LeftButton)
129 auto t = m_lastClick.elapsed();
130 if(t > QApplication::doubleClickInterval())
133 m_lastClick.restart();
139 m_lastClick.restart();
146 void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
147 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
148 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* evt)
override { focusOnText(); }
152 if(m_textItem->textInteractionFlags() == Qt::NoTextInteraction)
154 m_textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
155 m_textItem->setFocus(Qt::MouseFocusReason);
156 QTextCursor c = m_textItem->textCursor();
157 c.select(QTextCursor::Document);
158 m_textItem->setTextCursor(c);
164 m_textItem->setTextInteractionFlags(Qt::NoTextInteraction);
165 QTextCursor c = m_textItem->textCursor();
167 m_textItem->setTextCursor(c);
169 m_dispatcher.commit();
172 QElapsedTimer m_lastClick{};