void LabelItemDialog::saveDimensions(ViewItem *viewitem) { Q_ASSERT(viewitem); LabelItem *item = qobject_cast<LabelItem*>(viewitem); Q_ASSERT(item); QPointF xy(_labelDimensionsTab->x(),_labelDimensionsTab->y()); qreal theta = _labelDimensionsTab->rotation(); bool fix_left = _labelDimensionsTab->fixLeft(); if (_labelDimensionsTab->lockPosToData() && item->dataPosLockable()) { QRectF dr = item->dataRelativeRect(); if (fix_left) { dr.moveTopLeft(xy); item->setFixLeft(true); } else { dr.moveBottomRight(xy); item->setFixLeft(false); } item->setDataRelativeRect(dr); bool lockPosToData = _labelDimensionsTab->lockPosToDataDirty() ? _labelDimensionsTab->lockPosToData() : item->lockPosToData(); item->setLockPosToData(lockPosToData); item->applyDataLockedDimensions(); } else { QRectF parentRect = item->parentRect(); qreal parentWidth = parentRect.width(); qreal parentHeight = parentRect.height(); qreal parentX = parentRect.x(); qreal parentY = parentRect.y(); bool lockPosToData = _labelDimensionsTab->lockPosToDataDirty() ? _labelDimensionsTab->lockPosToData() : item->lockPosToData(); item->setLockPosToData(lockPosToData); qreal width = item->rect().width(); qreal height = item->rect().height(); item->setPos(parentX + xy.x()*parentWidth, parentY + xy.y()*parentHeight); if (fix_left) { item->setViewRect(0,-height, width, height); item->setFixLeft(true); } else { item->setViewRect(-width,-height, width, height); item->setFixLeft(false); } } QTransform transform; transform.rotate(theta); item->setTransform(transform); item->updateRelativeSize(true); if (_saveAsDefault->isChecked()) { _dialogDefaults->setValue(item->staticDefaultsGroupName()+"/fixLeft",_labelDimensionsTab->fixLeft()); } }
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(); }