示例#1
0
void AnnotationItem::update()
{
    QMT_CHECK(!m_isUpdating);
    m_isUpdating = true;

    prepareGeometryChange();

    const Style *style = adaptedStyle();

    // text
    if (!m_textItem) {
        m_textItem = new AnnotationTextItem(this);
        m_textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
        m_textItem->installSceneEventFilter(this);
        QObject::connect(m_textItem->document(), &QTextDocument::contentsChanged, m_textItem,
                         [=]() { this->onContentsChanged(); } );
    }
    m_textItem->setFont(style->normalFont());
    m_textItem->setDefaultTextColor(style->textBrush().color());
    if (!m_isChanged)
        m_textItem->setPlainText(annotation()->text());

    // item shown if annotation has no text and is not selected
    if (!m_noTextItem)
        m_noTextItem = new QGraphicsRectItem(this);
    m_noTextItem->setPen(QPen(QBrush(QColor(192, 192, 192)), 1, Qt::DashDotLine));
    m_noTextItem->setVisible(!isSelected() && m_textItem->document()->isEmpty());

    updateSelectionMarker();
    updateGeometry();
    setZValue(ANNOTATION_ITEMS_ZVALUE);

    m_isUpdating = false;
}
示例#2
0
void DiagramItem::update()
{
    prepareGeometryChange();
    updateStereotypeIconDisplay();

    const Style *style = adaptedStyle(stereotypeIconId());

    // custom icon
    if (stereotypeIconDisplay() == StereotypeIcon::DisplayIcon) {
        if (!m_customIcon)
            m_customIcon = new CustomIconItem(diagramSceneModel(), this);
        m_customIcon->setStereotypeIconId(stereotypeIconId());
        m_customIcon->setBaseSize(stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(), CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT));
        m_customIcon->setBrush(style->fillBrush());
        m_customIcon->setPen(style->outerLinePen());
        m_customIcon->setZValue(SHAPE_ZVALUE);
    } else if (m_customIcon) {
        m_customIcon->scene()->removeItem(m_customIcon);
        delete m_customIcon;
        m_customIcon = 0;
    }

    // shape
    if (!m_customIcon) {
        if (!m_body)
            m_body = new QGraphicsPolygonItem(this);
        m_body->setBrush(style->fillBrush());
        m_body->setPen(style->outerLinePen());
        m_body->setZValue(SHAPE_ZVALUE);
        if (!m_fold)
            m_fold = new QGraphicsPolygonItem(this);
        m_fold->setBrush(style->extraFillBrush());
        m_fold->setPen(style->outerLinePen());
        m_fold->setZValue(SHAPE_DETAILS_ZVALUE);
    } else {
        if (m_fold) {
            m_fold->scene()->removeItem(m_fold);
            delete m_fold;
            m_fold = 0;
        }
        if (m_body) {
            m_body->scene()->removeItem(m_body);
            delete m_body;
            m_body = 0;
        }
    }

    // stereotypes
    updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);

    // diagram name
    updateNameItem(style);

    updateSelectionMarker(m_customIcon);
    updateAlignmentButtons();
    updateGeometry();
}
示例#3
0
void BoundaryItem::update()
{
    QMT_CHECK(!_on_update);
    _on_update = true;

    prepareGeometryChange();

    const Style *style = getAdaptedStyle();

    // text
    if (!_text_item) {
        _text_item = new BoundaryTextItem(this);
        _text_item->setTextInteractionFlags(Qt::TextEditorInteraction);
        _text_item->installSceneEventFilter(this);
        QObject::connect(_text_item->document(), &QTextDocument::contentsChanged, _text_item,
                         [=]() { this->onContentsChanged(); } );
    }
    _text_item->setFont(style->getNormalFont());
    _text_item->setDefaultTextColor(style->getTextBrush().color());
    if (!_on_changed) {
        _text_item->setTextWidth(-1);
        _text_item->setPlainText(_boundary->getText());
    }

    // item shown if annotation has no text and is not selected
    if (_text_item->document()->isEmpty() && isSelected()) {
        if (!_no_text_item) {
            _no_text_item = new QGraphicsRectItem(this);
        }
        _no_text_item->setPen(QPen(QBrush(QColor(192, 192, 192)), 1, Qt::DashDotLine));
    } else if (_no_text_item) {
        _no_text_item->scene()->removeItem(_no_text_item);
        delete _no_text_item;
        _no_text_item = 0;
    }

    // item shown if annotation has no text and is not selected
    if (!_border_item) {
        _border_item = new QGraphicsRectItem(this);
    }
    _border_item->setPen(QPen(QBrush(Qt::black), 1, Qt::DashLine));

    updateSelectionMarker();

    updateGeometry();

    setZValue(BOUNDARY_ITEMS_ZVALUE);

    _on_update = false;
}