94 QGraphicsItem* parent)
98 , m_dispatcher{m_context.commandStack}
100 setAcceptedMouseButtons(Qt::LeftButton);
101 setFlag(ItemHasNoContents,
true);
102 this->setAcceptHoverEvents(
true);
105 if(process.inlets().size() > 1)
106 reflow_inlet = qobject_cast<Process::ControlInlet*>(process.inlets()[1]);
111 tr(
"Comment box\nPut the text you want in here by double-clicking !"));
113 connect(m_textItem->document(), &QTextDocument::contentsChanged,
this, [&]() {
114 this->prepareGeometryChange();
116 auto other = m_textItem->toHtml().toStdString();
117 if(auto v = value_inlet->value(); ossia::convert<std::string>(v) != other)
118 m_dispatcher.submit(*value_inlet, other);
125 QSizeF sz = m_textItem->boundingRect().size();
127 ((Process::ProcessModel&)m_process).setSize(sz);
129 }, Qt::QueuedConnection);
138 value_inlet, &Process::ControlInlet::executionValueChanged,
this,
139 [
this](
const ossia::value& v) { update(); });
141 value_inlet, &Process::ControlInlet::valueChanged,
this, &Layer::updateText);
142 updateText(value_inlet->value());
144 connect(m_textItem, &score::TextItem::focusOut,
this, &Layer::focusOut);
149 reflow_inlet, &Process::ControlInlet::valueChanged,
this,
150 [
this](
const ossia::value&) { applyReflow(); });
152 &process, &Process::ProcessModel::sizeChanged,
this,
153 [
this](QSizeF) { applyReflow(); });
158 void updateText(
const ossia::value& v)
160 const auto& str = ossia::convert<std::string>(v);
161 const auto& qstr = QString::fromUtf8(str);
163 if(qstr != m_textItem->toHtml())
164 this->m_textItem->setHtml(qstr);
167 bool reflowEnabled()
const
169 return reflow_inlet && ossia::convert<bool>(reflow_inlet->value());
174 prepareGeometryChange();
176 *m_textItem->document(),
177 reflowEnabled() ? m_process.size().width() - 2. : -1.);
180 void reset() { update(); }
182 void paint_impl(QPainter* p)
const override { }
184 void mousePressEvent(QGraphicsSceneMouseEvent* event)
override
186 if(event->button() == Qt::MouseButton::LeftButton)
188 auto t = m_lastClick.elapsed();
189 if(t > QApplication::doubleClickInterval())
192 m_lastClick.restart();
198 m_lastClick.restart();
205 void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
206 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
override {
event->accept(); }
207 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* evt)
override { focusOnText(); }
211 if(m_textItem->textInteractionFlags() == Qt::NoTextInteraction)
213 m_textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
214 m_textItem->setFocus(Qt::MouseFocusReason);
215 QTextCursor c = m_textItem->textCursor();
216 c.select(QTextCursor::Document);
217 m_textItem->setTextCursor(c);
223 m_textItem->setTextInteractionFlags(Qt::NoTextInteraction);
224 QTextCursor c = m_textItem->textCursor();
226 m_textItem->setTextCursor(c);
228 m_dispatcher.commit();
231 QElapsedTimer m_lastClick{};