forked from qt-creator/qt-creator
ModelEditor: Support text alignment with all object types
Change-Id: I9f67527ff21883194158f82039d3dcf513186150 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -478,25 +478,29 @@ QSizeF ClassItem::calcMinimumGeometry() const
|
||||
double height = 0.0;
|
||||
|
||||
if (m_customIcon) {
|
||||
return stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
QSizeF sz = stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
if (shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignTop
|
||||
&& shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignCenter)
|
||||
return sz;
|
||||
width = sz.width();
|
||||
}
|
||||
|
||||
height += BODY_VERT_BORDER;
|
||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||
width = std::max(width, stereotypeIconItem->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, stereotypeIconItem->boundingRect().width());
|
||||
height += stereotypeIconItem->boundingRect().height();
|
||||
}
|
||||
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
||||
width = std::max(width, stereotypesItem->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, stereotypesItem->boundingRect().width());
|
||||
height += stereotypesItem->boundingRect().height();
|
||||
}
|
||||
if (m_namespace) {
|
||||
width = std::max(width, m_namespace->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, m_namespace->boundingRect().width());
|
||||
height += m_namespace->boundingRect().height();
|
||||
}
|
||||
if (nameItem()) {
|
||||
width = std::max(width, nameItem()->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, nameItem()->boundingRect().width());
|
||||
height += nameItem()->boundingRect().height();
|
||||
}
|
||||
if (m_contextLabel)
|
||||
@@ -504,17 +508,19 @@ QSizeF ClassItem::calcMinimumGeometry() const
|
||||
if (m_attributesSeparator)
|
||||
height += 8.0;
|
||||
if (m_attributes) {
|
||||
width = std::max(width, m_attributes->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, m_attributes->boundingRect().width());
|
||||
height += m_attributes->boundingRect().height();
|
||||
}
|
||||
if (m_methodsSeparator)
|
||||
height += 8.0;
|
||||
if (m_methods) {
|
||||
width = std::max(width, m_methods->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, m_methods->boundingRect().width());
|
||||
height += m_methods->boundingRect().height();
|
||||
}
|
||||
height += BODY_VERT_BORDER;
|
||||
|
||||
width = BODY_HORIZ_BORDER + width + BODY_HORIZ_BORDER;
|
||||
|
||||
return GeometryUtilities::ensureMinimumRasterSize(QSizeF(width, height), 2 * RASTER_WIDTH, 2 * RASTER_HEIGHT);
|
||||
}
|
||||
|
||||
@@ -564,13 +570,40 @@ void ClassItem::updateGeometry()
|
||||
if (m_customIcon) {
|
||||
m_customIcon->setPos(left, top);
|
||||
m_customIcon->setActualSize(QSizeF(width, height));
|
||||
y += height;
|
||||
}
|
||||
|
||||
if (m_shape)
|
||||
m_shape->setRect(rect);
|
||||
|
||||
y += BODY_VERT_BORDER;
|
||||
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();
|
||||
|
@@ -214,7 +214,12 @@ QSizeF ComponentItem::calcMinimumGeometry() const
|
||||
double height = 0.0;
|
||||
|
||||
if (m_customIcon) {
|
||||
return stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(), CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
QSizeF sz = stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
if (shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignTop
|
||||
&& shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignCenter)
|
||||
return sz;
|
||||
width = sz.width();
|
||||
}
|
||||
|
||||
height += BODY_VERT_BORDER;
|
||||
@@ -286,7 +291,6 @@ void ComponentItem::updateGeometry()
|
||||
if (m_customIcon) {
|
||||
m_customIcon->setPos(left, top);
|
||||
m_customIcon->setActualSize(QSizeF(width, height));
|
||||
y += height;
|
||||
}
|
||||
|
||||
if (m_shape)
|
||||
@@ -304,7 +308,35 @@ void ComponentItem::updateGeometry()
|
||||
m_lowerRect->setPos(left - RECT_WIDTH * 0.5, top + UPPER_RECT_Y + RECT_HEIGHT + RECT_Y_DISTANCE);
|
||||
}
|
||||
|
||||
y += BODY_VERT_BORDER;
|
||||
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();
|
||||
|
@@ -147,27 +147,33 @@ QSizeF DiagramItem::calcMinimumGeometry() const
|
||||
double height = 0.0;
|
||||
|
||||
if (m_customIcon) {
|
||||
return stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
QSizeF sz = stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
if (shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignTop
|
||||
&& shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignCenter)
|
||||
return sz;
|
||||
width = sz.width();
|
||||
}
|
||||
|
||||
height += BODY_VERT_BORDER;
|
||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||
width = std::max(width, stereotypeIconItem->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, stereotypeIconItem->boundingRect().width());
|
||||
height += std::max(FOLD_HEIGHT, stereotypeIconItem->boundingRect().height());
|
||||
} else {
|
||||
height += FOLD_HEIGHT;
|
||||
}
|
||||
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
||||
width = std::max(width, stereotypesItem->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, stereotypesItem->boundingRect().width());
|
||||
height += stereotypesItem->boundingRect().height();
|
||||
}
|
||||
if (nameItem()) {
|
||||
width = std::max(width, nameItem()->boundingRect().width() + 2 * BODY_HORIZ_BORDER);
|
||||
width = std::max(width, nameItem()->boundingRect().width());
|
||||
height += nameItem()->boundingRect().height();
|
||||
}
|
||||
height += BODY_VERT_BORDER;
|
||||
|
||||
width = BODY_HORIZ_BORDER + width + BODY_HORIZ_BORDER;
|
||||
|
||||
return GeometryUtilities::ensureMinimumRasterSize(QSizeF(width, height), 2 * RASTER_WIDTH, 2 * RASTER_HEIGHT);
|
||||
}
|
||||
|
||||
@@ -215,7 +221,6 @@ void DiagramItem::updateGeometry()
|
||||
if (m_customIcon) {
|
||||
m_customIcon->setPos(left, top);
|
||||
m_customIcon->setActualSize(QSizeF(width, height));
|
||||
y += height;
|
||||
}
|
||||
|
||||
if (m_body) {
|
||||
@@ -237,8 +242,31 @@ void DiagramItem::updateGeometry()
|
||||
m_fold->setPolygon(foldPolygon);
|
||||
}
|
||||
|
||||
y += BODY_VERT_BORDER;
|
||||
if (!m_customIcon) {
|
||||
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();
|
||||
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 {
|
||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||
stereotypeIconItem->setPos(left + BODY_HORIZ_BORDER, y);
|
||||
y += std::max(FOLD_HEIGHT, stereotypeIconItem->boundingRect().height());
|
||||
|
@@ -179,13 +179,38 @@ PackageItem::ShapeGeometry PackageItem::calcMinimumGeometry() const
|
||||
{
|
||||
double width = 0.0;
|
||||
double height = 0.0;
|
||||
double tabHeight = 0.0;
|
||||
double tabWidth = 0.0;
|
||||
|
||||
if (m_customIcon) {
|
||||
return ShapeGeometry(stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(), CUSTOM_ICON_MINIMUM_AUTO_WIDTH,
|
||||
CUSTOM_ICON_MINIMUM_AUTO_HEIGHT), QSizeF(tabWidth, tabHeight));
|
||||
QSizeF sz = stereotypeIconMinimumSize(m_customIcon->stereotypeIcon(),
|
||||
CUSTOM_ICON_MINIMUM_AUTO_WIDTH, CUSTOM_ICON_MINIMUM_AUTO_HEIGHT);
|
||||
if (shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignTop
|
||||
&& shapeIcon().textAlignment() != qmt::StereotypeIcon::TextalignCenter)
|
||||
return ShapeGeometry(sz, QSizeF(0.0, 0.0));
|
||||
width = sz.width();
|
||||
height += BODY_VERT_BORDER;
|
||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||
width = std::max(width, stereotypeIconItem->boundingRect().width());
|
||||
height += stereotypeIconItem->boundingRect().height();
|
||||
}
|
||||
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
||||
width = std::max(width, stereotypesItem->boundingRect().width());
|
||||
height += stereotypesItem->boundingRect().height();
|
||||
}
|
||||
if (nameItem()) {
|
||||
width = std::max(width, nameItem()->boundingRect().width());
|
||||
height += nameItem()->boundingRect().height();
|
||||
}
|
||||
if (m_contextLabel)
|
||||
height += m_contextLabel->height();
|
||||
height += BODY_VERT_BORDER;
|
||||
|
||||
width = BODY_HORIZ_BORDER + width + BODY_HORIZ_BORDER;
|
||||
|
||||
return ShapeGeometry(GeometryUtilities::ensureMinimumRasterSize(QSizeF(width, height), 2 * RASTER_WIDTH, 2 * RASTER_HEIGHT), QSizeF(0.0, 0.0));
|
||||
}
|
||||
|
||||
double tabHeight = 0.0;
|
||||
double tabWidth = 0.0;
|
||||
double bodyHeight = 0.0;
|
||||
double bodyWidth = 0.0;
|
||||
|
||||
@@ -262,9 +287,36 @@ void PackageItem::updateGeometry()
|
||||
if (m_customIcon) {
|
||||
m_customIcon->setPos(left, top);
|
||||
m_customIcon->setActualSize(QSizeF(width, height));
|
||||
y += height;
|
||||
|
||||
y += BODY_VERT_BORDER;
|
||||
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;
|
||||
}
|
||||
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();
|
||||
@@ -276,7 +328,6 @@ void PackageItem::updateGeometry()
|
||||
if (m_contextLabel) {
|
||||
m_contextLabel->resetMaxWidth();
|
||||
m_contextLabel->setPos(-m_contextLabel->boundingRect().width() / 2.0, y);
|
||||
y += m_contextLabel->boundingRect().height();
|
||||
}
|
||||
} else if (m_shape) {
|
||||
QPolygonF polygon;
|
||||
|
Reference in New Issue
Block a user