Commit b61d3ab7 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

umbrello/widgets/umlwidget.{h,cpp}

- Change return type of virtual function onWidget() from bool to UMLWidget*.
  This is one of the steps for moving management of widget-owned floating
  texts from UMLScene to the owning widget.

umbrello/widgets/messagewidget.{h,cpp}
- Adapt reimplemented function onWidget() to changed return type.

umbrello/widgets/pinwidget.{h,cpp}
umbrello/widgets/portwidget.{h,cpp}
- Reimplement UMLWidget::onWidget() in order to additionally check m_pName.

umbrello/umlscene.cpp
- Adapt function widgetAt() to changed return type of UMLWidget::onWidget().
parent 49e6c681
......@@ -996,12 +996,13 @@ UMLWidget* UMLScene::widgetAt(const QPointF& p)
qreal relativeSize = 99990.0; // start with an arbitrary large number
UMLWidget *retWid = 0;
foreach(UMLWidget* wid, widgetList()) {
if (!wid->onWidget(p))
UMLWidget* w = wid->onWidget(p);
if (w == NULL)
continue;
const qreal s = (wid->width() + wid->height()) / 2.0;
const qreal s = (w->width() + w->height()) / 2.0;
if (s < relativeSize) {
relativeSize = s;
retWid = wid;
retWid = w;
}
}
return retWid;
......
......@@ -590,12 +590,12 @@ void MessageWidget::paintFound(QPainter *painter, const QStyleOptionGraphicsItem
*
* @param p Point to be checked.
*
* @return True if the point is on a part of the MessageWidget.
* @return 'this' if the point is on a part of the MessageWidget.
* NB In case of a synchronous message, the empty space
* between call line and return line does not count, i.e. if
* the point is located in that space the function returns false.
* the point is located in that space the function returns NULL.
*/
bool MessageWidget::onWidget(const QPointF& p)
UMLWidget* MessageWidget::onWidget(const QPointF& p)
{
if (m_sequenceMessageType != Uml::SequenceMessage::Synchronous) {
return UMLWidget::onWidget(p);
......@@ -603,18 +603,18 @@ bool MessageWidget::onWidget(const QPointF& p)
// Synchronous message:
// Consists of top arrow (call) and bottom arrow (return.)
if (p.x() < x() || p.x() > x() + width())
return false;
return NULL;
const int tolerance = 5; // pixels
const int pY = p.y();
const int topArrowY = y() + 3;
const int bottomArrowY = y() + height() - 3;
if (pY < topArrowY - tolerance || pY > bottomArrowY + tolerance)
return false;
return NULL;
if (height() <= 2 * tolerance)
return true;
return this;
if (pY > topArrowY + tolerance && pY < bottomArrowY - tolerance)
return false;
return true;
return NULL;
return this;
}
/**
......
......@@ -129,7 +129,7 @@ public:
int getMinY();
int getMaxY();
bool onWidget(const QPointF& p);
UMLWidget* onWidget(const QPointF& p);
virtual void resizeWidget(qreal newW, qreal newH);
......
......@@ -189,6 +189,24 @@ void PinWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* me)
}
}
/**
* Override method from UMLWidget in order to additionally check m_pName.
*
* @param p Point to be checked.
*
* @return 'this' if UMLWidget::onWidget(p) returns non NULL;
* m_pName if m_pName is non NULL and m_pName->onWidget(p) returns non NULL;
* else NULL.
*/
UMLWidget* PinWidget::onWidget(const QPointF &p)
{
if (UMLWidget::onWidget(p) != NULL)
return this;
if (m_pName)
return m_pName->onWidget(p);
return NULL;
}
/**
* Captures any popup menu signals for menus it created.
*/
......
......@@ -41,6 +41,8 @@ public:
int getMinY();
UMLWidget* onWidget(const QPointF& p);
void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
bool loadFromXMI(QDomElement& qElement);
......
......@@ -243,6 +243,26 @@ void PortWidget::setFloatingTextWidget(FloatingTextWidget *ft) {
m_pName = ft;
}
/**
* Override method from UMLWidget in order to additionally check m_pName.
*
* @param p Point to be checked.
*
* @return 'this' if UMLWidget::onWidget(p) returns non NULL;
* m_pName if m_pName is non NULL and m_pName->onWidget(p) returns non NULL;
* else NULL.
*/
UMLWidget* PortWidget::onWidget(const QPointF &p)
{
if (UMLWidget::onWidget(p) != NULL)
return this;
if (m_pName) {
uDebug() << "floatingtext: " << m_pName->text();
return m_pName->onWidget(p);
}
return NULL;
}
/**
* Loads from a "portwidget" XMI element.
......
......@@ -37,6 +37,8 @@ public:
virtual void updateWidget();
virtual void moveWidgetBy(qreal diffX, qreal diffY);
void attachToOwningComponent();
UMLWidget* onWidget(const QPointF& p);
FloatingTextWidget *floatingTextWidget();
void setFloatingTextWidget(FloatingTextWidget *ft);
......
......@@ -1113,13 +1113,14 @@ void UMLWidget::showPropertiesDialog()
}
/**
* Returns true if the given point is in the boundaries of the widget.
* Default implementation returns 'this' if the given point is in the
* boundaries of the widget, else returns NULL.
*
* @param p Point to be checked.
*
* @return true if the given point is in the boundaries of the widget.
* @return 'this' if the given point is in the boundaries of the widget.
*/
bool UMLWidget::onWidget(const QPointF &p)
UMLWidget* UMLWidget::onWidget(const QPointF &p)
{
const qreal w = width();
const qreal h = height();
......@@ -1127,10 +1128,15 @@ bool UMLWidget::onWidget(const QPointF &p)
const qreal right = left + w;
const qreal top = y();
const qreal bottom = top + h;
uDebug() << "p=(" << p.x() << "," << p.y() << "), x=" << left << ", y=" << top << ", w=" << w << ", h=" << h
<< "; right=" << right << ", bottom=" << bottom;
if (p.x() < left || p.x() > right ||
p.y() < top || p.y() > bottom) // Qt coord.sys. origin in top left corner
return false;
return true;
p.y() < top || p.y() > bottom) { // Qt coord.sys. origin in top left corner
uDebug() << "returning NULL";
return NULL;
}
uDebug() << "returning this";
return this;
}
/**
......
......@@ -89,7 +89,7 @@ public:
virtual bool activate(IDChangeLog* ChangeLog = 0);
virtual bool onWidget(const QPointF &p);
virtual UMLWidget* onWidget(const QPointF &p);
void setPenFromSettings(QPainter &p);
void setPenFromSettings(QPainter *p);
......
Supports Markdown
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