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

Ouch... forgot to add files in commit 17e9a744

parent 17e9a744
......@@ -352,6 +352,7 @@ set(libwidgets_SRCS
widgets/objectnodewidget.cpp
widgets/objectwidget.cpp
widgets/packagewidget.cpp
widgets/pinportbase.cpp
widgets/pinwidget.cpp
widgets/portwidget.cpp
widgets/preconditionwidget.cpp
......
......@@ -27,7 +27,7 @@
#include "model_utils.h"
#include "objectnodewidget.h"
#include "objectwidget.h"
#include "portwidget.h"
#include "pinportbase.h"
#include "preconditionwidget.h"
#include "signalwidget.h"
#include "statewidget.h"
......@@ -389,8 +389,8 @@ void ListPopupMenu::insertSingleSelectionMenu(WidgetBase* object)
insert(mt_Rename);
insert(mt_NameAsTooltip, i18n("Name as Tooltip"), CHECKABLE);
{
PortWidget *portW = static_cast<PortWidget*>(object);
FloatingTextWidget *ft = portW->floatingTextWidget();
PinPortBase *pW = static_cast<PinPortBase*>(object);
FloatingTextWidget *ft = pW->floatingTextWidget();
if (ft == NULL)
m_actions[mt_NameAsTooltip]->setChecked(true);
}
......@@ -535,6 +535,13 @@ void ListPopupMenu::insertSingleSelectionMenu(WidgetBase* object)
insert(mt_Clear, Icon_Utils::SmallIcon(Icon_Utils::it_Clear), i18nc("clear precondition", "Clear"));
addSeparator();
insert(mt_Rename, i18n("Change Text..."));
if (type == WidgetBase::wt_Pin) {
insert(mt_NameAsTooltip, i18n("Name as Tooltip"), CHECKABLE);
PinPortBase *pW = static_cast<PinPortBase*>(object);
FloatingTextWidget *ft = pW->floatingTextWidget();
if (ft == NULL)
m_actions[mt_NameAsTooltip]->setChecked(true);
}
insert(mt_Delete);
insert(mt_Change_Font);
break;
......
......@@ -25,7 +25,7 @@
#include "classoptionspage.h"
#include "cmds.h"
#include "componentwidget.h"
#include "portwidget.h"
#include "pinportbase.h"
#include "datatypewidget.h"
#include "debug_utils.h"
#include "docwindow.h"
......@@ -539,8 +539,8 @@ void UMLScene::print(QPrinter *pPrinter, QPainter & pPainter)
*/
void UMLScene::setupNewWidget(UMLWidget *w)
{
if (w->baseType() == WidgetBase::wt_Port) {
PortWidget *pw = static_cast<PortWidget*>(w);
if (w->baseType() == WidgetBase::wt_Pin || w->baseType() == WidgetBase::wt_Port) {
PinPortBase *pw = static_cast<PinPortBase*>(w);
pw->attachToOwner();
} else if (w->baseType() != WidgetBase::wt_Object) {
// ObjectWidget's position is handled by the widget
......
......@@ -297,6 +297,15 @@ void ActivityWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
UMLWidget::paint(painter, option, widget);
}
/**
* Overridden from UMLWidget due to emission of signal sigActMoved()
*/
void ActivityWidget::moveWidgetBy(qreal diffX, qreal diffY)
{
UMLWidget::moveWidgetBy(diffX, diffY);
emit sigActMoved(diffX, diffY);
}
/**
* Loads the widget from the "activitywidget" XMI element.
*/
......
......@@ -64,12 +64,24 @@ public:
virtual void showPropertiesDialog();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual void moveWidgetBy(qreal diffX, qreal diffY);
virtual bool loadFromXMI(QDomElement & qElement);
virtual void saveToXMI(QDomDocument & qDoc, QDomElement & qElement);
void constrain(qreal& width, qreal& height);
signals:
/**
* Emitted when the activity widget is moved.
* Provides the delta X and delta Y amount by which the widget was moved
* relative to the previous position.
* Slots into PinWidget::slotActMoved()
* @param diffX The difference between previous and new X value.
* @param diffY The difference between previous and new Y value.
*/
void sigActMoved(qreal diffX, qreal diffY);
public Q_SLOTS:
virtual void slotMenuSelection(QAction* action);
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2002-2013 *
* copyright (C) 2002-2014 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -16,7 +16,7 @@
#include "floatingtextwidget.h"
#include "listpopupmenu.h"
#include "umlscene.h"
#include "uniqueid.h"
#include "activitywidget.h"
// kde includes
#include <kinputdialog.h>
......@@ -35,24 +35,15 @@ DEBUG_REGISTER_DISABLED(PinWidget)
* @param id The ID to assign (-1 will prompt a new ID).
*/
PinWidget::PinWidget(UMLScene* scene, UMLWidget* a, Uml::ID::Type id)
: UMLWidget(scene, WidgetBase::wt_Pin, id),
m_pOw(a)
: PinPortBase(scene, WidgetBase::wt_Pin, a, id)
{
setParent(a);
m_ignoreSnapToGrid = true;
m_ignoreSnapComponentSizeToGrid = true;
m_resizable = false;
setMinimumSize(QSizeF(10, 10));
setMaximumSize(QSizeF(10, 10));
setSize(10, 10);
m_nY = y() < getMinY() ? getMinY() : y();
// setParent(a);
// m_nY = y() < getMinY() ? getMinY() : y();
m_pName = new FloatingTextWidget(scene, Uml::TextRole::Floating, "");
m_scene->addFloatingTextWidget(m_pName);
m_pName->setX(0);
m_pName->setY(0);
activate();
m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, name());
m_pName->setParentItem(this);
m_pName->setText(name()); // to get geometry update
m_pName->activate();
setVisible(true);
}
......@@ -61,150 +52,15 @@ PinWidget::PinWidget(UMLScene* scene, UMLWidget* a, Uml::ID::Type id)
*/
PinWidget::~PinWidget()
{
if (m_scene->widgetList().contains(this))
m_scene->widgetList().removeAll(this);
}
/**
* Overrides the standard paint event.
* Implement abstract function from PinPortWidget.
*/
void PinWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void PinWidget::connectOwnerMotion()
{
int w = 10;
int h = 10;
int widthActivity = m_pOw->width();
int heightActivity = m_pOw->height();
int y = 0;
int x = m_pOw->x() + (widthActivity/2);
int offsetX = this->x();
int offsetY = this->y();
const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
const int fontHeight = fm.lineSpacing();
const bool floTxtNeedsPositioning = m_pName && !m_pName->text().isEmpty() && m_pName->x() == 0 && m_pName->y() == 0;
if ((offsetY + heightActivity/2) <= m_pOw->y() + heightActivity){
y = m_pOw->y() - 5;
if (floTxtNeedsPositioning) {
//the floating text has not been linked with the signal
m_pName->setX(x + 5 - m_Text.length()/2);
m_pName->setY(y -fontHeight);
}
} else if((offsetY + heightActivity/2) > m_pOw->y() + heightActivity){
y = m_pOw->y() + heightActivity - 5;
if (floTxtNeedsPositioning) {
//the floating text has not been linked with the signal
m_pName->setX(x + 5 - m_Text.length()/2);
m_pName->setY(y + fontHeight);
}
}
if (offsetX + widthActivity/4 <= m_pOw->x() + widthActivity/2
&& (offsetY > m_pOw->y() +5 && offsetY < m_pOw->y() + heightActivity - 5)){
x = m_pOw->x() -5;
y = m_pOw->y() + (heightActivity/2) -5;
if (floTxtNeedsPositioning) {
m_pName->setX(x - m_Text.length());
m_pName->setY(y - fontHeight);
}
} else if (offsetX + widthActivity/4 > m_pOw->x() + widthActivity/2
&& (offsetY > m_pOw->y() +5 && offsetY < m_pOw->y() + heightActivity - 5)){
x = m_pOw->x() + widthActivity -5;
y = m_pOw->y() + (heightActivity/2) -5;
if (floTxtNeedsPositioning) {
//the floating text has not been linked with the signal
m_pName->setX(x + 10);
m_pName->setY(y - fontHeight);
}
}
m_oldX = this->x();
setX(x);
m_oldY = this->y();
setY(y);
//test if y isn't above the object
// if (y <= m_pOw[Uml::A]->y() + height_Activity-5 && x == m_pOw[Uml::A]->x() + (width_Activity/2)) {
// y = m_pOw[Uml::A]->y() + height_Activity + 15;
// }
// if (y + h >= m_pOw[Uml::A]->getEndLineY()) {
// y = m_pOw[Uml::A]->getEndLineY() - h;
// }
setPenFromSettings(painter);
if (UMLWidget::useFillColor()) {
painter->setBrush(UMLWidget::fillColor());
}
painter->drawRect(0, 0, w, h);
//make sure it's always above the others
setZValue(20);
setPenFromSettings(painter);
if (m_pName) {
m_pName->setVisible((m_pName->text().length() > 0));
m_pName->updateGeometry();
}
UMLWidget::paint(painter, option, widget);
}
/**
* Sets the name of the pin.
*/
void PinWidget::setName(const QString &strName)
{
m_Text = strName;
updateGeometry();
if (m_pName) {
m_pName->setText(m_Text);
} else {
m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, strName);
m_scene->addFloatingTextWidget(m_pName);
}
}
/**
* Returns the minimum height this widget should be set at.
* Takes into account the position of the widget it is related to.
*/
int PinWidget::getMinY()
{
if (!m_pOw) {
return 0;
}
int heightA = m_pOw->y() + m_pOw->height();
return heightA;
}
/**
* Overrides mouseMoveEvent.
*/
void PinWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* me)
{
UMLWidget::mouseMoveEvent(me);
int diffX = m_oldX - x();
int diffY = m_oldY - y();
if (m_pName && !m_pName->text().isEmpty()) {
m_pName->setX(m_pName->x() - diffX);
m_pName->setY(m_pName->y() - diffY);
}
}
/**
* 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;
ActivityWidget *owner = static_cast<ActivityWidget*>(ownerWidget());
connect(owner, SIGNAL(sigActMoved(qreal, qreal)), this, SLOT(slotOwnerMoved(qreal, qreal)));
}
/**
......@@ -228,82 +84,8 @@ void PinWidget::slotMenuSelection(QAction* action)
break;
default:
UMLWidget::slotMenuSelection(action);
}
}
/**
* Saves the widget to the "pinwidget" XMI element.
*/
void PinWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
{
QDomElement PinElement = qDoc.createElement("pinwidget");
PinElement.setAttribute("widgetaid", Uml::ID::toString(m_pOw->id()));
UMLWidget::saveToXMI(qDoc, PinElement);
if (m_pName && !m_pName->text().isEmpty()) {
PinElement.setAttribute("textid", Uml::ID::toString(m_pName->id()));
m_pName -> saveToXMI(qDoc, PinElement);
}
qElement.appendChild(PinElement);
}
/**
* Loads the widget from the "pinwidget" XMI element.
*/
bool PinWidget::loadFromXMI(QDomElement& qElement)
{
if(!UMLWidget::loadFromXMI(qElement))
return false;
QString widgetaid = qElement.attribute("widgetaid", "-1");
Uml::ID::Type aId = Uml::ID::fromString(widgetaid);
UMLWidget *pWA = m_scene -> findWidget(aId);
if (pWA == NULL) {
DEBUG(DBG_SRC) << "role A object " << Uml::ID::toString(aId) << " not found";
return false;
}
m_pOw = pWA;
// We dont' really need the textid.
// @todo remove this code
QString textid = qElement.attribute("textid", "-1");
Uml::ID::Type textId = Uml::ID::fromString(textid);
if (textId != Uml::ID::None) {
UMLWidget *flotext = m_scene -> findWidget(textId);
if (flotext != NULL) {
if (flotext->baseType() == WidgetBase::wt_Text) {
uWarning() << "Check XMI file: floatingtext " << textid
<< " is already defined";
m_pName = static_cast<FloatingTextWidget*>(flotext);
return true;
} else {
uError() << "floatingtext xmi.id" << textid
<< " conflicts with existing " << flotext->baseType();
return false;
}
}
}
//now load child elements
QDomNode node = qElement.firstChild();
QDomElement element = node.toElement();
if (!element.isNull()) {
QString tag = element.tagName();
if (tag == "floatingtext" || tag == "UML::FloatingTextWidget") {
m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, m_Text, textId);
if(! m_pName->loadFromXMI(element)) {
// Most likely cause: The FloatingTextWidget is empty.
delete m_pName;
m_pName = NULL;
}
} else {
uError() << "unknown tag " << tag;
}
PinPortBase::slotMenuSelection(action);
}
return true;
}
#include "pinwidget.moc"
......@@ -11,9 +11,7 @@
#ifndef PINWIDGET_H
#define PINWIDGET_H
#include "umlwidget.h"
class FloatingTextWidget;
#include "pinportbase.h"
/**
* This class is the graphical version of a UML Pin. A pinWidget is created
......@@ -27,7 +25,7 @@ class FloatingTextWidget;
* @author Hassan KOUCH <hkouch@hotmail.com>
* Bugs and comments to umbrello-devel@kde.org or http://bugs.kde.org
*/
class PinWidget : public UMLWidget
class PinWidget : public PinPortBase
{
Q_OBJECT
public:
......@@ -35,30 +33,14 @@ public:
PinWidget(UMLScene* scene, UMLWidget* a, Uml::ID::Type id = Uml::ID::None);
virtual ~PinWidget();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual void setName(const QString &strName);
int getMinY();
UMLWidget* onWidget(const QPointF& p);
void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
bool loadFromXMI(QDomElement& qElement);
void mouseMoveEvent(QGraphicsSceneMouseEvent* me);
void connectOwnerMotion();
// int getMinY();
public slots:
void slotMenuSelection(QAction* action);
private:
UMLWidget* m_pOw;
FloatingTextWidget* m_pName; ///< displays the name of the signal widget
int m_oldX; ///< save the value to know how to move the floatingtext in x
int m_oldY; ///< save the value to know how to move the floatingtext in x
int m_nY;
// private:
// int m_nY;
};
#endif
......@@ -17,19 +17,17 @@
#include "debug_utils.h"
#include "umldoc.h"
#include "umlscene.h"
#include "umlview.h"
#include "componentwidget.h"
#include "floatingtextwidget.h"
// kde includes
#include <kinputdialog.h>
#include <klocale.h>
// qt includes
#include <QPainter>
#include <QToolTip>
// sys includes
#include <cmath>
const QSizeF PortWidget::FixedSize(15, 15);
/**
* Constructs a PortWidget.
*
......@@ -37,24 +35,9 @@ const QSizeF PortWidget::FixedSize(15, 15);
* @param d The UMLPort this will be representing.
*/
PortWidget::PortWidget(UMLScene *scene, UMLPort *d)
: UMLWidget(scene, WidgetBase::wt_Port, d)
: PinPortBase(scene, WidgetBase::wt_Port, d)
{
m_ignoreSnapToGrid = true;
m_ignoreSnapComponentSizeToGrid = true;
m_resizable = false;
m_pName = NULL;
setMinimumSize(FixedSize);
setMaximumSize(FixedSize);
setSize(FixedSize);
setToolTip(d->name());
UMLWidget *owner = ownerWidget();
if (owner) {
ComponentWidget *compWidget = static_cast<ComponentWidget*>(owner);
connect(compWidget, SIGNAL(sigCompMoved(qreal, qreal)), this, SLOT(slotOwnerMoved(qreal, qreal)));
} else {
uError() << "ownerWidget() returns NULL";
}
}
/**
......@@ -64,140 +47,25 @@ PortWidget::~PortWidget()
{
}
UMLWidget* PortWidget::ownerWidget()
{
const Uml::ID::Type compWidgetId = m_umlObject->umlPackage()->id();
return m_scene->widgetOnDiagram(compWidgetId);
}
/**
* Overrides method from UMLWidget in order to set a tooltip.
* The tooltip is set to the port name.
* The reason for using a tooltip for the name is that the size of the port
* widget is not large enough to accomodate the average name.
* Override function from PinPortWidget.
*/
void PortWidget::updateWidget()
{
QString strName = name();
uDebug() << " port name is " << strName;
if (m_pName) {
m_pName->setText(strName);
} else {
setToolTip(strName);
}
}
/**
* Overridden from UMLWidget.
* Moves the widget to a new position using the difference between the
* current position and the new position.
* Movement is constrained such that the port is always attached to its
* component.
*
* @param diffX The difference between current X position and new X position.
* @param diffY The difference between current Y position and new Y position.
*/
void PortWidget::moveWidgetBy(qreal diffX, qreal diffY)
UMLWidget* PortWidget::ownerWidget()
{
UMLWidget* owner = ownerWidget();
qreal newX = x() + diffX;
qreal newY = y() + diffY;
if (owner == NULL) {
uError() << "ownerWidget() returns NULL";
setX(newX);
setY(newY);
return;
}
const qreal deltaTop = fabs(y() + height() - owner->y());
const qreal deltaBottom = fabs(owner->y() + owner->height() - y());
const qreal deltaLeft = fabs(x() + width() - owner->x());
const qreal deltaRight = fabs(owner->x() + owner->width() - x());
bool didAnyMovement = false;
if (deltaTop < 1.0 || deltaBottom < 1.0) {
if (newX < owner->x() - width())
newX = owner->x() - width();
else if (newX > owner->x() + owner->width())
newX = owner->x() + owner->width();
setX(newX);
didAnyMovement = true;
}
if (deltaLeft < 1.0 || deltaRight < 1.0) {
if (newY < owner->y() - height())
newY = owner->y() - height();
else if (newY > owner->y() + owner->height())
newY = owner->y() + owner->height();
setY(newY);
didAnyMovement = true;
}
if (!didAnyMovement) {
uDebug() << "constraint failed for (" << diffX << ", " << diffY << ")";
setX(newX);
setY(newY);
if (m_pOw == NULL) {
const Uml::ID::Type compWidgetId = m_umlObject->umlPackage()->id();
m_pOw = m_scene->widgetOnDiagram(compWidgetId);
}
return m_pOw;
}
/**
* Align this PortWidget's position such that it is attached at one of the
* sides of its owner's widget.
* Implement abstract function from PinPortWidget.
*/
void PortWidget::attachToOwner() {
UMLWidget *owner = ownerWidget();
const QPointF scenePos = m_scene->pos();
if (owner == NULL) {
uError() << "ownerWidget() returns NULL";
setX(scenePos.x());
setY(scenePos.y());
return;
}
bool xIsWithinComponent = false;
if (scenePos.x() < owner->x() - width()) {
setX(owner->x() - width());
} else if (scenePos.x() <= owner->x() + owner->width()) {
setX(scenePos.x());
xIsWithinComponent = true;
} else {
setX(owner->x() + owner->width());
}
if (scenePos.y() < owner->y() - height()) {
setY(owner->y() - height());
} else if (scenePos.y() <= owner->y() + owner->height()) {
if (xIsWithinComponent) {
if (scenePos.y() <= owner->y() + owner->height() / 2.0)
setY(owner->y() - height());
else
setY(owner->y() + owner->height());