Commit 1a3a5424 authored by Ralf Habacker's avatar Ralf Habacker

Fix 'Box widgets inside a combined fragment are not selectable'

The fix is implemented by adding a virtual method shape(), which
returns a tube around the widget border. The bounding rect of
the widget has been adjusted to reflect the shape.

BUG:389357
FIXED-IN:2.24.3 (KDE Applications 17.12.3)
parent 14940731
......@@ -27,8 +27,13 @@
#include <QPainter>
#include <QString>
DEBUG_REGISTER_DISABLED(CombinedFragmentWidget)
static const int defaultWidth = 100;
static const int defaultHeight = 50;
static const int initialLabelWidth = 45;
static const int labelHeight = 20;
static const int labelBorderMargin = 10;
/**
* Creates a Combined Fragment widget.
......@@ -38,7 +43,8 @@ static const int defaultHeight = 50;
* @param id The ID to assign (-1 will prompt a new ID.)
*/
CombinedFragmentWidget::CombinedFragmentWidget(UMLScene * scene, CombinedFragmentType combinedfragmentType, Uml::ID::Type id)
: UMLWidget(scene, WidgetBase::wt_CombinedFragment, id)
: UMLWidget(scene, WidgetBase::wt_CombinedFragment, id),
m_labelWidth(initialLabelWidth)
{
setZValue(-10);
setCombinedFragmentType(combinedfragmentType);
......@@ -64,7 +70,7 @@ void CombinedFragmentWidget::paint(QPainter *painter, const QStyleOptionGraphics
int w = width();
int h = height();
int line_width = 45;
int line_width = initialLabelWidth;
int old_Y;
setPenFromSettings(painter);
......@@ -177,9 +183,10 @@ void CombinedFragmentWidget::paint(QPainter *painter, const QStyleOptionGraphics
}
setPenFromSettings(painter);
painter->drawLine(0, 20, line_width, 20);
painter->drawLine(line_width, 20, line_width + 10, 10);
painter->drawLine(line_width + 10, 10, line_width + 10, 0);
painter->drawLine(0, labelHeight, line_width, labelHeight);
painter->drawLine(line_width, labelHeight, line_width + labelBorderMargin, labelHeight-labelBorderMargin);
painter->drawLine(line_width + labelBorderMargin, labelHeight-labelBorderMargin, line_width + labelBorderMargin, 0);
m_labelWidth = line_width;
UMLWidget::paint(painter, option, widget);
}
......@@ -480,3 +487,41 @@ void CombinedFragmentWidget::setDashLineGeometryAndPosition() const
void CombinedFragmentWidget::toForeground()
{
}
QRectF CombinedFragmentWidget::boundingRect() const
{
const qreal r = defaultMargin / 2.0;
return rect().adjusted(-r, -r, r, r);
}
QPainterPath CombinedFragmentWidget::shape() const
{
const qreal w = width();
const qreal h = height();
const qreal s = selectionMarkerSize * resizeMarkerLineCount;
const qreal r = defaultMargin / 2.0;
const qreal lw = m_labelWidth + r;
const qreal lh = labelHeight + r;
QPainterPath outerPath;
outerPath.setFillRule(Qt::WindingFill);
outerPath.addRect(boundingRect());
QPolygonF inner;
inner.append(QPointF(r, lh));
inner.append(QPointF(lw, lh));
inner.append(QPointF(lw + labelBorderMargin, lh - labelBorderMargin));
inner.append(QPointF(lw + labelBorderMargin, r));
inner.append(QPointF(w - selectionMarkerSize - r, r));
inner.append(QPointF(w - r, selectionMarkerSize + r));
inner.append(QPointF(w - r, h - s));
inner.append(QPointF(w - s, h - r));
inner.append(QPointF(selectionMarkerSize + r, h - r));
inner.append(QPointF(r, h - selectionMarkerSize - r));
inner.append(QPointF(r, lh));
QPainterPath innerPath;
innerPath.addPolygon(inner);
QPainterPath result = outerPath.subtracted(innerPath);
return result.simplified();
}
......@@ -70,6 +70,9 @@ public:
virtual bool activate(IDChangeLog* ChangeLog = 0);
virtual QRectF boundingRect() const;
virtual QPainterPath shape() const;
public slots:
void slotMenuSelection(QAction* action);
......@@ -86,7 +89,7 @@ private:
/// Dash lines of an alternative or parallel combined fragment
QList<FloatingDashLineWidget*> m_dashLines;
qreal m_labelWidth;
};
#endif
......@@ -47,6 +47,9 @@ DEBUG_REGISTER_DISABLED(UMLWidget)
const QSizeF UMLWidget::DefaultMinimumSize(50, 20);
const QSizeF UMLWidget::DefaultMaximumSize(1000, 5000);
const int UMLWidget::defaultMargin = 5;
const int UMLWidget::selectionMarkerSize = 4;
const int UMLWidget::resizeMarkerLineCount = 3;
/**
* Creates a UMLWidget object.
......@@ -1706,7 +1709,7 @@ void UMLWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
if (option->state & QStyle::State_Selected) {
const qreal w = width();
const qreal h = height();
const qreal s = 4;
const qreal s = selectionMarkerSize;
QBrush brush(Qt::blue);
painter->fillRect(0, 0, s, s, brush);
painter->fillRect(0, 0 + h - s, s, s, brush);
......
......@@ -45,6 +45,8 @@ public:
static const QSizeF DefaultMinimumSize;
static const QSizeF DefaultMaximumSize;
static const int defaultMargin;
static const int selectionMarkerSize;
static const int resizeMarkerLineCount;
explicit UMLWidget(UMLScene *scene, WidgetType type = wt_UMLWidget, UMLObject *o = 0);
explicit UMLWidget(UMLScene *scene, WidgetType type = wt_UMLWidget, Uml::ID::Type id = Uml::ID::None);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment