void BoundaryItem::updateGeometry()
{
    prepareGeometryChange();

    QSizeF geometry = calcMinimumGeometry();
    qreal width = geometry.width();
    qreal height = geometry.height();

    qreal text_width = 0.0;
    qreal text_height = 0.0;
    if (_text_item) {
        _text_item->setTextWidth(-1);
        QSizeF text_size = _text_item->document()->size();
        text_width = text_size.width();
        text_height = text_size.height();
    }

    QRectF boundary_rect = _boundary->getRect();
    if (boundary_rect.width() > width) {
        width = boundary_rect.width();
    }
    if (boundary_rect.height() > height) {
        height = boundary_rect.height();
    }

    // update sizes and positions
    double left = -width / 2.0;
    double top = -height / 2.0;

    setPos(_boundary->getPos());

    QRectF rect(left, top, width, height);

    // the object is updated without calling DiagramController intentionally.
    // attribute rect is not a real attribute stored on DObject but
    // a backup for the graphics item used for manual resized and persistency.
    _boundary->setRect(rect);

    if (_border_item) {
        _border_item->setRect(rect);
    }

    if (_no_text_item) {
        _no_text_item->setRect(QRectF(-text_width / 2, top + CONTENTS_BORDER_VERTICAL, text_width, text_height));
    }

    if (_text_item) {
        _text_item->setPos(-text_width / 2.0, top + CONTENTS_BORDER_VERTICAL);
    }

    updateSelectionMarkerGeometry(rect);
}
void AnnotationItem::updateGeometry()
{
    prepareGeometryChange();

    QSizeF geometry = calcMinimumGeometry();
    qreal width = geometry.width();
    qreal height = geometry.height();

    if (getAnnotation()->hasAutoSize()) {
        if (_text_item) {
            _text_item->setTextWidth(-1);
            QSizeF text_size = _text_item->document()->size();
            width = text_size.width() + 2 * CONTENTS_BORDER_HORIZONTAL;
            height = text_size.height() + 2 * CONTENTS_BORDER_VERTICAL;
        }
    } else {
        QRectF rect = getAnnotation()->getRect();
        width = rect.width();
        if (_text_item) {
            _text_item->setTextWidth(width - 2 * CONTENTS_BORDER_HORIZONTAL);
            height = _text_item->document()->size().height() + 2 * CONTENTS_BORDER_VERTICAL;
        }
    }

    // update sizes and positions
    double left = 0.0;
    double top = 0.0;

    setPos(getAnnotation()->getPos());

    QRectF rect(left, top, width, height);

    // the object is updated without calling DiagramController intentionally.
    // attribute rect is not a real attribute stored on DObject but
    // a backup for the graphics item used for manual resized and persistency.
    getAnnotation()->setRect(rect);

    if (_no_text_item) {
        _no_text_item->setRect(rect);
    }

    if (_text_item) {
        _text_item->setPos(left + CONTENTS_BORDER_HORIZONTAL, top + CONTENTS_BORDER_VERTICAL);
    }

    updateSelectionMarkerGeometry(rect);
}
Exemple #3
0
void DiagramItem::updateGeometry()
{
    prepareGeometryChange();

    // calc width and height
    double width = 0.0;
    double height = 0.0;

    QSizeF geometry = calcMinimumGeometry();
    width = geometry.width();
    height = geometry.height();

    if (object()->isAutoSized()) {
        if (!m_customIcon) {
            if (width < MINIMUM_AUTO_WIDTH)
                width = MINIMUM_AUTO_WIDTH;
            if (height < MINIMUM_AUTO_HEIGHT)
                height = MINIMUM_AUTO_HEIGHT;
        }
    } else {
        QRectF rect = object()->rect();
        if (rect.width() > width)
            width = rect.width();
        if (rect.height() > height)
            height = rect.height();
    }

    // update sizes and positions
    double left = -width / 2.0;
    double top = -height / 2.0;
    double y = top;

    setPos(object()->pos());

    QRectF rect(left, top, width, height);

    // the object is updated without calling DiagramController intentionally.
    // attribute rect is not a real attribute stored on DObject but
    // a backup for the graphics item used for manual resized and persistency.
    object()->setRect(rect);

    if (m_customIcon) {
        m_customIcon->setPos(left, top);
        m_customIcon->setActualSize(QSizeF(width, height));
        y += height;
    }

    if (m_body) {
        QPolygonF bodyPolygon;
        bodyPolygon
                << rect.topLeft()
                << rect.topRight() + QPointF(-FOLD_WIDTH, 0.0)
                << rect.topRight() + QPointF(0.0, FOLD_HEIGHT)
                << rect.bottomRight()
                << rect.bottomLeft();
        m_body->setPolygon(bodyPolygon);
    }
    if (m_fold) {
        QPolygonF foldPolygon;
        foldPolygon
                << rect.topRight() + QPointF(-FOLD_WIDTH, 0.0)
                << rect.topRight() + QPointF(0.0, FOLD_HEIGHT)
                << rect.topRight() + QPointF(-FOLD_WIDTH, FOLD_HEIGHT);
        m_fold->setPolygon(foldPolygon);
    }

    y += BODY_VERT_BORDER;
    if (!m_customIcon) {
        if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
            stereotypeIconItem->setPos(left + BODY_HORIZ_BORDER, y);
            y += std::max(FOLD_HEIGHT, stereotypeIconItem->boundingRect().height());
        } else {
            y += FOLD_HEIGHT;
        }
    }
    if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
        stereotypesItem->setPos(-stereotypesItem->boundingRect().width() / 2.0, y);
        y += stereotypesItem->boundingRect().height();
    }
    if (m_diagramName) {
        m_diagramName->setPos(-m_diagramName->boundingRect().width() / 2.0, y);
        y += m_diagramName->boundingRect().height();
    }

    updateSelectionMarkerGeometry(rect);
    updateAlignmentButtonsGeometry(rect);
    updateDepth();
}
Exemple #4
0
void ItemItem::updateGeometry()
{
    prepareGeometryChange();

    // calc width and height
    double width = 0.0;
    double height = 0.0;

    QSizeF geometry = calcMinimumGeometry();
    width = geometry.width();
    height = geometry.height();

    if (object()->isAutoSized()) {
        // nothing
    } else {
        QRectF rect = object()->rect();
        if (rect.width() > width)
            width = rect.width();
        if (rect.height() > height)
            height = rect.height();
    }

    // update sizes and positions
    double left = -width / 2.0;
    double right = width / 2.0;
    double top = -height / 2.0;
    double y = top;

    setPos(object()->pos());

    QRectF rect(left, top, width, height);

    // the object is updated without calling DiagramController intentionally.
    // attribute rect is not a real attribute stored on DObject but
    // a backup for the graphics item used for manual resized and persistency.
    object()->setRect(rect);

    if (m_customIcon) {
        m_customIcon->setPos(left, top);
        m_customIcon->setActualSize(QSizeF(width, height));
    }

    if (m_shape)
        m_shape->setRect(rect);

    if (m_customIcon) {
        switch (shapeIcon().textAlignment()) {
        case qmt::StereotypeIcon::TextalignBelow:
            y += height + BODY_VERT_BORDER;
            break;
        case qmt::StereotypeIcon::TextalignCenter:
        {
            double h = 0.0;
            if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem())
                h += stereotypeIconItem->boundingRect().height();
            if (StereotypesItem *stereotypesItem = this->stereotypesItem())
                h += stereotypesItem->boundingRect().height();
            if (nameItem())
                h += nameItem()->boundingRect().height();
            if (m_contextLabel)
                h += m_contextLabel->height();
            y = top + (height - h) / 2.0;
            break;
        }
        case qmt::StereotypeIcon::TextalignNone:
            // nothing to do
            break;
        case qmt::StereotypeIcon::TextalignTop:
            y += BODY_VERT_BORDER;
            break;
        }
    } else {
        y += BODY_VERT_BORDER;
    }
    if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
        stereotypeIconItem->setPos(right - stereotypeIconItem->boundingRect().width() - BODY_HORIZ_BORDER, y);
        y += stereotypeIconItem->boundingRect().height();
    }
    if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
        stereotypesItem->setPos(-stereotypesItem->boundingRect().width() / 2.0, y);
        y += stereotypesItem->boundingRect().height();
    }
    if (nameItem()) {
        nameItem()->setPos(-nameItem()->boundingRect().width() / 2.0, y);
        y += nameItem()->boundingRect().height();
    }
    if (m_contextLabel) {
        if (m_customIcon) {
            m_contextLabel->resetMaxWidth();
        } else {
            double maxContextWidth = width - 2 * BODY_HORIZ_BORDER;
            m_contextLabel->setMaxWidth(maxContextWidth);
        }
        m_contextLabel->setPos(-m_contextLabel->boundingRect().width() / 2.0, y);
    }

    updateSelectionMarkerGeometry(rect);
    updateRelationStarterGeometry(rect);
    updateAlignmentButtonsGeometry(rect);
    updateDepth();
}