diff --git a/umbrello/umlwidgets/pinportbase.cpp b/umbrello/umlwidgets/pinportbase.cpp index d0151232a..81f333d97 100644 --- a/umbrello/umlwidgets/pinportbase.cpp +++ b/umbrello/umlwidgets/pinportbase.cpp @@ -1,318 +1,318 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ // own header #include "pinportbase.h" // app includes #include "port.h" #include "package.h" #include "debug_utils.h" #include "listpopupmenu.h" #include "umldoc.h" #include "umlscene.h" #include "umlview.h" #include "floatingtextwidget.h" #include "debug_utils.h" #include "umlwidgets/childwidgetplacementpin.h" #include "umlwidgets/childwidgetplacementport.h" // qt includes #include #include // sys includes #include -PinPortBase::PinPortBase(UMLScene *scene, WidgetType type, UMLObject *o) +PinPortBase::PinPortBase(UMLScene *scene, WidgetType type, UMLWidget *owner, UMLObject *o) : UMLWidget(scene, type, o), m_childPlacement(createPlacement(type)) { - init(); + init(owner); } PinPortBase::PinPortBase(UMLScene *scene, WidgetType type, UMLWidget *owner, Uml::ID::Type id) : UMLWidget(scene, type, id), m_childPlacement(createPlacement(type)) { init(owner); } /** * Standard destructor. */ PinPortBase::~PinPortBase() { } ChildWidgetPlacement* PinPortBase::createPlacement(WidgetBase::WidgetType type) { if (type == wt_Pin) { return new ChildWidgetPlacementPin(this); } else if (type == wt_Port) { return new ChildWidgetPlacementPort(this); } else { return 0; } } /** * Performs initializations which are common to PinWidget and PortWidget. */ void PinPortBase::init(UMLWidget *owner) { m_ignoreSnapToGrid = true; m_ignoreSnapComponentSizeToGrid = true; m_resizable = false; setParentItem(owner); m_pName = 0; const int edgeLength = 15; // old: (m_baseType == wt_Pin ? 10 : 15); const QSizeF fixedSize(edgeLength, edgeLength); setMinimumSize(fixedSize); setMaximumSize(fixedSize); setSize(fixedSize); m_childPlacement->setInitialPosition(); } UMLWidget* PinPortBase::ownerWidget() const { return dynamic_cast(parentItem()); } /** * Overrides method from UMLWidget in order to set a tooltip. * The tooltip is set to the name(). * The reason for using a tooltip for the name is that the size of this * widget is not large enough to accommodate the average name. */ void PinPortBase::updateWidget() { QString strName = name(); uDebug() << " port name is " << strName; if (m_pName) { m_pName->setText(strName); } else { setToolTip(strName); } } /** * Overrides method from UMLWidget to set the name. */ void PinPortBase::setName(const QString &strName) { UMLWidget::setName(strName); updateGeometry(); if (m_pName) { m_pName->setText(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 * owner widget. * * @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 PinPortBase::moveWidgetBy(qreal diffX, qreal diffY) { m_childPlacement->setNewPositionWhenMoved(diffX, diffY); } /** * Receive notification when parent is resized. * We need to track parent resize to always stay attached to it. */ void PinPortBase::notifyParentResize() { m_childPlacement->setNewPositionOnParentResize(); } /** * Overrides standard method. */ void PinPortBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { setPenFromSettings(painter); if (UMLWidget::useFillColor()) { painter->setBrush(UMLWidget::fillColor()); } else { painter->setBrush(m_scene->backgroundColor()); } painter->drawRect(0, 0, width(), height()); UMLWidget::paint(painter, option, widget); } QRectF PinPortBase::boundingRect() const { return QRectF(0, 0, width(), height()); } /** * Captures any popup menu signals for menus it created. */ void PinPortBase::slotMenuSelection(QAction* action) { uDebug() << "PinPortBase::slotMenuSelection"; ListPopupMenu::MenuType sel = ListPopupMenu::typeFromAction(action); switch(sel) { case ListPopupMenu::mt_NameAsTooltip: if (m_pName) { action->setChecked(true); delete m_pName; m_pName = 0; setToolTip(name()); } else { action->setChecked(false); 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(); UMLWidget* owner = ownerWidget(); if (owner == 0) { uError() << "PinPortBase::slotMenuSelection: ownerWidget() returns NULL"; setX(x()); setY(y()); } else { const qreal w = width(); const qreal h = height(); if (x() < owner->x()) m_pName->setX(-m_pName->width()); else if (x() >= owner->x() + owner->width()) m_pName->setX(w); else m_pName->setX(-m_pName->width() / 2.0 + w / 2.0); if (y() < owner->y()) m_pName->setY(-m_pName->height() - 2); else if (y() >= owner->y() + owner->height()) m_pName->setY(h); else m_pName->setY(-m_pName->height() / 2.0 + h / 2.0); } m_pName->update(); setToolTip(QString()); QToolTip::hideText(); } break; default: UMLWidget::slotMenuSelection(action); } } FloatingTextWidget *PinPortBase::floatingTextWidget() { return m_pName; } void PinPortBase::setFloatingTextWidget(FloatingTextWidget *ft) { m_pName = ft; if (m_pName) m_pName->setParentItem(this); } /** * 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 0; * m_pName if m_pName is non NULL and m_pName->onWidget(p) returns non 0; * else NULL. */ UMLWidget* PinPortBase::onWidget(const QPointF &p) { if (UMLWidget::onWidget(p) != 0) return this; if (m_pName) { uDebug() << "floatingtext: " << m_pName->text(); return m_pName->onWidget(p); } return 0; } /** * Reimplement function from UMLWidget */ UMLWidget* PinPortBase::widgetWithID(Uml::ID::Type id) { if (UMLWidget::widgetWithID(id)) return this; if (m_pName && m_pName->widgetWithID(id)) return m_pName; return 0; } /** * Saves the widget to the "pinwidget" or "portwidget" XMI element. */ void PinPortBase::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement) { QDomElement element = qDoc.createElement(baseType() == wt_Pin ? QLatin1String("pinwidget") : QLatin1String("portwidget")); Q_ASSERT(ownerWidget() != 0); element.setAttribute(QLatin1String("widgetaid"), Uml::ID::toString(ownerWidget()->id())); UMLWidget::saveToXMI1(qDoc, element); if (m_pName && !m_pName->text().isEmpty()) { m_pName->saveToXMI1(qDoc, element); } qElement.appendChild(element); } /** * Loads from a "pinwidget" or from a "portwidget" XMI element. */ bool PinPortBase::loadFromXMI1(QDomElement & qElement) { if (!UMLWidget::loadFromXMI1(qElement)) return false; QString widgetaid = qElement.attribute(QLatin1String("widgetaid"), QLatin1String("-1")); Uml::ID::Type aId = Uml::ID::fromString(widgetaid); UMLWidget *owner = m_scene->findWidget(aId); if (owner == 0) { DEBUG(DBG_SRC) << "owner object " << Uml::ID::toString(aId) << " not found"; return false; } setParentItem(owner); // Optional child element: floatingtext QDomNode node = qElement.firstChild(); QDomElement element = node.toElement(); if (!element.isNull()) { QString tag = element.tagName(); if (tag == QLatin1String("floatingtext")) { m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, name(), Uml::ID::Reserved); if (!m_pName->loadFromXMI1(element)) { // Most likely cause: The FloatingTextWidget is empty. delete m_pName; m_pName = 0; } else { m_pName->setParentItem(this); m_pName->activate(); m_pName->update(); } } else { uError() << "unknown tag " << tag; } } return true; } diff --git a/umbrello/umlwidgets/pinportbase.h b/umbrello/umlwidgets/pinportbase.h index 80f047337..97b5afde2 100644 --- a/umbrello/umlwidgets/pinportbase.h +++ b/umbrello/umlwidgets/pinportbase.h @@ -1,70 +1,70 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ #ifndef PINPORTBASE_H #define PINPORTBASE_H #include "umlwidget.h" #include class FloatingTextWidget; class ChildWidgetPlacement; /** * @short Abstract base class for PinWidget and PortWidget * @author Oliver Kellogg * @see UMLWidget * Bugs and comments to umbrello-devel@kde.org or http://bugs.kde.org */ class PinPortBase : public UMLWidget { Q_OBJECT public: - PinPortBase(UMLScene *scene, WidgetType type, UMLObject *o); - PinPortBase(UMLScene *scene, WidgetType type, UMLWidget *owner, Uml::ID::Type id); + PinPortBase(UMLScene *scene, WidgetType type, UMLWidget *owner, UMLObject *o); + PinPortBase(UMLScene *scene, WidgetType type, UMLWidget *owner = 0, Uml::ID::Type id = Uml::ID::None); virtual ~PinPortBase(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual QRectF boundingRect() const; virtual UMLWidget* ownerWidget() const; void updateWidget(); void setName(const QString &strName); void moveWidgetBy(qreal diffX, qreal diffY); virtual void notifyParentResize(); UMLWidget* onWidget(const QPointF& p); UMLWidget* widgetWithID(Uml::ID::Type id); FloatingTextWidget *floatingTextWidget(); void setFloatingTextWidget(FloatingTextWidget *ft); void saveToXMI1(QDomDocument& qDoc, QDomElement& qElement); bool loadFromXMI1(QDomElement& qElement); public slots: virtual void slotMenuSelection(QAction* action); protected: void init(UMLWidget *owner = 0); private: ChildWidgetPlacement* createPlacement(WidgetBase::WidgetType type); protected: FloatingTextWidget *m_pName; private: QScopedPointer m_childPlacement; }; #endif diff --git a/umbrello/umlwidgets/pinwidget.h b/umbrello/umlwidgets/pinwidget.h index 70e324a69..166c36816 100644 --- a/umbrello/umlwidgets/pinwidget.h +++ b/umbrello/umlwidgets/pinwidget.h @@ -1,45 +1,45 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2002-2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ #ifndef PINWIDGET_H #define PINWIDGET_H #include "pinportbase.h" /** * This class is the graphical version of a UML Pin. A pinWidget is created * by a @ref UMLView. An pinWidget belongs to only one @ref UMLView instance. * When the @ref UMLView instance that this class belongs to, it will be automatically deleted. * * The pinWidget class inherits from the @ref UMLWidget class which adds most of the functionality * to this class. * * @short A graphical version of a UML pin. * @author Hassan KOUCH * Bugs and comments to umbrello-devel@kde.org or http://bugs.kde.org */ class PinWidget : public PinPortBase { Q_OBJECT public: - PinWidget(UMLScene* scene, UMLWidget* a, Uml::ID::Type id = Uml::ID::None); + PinWidget(UMLScene* scene, UMLWidget* owner, Uml::ID::Type id = Uml::ID::None); virtual ~PinWidget(); // int getMinY(); public slots: void slotMenuSelection(QAction* action); // private: // int m_nY; }; #endif diff --git a/umbrello/umlwidgets/portwidget.cpp b/umbrello/umlwidgets/portwidget.cpp index 3f89c68a4..6d72674a6 100644 --- a/umbrello/umlwidgets/portwidget.cpp +++ b/umbrello/umlwidgets/portwidget.cpp @@ -1,84 +1,82 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ // own header #include "portwidget.h" // app includes #include "port.h" #include "package.h" #include "debug_utils.h" #include "dialog_utils.h" #include "listpopupmenu.h" #include "umldoc.h" #include "umlscene.h" #include "componentwidget.h" #include "floatingtextwidget.h" // kde includes #include // qt includes #include #include /** * Constructs a PortWidget. * * @param scene The parent of this PortWidget. * @param d The UMLPort this will be representing. */ -PortWidget::PortWidget(UMLScene *scene, UMLPort *d) - : PinPortBase(scene, WidgetBase::wt_Port, d) +PortWidget::PortWidget(UMLScene *scene, UMLPort *d, UMLWidget *owner) + : PinPortBase(scene, WidgetBase::wt_Port, owner, d) { setToolTip(d->name()); - const Uml::ID::Type compWidgetId = m_umlObject->umlPackage()->id(); - setParentItem(scene->widgetOnDiagram(compWidgetId)); } /** * Standard deconstructor. */ PortWidget::~PortWidget() { } /** * Override function from PinPortWidget. */ UMLWidget* PortWidget::ownerWidget() const { return PinPortBase::ownerWidget(); } /** * Captures any popup menu signals for menus it created. */ void PortWidget::slotMenuSelection(QAction* action) { ListPopupMenu::MenuType sel = ListPopupMenu::typeFromAction(action); switch(sel) { case ListPopupMenu::mt_Rename: { QString newName = name(); bool ok = Dialog_Utils::askName(i18n("Enter Port Name"), i18n("Enter the port name :"), newName); if (ok) { setName(newName); } } break; default: PinPortBase::slotMenuSelection(action); } } diff --git a/umbrello/umlwidgets/portwidget.h b/umbrello/umlwidgets/portwidget.h index 19ff94200..02cfb20a7 100644 --- a/umbrello/umlwidgets/portwidget.h +++ b/umbrello/umlwidgets/portwidget.h @@ -1,41 +1,41 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ #ifndef PORTWIDGET_H #define PORTWIDGET_H #include "pinportbase.h" class UMLPort; /** * Defines a graphical version of the UML2 port. Most of the functionality * comes from the @ref PinPortBase class from which this class inherits. * * @short A graphical version of a port on a component. * @author Oliver Kellogg * @see PinPortBase, UMLWidget * Bugs and comments to umbrello-devel@kde.org or http://bugs.kde.org */ class PortWidget : public PinPortBase { Q_OBJECT public: - PortWidget(UMLScene *scene, UMLPort *d); + PortWidget(UMLScene *scene, UMLPort *d, UMLWidget *owner = 0); virtual ~PortWidget(); UMLWidget* ownerWidget() const; public slots: void slotMenuSelection(QAction* action); }; #endif diff --git a/umbrello/umlwidgets/toolbarstateonewidget.cpp b/umbrello/umlwidgets/toolbarstateonewidget.cpp index d2071bc84..b3ee2f615 100644 --- a/umbrello/umlwidgets/toolbarstateonewidget.cpp +++ b/umbrello/umlwidgets/toolbarstateonewidget.cpp @@ -1,240 +1,240 @@ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * copyright (C) 2004-2014 * * Umbrello UML Modeller Authors * ***************************************************************************/ // own header #include "toolbarstateonewidget.h" // app includes #include "activitywidget.h" #include "dialog_utils.h" #include "floatingtextwidget.h" #include "messagewidget.h" #include "model_utils.h" #include "objectwidget.h" #include "pinwidget.h" #include "portwidget.h" #include "preconditionwidget.h" #include "regionwidget.h" #include "uml.h" #include "umldoc.h" #include "port.h" #include "umlscene.h" #include "umlwidget.h" #include "object_factory.h" #include "package.h" #include "widget_factory.h" #include "widget_utils.h" // kde includes #include #include // qt includes // using namespace Uml; /** * Creates a new ToolBarStateOneWidget. * * @param umlScene The UMLScene to use. */ ToolBarStateOneWidget::ToolBarStateOneWidget(UMLScene *umlScene) : ToolBarStatePool(umlScene), m_firstObject(0), m_isObjectWidgetLine(false) { } /** * Destroys this ToolBarStateOneWidget. */ ToolBarStateOneWidget::~ToolBarStateOneWidget() { } /** * Called when the current tool is changed to use another tool. * Executes base method and cleans the message. */ void ToolBarStateOneWidget::cleanBeforeChange() { ToolBarStatePool::cleanBeforeChange(); } /** * Called when a mouse event happened. * It executes the base method and then updates the position of the * message line, if any. */ void ToolBarStateOneWidget::mouseMove(QGraphicsSceneMouseEvent* ome) { ToolBarStatePool::mouseMove(ome); } /** * A widget was removed from the UMLView. * If the widget removed was the current widget, the current widget is set * to 0. * Also, if it was the first object, the message is cleaned. */ void ToolBarStateOneWidget::slotWidgetRemoved(UMLWidget* widget) { ToolBarState::slotWidgetRemoved(widget); } /** * Selects only widgets, but no associations. * Overrides base class method. * If the press event happened on the line of an object, the object is set * as current widget. If the press event happened on a widget, the widget is * set as current widget. */ void ToolBarStateOneWidget::setCurrentElement() { m_isObjectWidgetLine = false; ObjectWidget* objectWidgetLine = m_pUMLScene->onWidgetLine(m_pMouseEvent->scenePos()); if (objectWidgetLine) { setCurrentWidget(objectWidgetLine); m_isObjectWidgetLine = true; return; } UMLWidget *widget = m_pUMLScene->widgetAt(m_pMouseEvent->scenePos()); if (widget) { setCurrentWidget(widget); return; } } /** * Called when the release event happened on a widget. * If the button pressed isn't left button or the widget isn't an object * widget, the message is cleaned. * If the release event didn't happen on the line of an object and the first * object wasn't selected, nothing is done. If the first object was already * selected, a creation message is made. * If the event happened on the line of an object, the first object or the * second are set, depending on whether the first object was already set or * not. */ void ToolBarStateOneWidget::mouseReleaseWidget() { WidgetBase::WidgetType type = widgetType(); if (type == WidgetBase::wt_Precondition) { m_firstObject = 0; } if (type == WidgetBase::wt_Pin || type == WidgetBase::wt_Port) { m_firstObject = 0; } if (m_pMouseEvent->button() != Qt::LeftButton || (!currentWidget()->isObjectWidget() && !currentWidget()->isActivityWidget() && !currentWidget()->isComponentWidget() && !currentWidget()->isRegionWidget())) { return; } if (!m_firstObject && (type == WidgetBase::wt_Pin || type == WidgetBase::wt_Port)) { setWidget(currentWidget()); return ; } if (!m_isObjectWidgetLine && !m_firstObject) { return; } if (!m_firstObject) { setWidget(currentWidget()); } } /** * Called when the release event happened on an empty space. * Cleans the message. * Empty spaces are not only actual empty spaces, but also associations. */ void ToolBarStateOneWidget::mouseReleaseEmpty() { } /** * Sets the first object of the message using the specified object. * The temporal visual message is created and mouse tracking enabled, so * mouse events will be delivered. * * @param firstObject The first object of the message. */ void ToolBarStateOneWidget::setWidget(UMLWidget* firstObject) { m_firstObject = firstObject; UMLWidget * umlwidget = 0; //m_pUMLScene->viewport()->setMouseTracking(true); if (widgetType() == WidgetBase::wt_Precondition) { umlwidget = new PreconditionWidget(m_pUMLScene, static_cast(m_firstObject)); Dialog_Utils::askNameForWidget(umlwidget, i18n("Enter Precondition Name"), i18n("Enter the precondition"), i18n("new precondition")); // Create the widget. Some setup functions can remove the widget. } if (widgetType() == WidgetBase::wt_Pin && m_firstObject->isActivityWidget()) { QString name = i18n("new pin"); if (Dialog_Utils::askName(i18n("Enter Pin Name"), i18n("Enter the Pin"), name)) { umlwidget = new PinWidget(m_pUMLScene, m_firstObject); } } else if (widgetType() == WidgetBase::wt_Port && m_firstObject->isComponentWidget()) { UMLPackage* component = m_firstObject->umlObject()->asUMLPackage(); QString name = Model_Utils::uniqObjectName(UMLObject::ot_Port, component); if (Dialog_Utils::askName(i18n("Enter Port Name"), i18n("Enter the port"), name)) { UMLPort *port = Object_Factory::createUMLObject(UMLObject::ot_Port, name, component)->asUMLPort(); - umlwidget = Widget_Factory::createWidget(m_pUMLScene, port); + umlwidget = new PortWidget(m_pUMLScene, port, m_firstObject); } } if (umlwidget) { m_pUMLScene->setupNewWidget(umlwidget); } } /** * Returns the widget type of this tool. * * @return The widget type of this tool. */ WidgetBase::WidgetType ToolBarStateOneWidget::widgetType() { if (getButton() == WorkToolBar::tbb_Seq_Precondition) { return WidgetBase::wt_Precondition; } if (getButton() == WorkToolBar::tbb_Pin) { return WidgetBase::wt_Pin; } if (getButton() == WorkToolBar::tbb_Port) { return WidgetBase::wt_Port; } // Shouldn't happen Q_ASSERT(0); return WidgetBase::wt_Pin; } /** * Goes back to the initial state. */ void ToolBarStateOneWidget::init() { ToolBarStatePool::init(); }