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()); } }
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(); }