ScriptEditorItem::ScriptEditorItem(ScriptDatum* datum, Canvas* canvas) : QGraphicsTextItem("HELLO WORLD"), datum(datum), border(10), close(new ScriptEditorCloseButton(this)), move(new ScriptEditorMoveButton(this)) { QFont font; font.setFamily("Courier"); setFont(font); canvas->scene->addItem(this); new SyntaxHighlighter(document()); setDefaultTextColor(Colors::base04); setTextInteractionFlags(Qt::TextEditorInteraction); connect(document(), SIGNAL(contentsChanged()), this, SLOT(onTextChanged())); connect(datum, SIGNAL(changed()), this, SLOT(onDatumChanged())); connect(datum, SIGNAL(destroyed()), this, SLOT(deleteLater())); onDatumChanged(); // update tooltip and text setZValue(3); }
void DatumTextItem::setAsTitle() { background = Colors::base03; foreground = Colors::base06; auto f = font(); f.setBold(true); setFont(f); // Allow this item to grow horizontally forever setTextWidth(-1); // Force a redraw onDatumChanged(); }
DatumTextItem::DatumTextItem(Datum* datum, QGraphicsItem* parent) : QGraphicsTextItem(parent), d(datum), txt(document()), background(Colors::base02), foreground(Colors::base04), border(background) { setTextInteractionFlags(Qt::TextEditorInteraction); setTextWidth(150); connect(datum, &Datum::changed, this, &DatumTextItem::onDatumChanged); onDatumChanged(); bbox = boundingRect(); connect(txt, &QTextDocument::contentsChanged, this, &DatumTextItem::onTextChanged); connect(document(), &QTextDocument::undoCommandAdded, this, &DatumTextItem::onUndoCommandAdded); installEventFilter(this); }