ViewItem* LabelItemFactory::generateGraphics(QXmlStreamReader& xml, ObjectStore *store, View *view, ViewItem *parent) { LabelItem *rc = 0; while (!xml.atEnd()) { bool validTag = true; if (xml.isStartElement()) { if (!rc && xml.name().toString() == "label") { QXmlStreamAttributes attrs = xml.attributes(); QStringRef av; av = attrs.value("text"); if (!av.isNull()) { Q_ASSERT(!rc); rc = new LabelItem(view, av.toString()); if (parent) { rc->setParentViewItem(parent); // Add any new specialized LabelItem Properties here. } } av = attrs.value("scale"); if (!av.isNull()) { rc->setLabelScale(QVariant(av.toString()).toInt()); } av = attrs.value("color"); if (!av.isNull()) { rc->setLabelColor(QColor(av.toString())); } av = attrs.value("font"); if (!av.isNull()) { QFont font; font.fromString(av.toString()); rc->setLabelFont(font); } av = attrs.value("fixleft"); if (!av.isNull()) { rc->setFixLeft(QVariant(av.toString()).toBool()); } } else { Q_ASSERT(rc); if (!rc->parse(xml, validTag) && validTag) { ViewItem *i = GraphicsFactory::parse(xml, store, view, rc); if (!i) { } } } } else if (xml.isEndElement()) { if (xml.name().toString() == "label") { break; } else { validTag = false; } } if (!validTag) { qDebug("invalid Tag\n"); Debug::self()->log(QObject::tr("Error creating box object from Kst file."), Debug::Warning); delete rc; return 0; } xml.readNext(); } return rc; }
void CreateLabelCommand::createItem(QString *inText) { if (inText) { _item = new LabelItem(_view, *inText); } else { bool ok = false; QString text; LabelCreator dialog; if (dialog.exec() == QDialog::Accepted) { text = dialog.labelText(); ok = true; } if (!ok || text.isEmpty()) { return; } _item = new LabelItem(_view, text); LabelItem *label = qobject_cast<LabelItem*>(_item); label->setLabelScale(dialog.labelScale()); label->setLabelColor(dialog.labelColor()); label->setLabelFont(dialog.labelFont()); label->setFixLeft(dialog.fixLeft()); label->setLockPosToData(dialog.lockPosToData()); if (dialog.saveAsDefaults()) { label->saveAsDialogDefaults(); dialogDefaults().setValue(label->staticDefaultsGroupName()+"/fixLeft",dialog.fixLeft()); dialogDefaults().setValue(label->staticDefaultsGroupName()+"/lockPosToData",dialog.lockPosToData()); } } _item->view()->scene()->addItem(_item); _view->setCursor(Qt::IBeamCursor); CreateCommand::createItem(); }