64 QGraphicsItem* parent)
68 , m_dispatcher{m_context.commandStack}
70 setAcceptedMouseButtons(Qt::LeftButton);
71 setFlag(ItemHasNoContents,
true);
72 this->setAcceptHoverEvents(
true);
78 tr(
"Comment box\nPut the text you want in here by double-clicking !"));
80 connect(m_textItem->document(), &QTextDocument::contentsChanged,
this, [&]() {
81 this->prepareGeometryChange();
83 auto other = m_textItem->toHtml().toStdString();
84 if(auto v = value_inlet->value(); ossia::convert<std::string>(v) != other)
85 m_dispatcher.submit(*value_inlet, other);
87 QSizeF sz = m_textItem->boundingRect().size();
89 ((Process::ProcessModel&)m_process).setSize(sz);
90 }, Qt::QueuedConnection);
99 value_inlet, &Process::ControlInlet::executionValueChanged,
this,
100 [
this](
const ossia::value& v) { update(); });
102 value_inlet, &Process::ControlInlet::valueChanged,
this, &Layer::updateText);
103 updateText(value_inlet->value());
105 connect(m_textItem, &score::TextItem::focusOut,
this, &Layer::focusOut);
111 void updateText(
const ossia::value& v)
113 const auto& str = ossia::convert<std::string>(v);
114 const auto& qstr = QString::fromUtf8(str);
116 if(qstr != m_textItem->toHtml())
117 this->m_textItem->setHtml(qstr);
120 void reset() { update(); }
122 void paint_impl(QPainter* p)
const override { }
124 void mousePressEvent(QGraphicsSceneMouseEvent* event)
override
126 if(event->button() == Qt::MouseButton::LeftButton)
128 auto t = m_lastClick.elapsed();
129 if(t > QApplication::doubleClickInterval())
132 m_lastClick.restart();
138 m_lastClick.restart();
145 void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
146 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
147 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* evt)
override { focusOnText(); }
151 if(m_textItem->textInteractionFlags() == Qt::NoTextInteraction)
153 m_textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
154 m_textItem->setFocus(Qt::MouseFocusReason);
155 QTextCursor c = m_textItem->textCursor();
156 c.select(QTextCursor::Document);
157 m_textItem->setTextCursor(c);
163 m_textItem->setTextInteractionFlags(Qt::NoTextInteraction);
164 QTextCursor c = m_textItem->textCursor();
166 m_textItem->setTextCursor(c);
168 m_dispatcher.commit();
171 QElapsedTimer m_lastClick{};