aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib
diff options
context:
space:
mode:
authorJochen Becher <[email protected]>2018-01-11 20:58:32 +0100
committerJochen Becher <[email protected]>2018-01-12 16:49:11 +0000
commita5cf82b4e2e777bd342e70a7931412ea920e1e55 (patch)
tree1c2586c2a3a9911e6a15c6fe33d59c125ba69ea5 /src/libs/modelinglib
parentd12e74265c2813a71cf0a3c25f4c834c64358bb0 (diff)
ModelEditor: Support text alignment with all object types
Change-Id: I9f67527ff21883194158f82039d3dcf513186150 Reviewed-by: Tobias Hunger <[email protected]>
Diffstat (limited to 'src/libs/modelinglib')
-rw-r--r--src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp53
-rw-r--r--src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp38
-rw-r--r--src/libs/modelinglib/qmt/diagram_scene/items/diagramitem.cpp44
-rw-r--r--src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp65
4 files changed, 172 insertions, 28 deletions
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp
index 958643dfe29..a6a2a37c46b 100644
--- a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp
+++ b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp
@@ -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();
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp
index 00ab655c259..96f0b8231cc 100644
--- a/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp
+++ b/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp
@@ -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();
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/diagramitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/diagramitem.cpp
index c466328407d..c3cce6a2972 100644
--- a/src/libs/modelinglib/qmt/diagram_scene/items/diagramitem.cpp
+++ b/src/libs/modelinglib/qmt/diagram_scene/items/diagramitem.cpp
@@ -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());
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp
index 3b61e4e5493..8cc4f7ed927 100644
--- a/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp
+++ b/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp
@@ -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;