[Uml-devel] KDE/kdesdk/umbrello/umbrello/widgets
Ralf Habacker
ralf.habacker at gmail.com
Sun Nov 25 11:27:10 UTC 2012
SVN commit 1326036 by habacker:
Made QGraphicsObject a common base class of WidgetBase and UMLWidget.
CCBUG:310283
M +2 -2 associationwidget.cpp
M +2 -1 associationwidget.h
M +0 -3 enumwidget.h
M +38 -16 umlwidget.cpp
M +11 -17 umlwidget.h
M +31 -1 widgetbase.cpp
M +7 -2 widgetbase.h
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/associationwidget.cpp #1326035:1326036
@@ -3859,9 +3859,9 @@
/**
* Returns the bounding rectangle of all segments of the association.
*/
-UMLSceneRect AssociationWidget::boundingRect()
+QRectF AssociationWidget::boundingRect() const
{
- UMLSceneRect rectangle;
+ QRectF rectangle;
/* we also want the end points connected to the other widget */
int pos = m_associationLine->count();
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/associationwidget.h #1326035:1326036
@@ -16,6 +16,7 @@
#include "linkwidget.h"
#include "messagewidgetlist.h"
#include "umlwidgetlist.h"
+#include "umlscene.h"
#include "widgetbase.h"
class ListPopupMenu;
@@ -156,7 +157,7 @@
AssociationLine* associationLine() const;
virtual bool activate();
- UMLSceneRect boundingRect();
+ virtual QRectF boundingRect() const;
void widgetMoved(UMLWidget* widget, int x, int y);
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/enumwidget.h #1326035:1326036
@@ -11,11 +11,8 @@
#ifndef ENUMWIDGET_H
#define ENUMWIDGET_H
-
#include "umlwidget.h"
-class UMLScene;
-
#define ENUM_MARGIN 5
/**
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/umlwidget.cpp #1326035:1326036
@@ -127,7 +127,7 @@
m_showStereotype = other.m_showStereotype;
setX(other.x());
setY(other.y());
- QGraphicsRectItem::setRect(rect().x(), rect().y(), other.width(), other.height());
+ setRect(rect().x(), rect().y(), other.width(), other.height());
// assign volatile (non-saved) members
m_selected = other.m_selected;
@@ -307,7 +307,7 @@
height = maxSize.height();
if (fixedAspectRatio()) {
- UMLSceneSize size = QGraphicsRectItem::rect().size();
+ UMLSceneSize size = rect().size();
float aspectRatio = size.width() > 0 ? (float)size.height()/size.width() : 1;
height = width * aspectRatio;
}
@@ -380,6 +380,35 @@
}
/**
+ * return drawing rectangle of widget in local coordinates
+ */
+QRectF UMLWidget::rect() const
+{
+ return m_rect;
+}
+
+/**
+ * set widget rectangle in item coordinates
+ */
+void UMLWidget::setRect(const QRectF& rect)
+{
+ if (m_rect == rect)
+ return;
+ prepareGeometryChange();
+ m_rect = rect;
+ m_boundingRect = rect;
+ update();
+}
+
+/**
+ * set widget rectangle in item coordinates
+ */
+void UMLWidget::setRect(qreal x, qreal y, qreal width, qreal height)
+{
+ setRect(QRectF(x, y, width, height));
+}
+
+/**
* Captures any popup menu signals for menus it created.
*
* @param action The action which has to be executed.
@@ -999,13 +1028,6 @@
return (w + h) / 2;
}
-void UMLWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
-{
- Q_UNUSED(option); Q_UNUSED(widget);
- draw(*painter, 0, 0);
-}
-
-
/**
* Move the widget by an X and Y offset relative to
* the current position.
@@ -1133,19 +1155,19 @@
* Gets the x-coordinate.
*/
UMLSceneValue UMLWidget::x() const {
- return QGraphicsRectItem::x();
+ return QGraphicsObject::x();
}
/**
* Gets the y-coordinate.
*/
UMLSceneValue UMLWidget::y() const {
- return QGraphicsRectItem::y();
+ return QGraphicsObject::y();
}
/**
* Gets the z-coordinate.
*/
UMLSceneValue UMLWidget::z() const {
- return QGraphicsRectItem::zValue();
+ return QGraphicsObject::zValue();
}
/**
@@ -1160,7 +1182,7 @@
if (!m_ignoreSnapToGrid) {
x = m_scene->snappedX(x);
}
- QGraphicsRectItem::setX(x);
+ QGraphicsObject::setX(x);
}
/**
@@ -1175,7 +1197,7 @@
if (!m_ignoreSnapToGrid) {
y = m_scene->snappedX(y);
}
- QGraphicsRectItem::setY(y);
+ QGraphicsObject::setY(y);
}
/**
@@ -1186,7 +1208,7 @@
void UMLWidget::setZ(UMLSceneValue z)
{
m_origZ = this->z();
- QGraphicsRectItem::setZValue(z);
+ QGraphicsObject::setZValue(z);
}
/**
@@ -1293,7 +1315,7 @@
height = (numY + 1) * m_scene->snapY();
}
- QGraphicsRectItem::setRect(rect().x(), rect().y(), width, height);
+ setRect(rect().x(), rect().y(), width, height);
}
/**
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/umlwidget.h #1326035:1326036
@@ -16,6 +16,7 @@
#include "associationwidgetlist.h"
#include "optionstate.h"
#include "umlscene.h"
+#include "widgetbase.h"
#include <QDateTime>
#include <QFont>
@@ -23,7 +24,6 @@
class UMLWidgetController;
class UMLObject;
-class UMLScene;
class UMLDoc;
class ListPopupMenu;
class IDChangeLog;
@@ -39,7 +39,7 @@
* @author Paul Hensgen <phensgen at techie.com>
* Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
*/
-class UMLWidget : public WidgetBase, public QGraphicsRectItem
+class UMLWidget : public WidgetBase
{
Q_OBJECT
public:
@@ -99,17 +99,6 @@
virtual UMLSceneValue onWidget(const UMLScenePoint & p);
- /**
- * Draws the UMLWidget on the given paint device
- *
- * @param p The painter for the drawing device
- * @param offsetX x position to start the drawing.
- * @param offsetY y position to start the drawing.
- *
- */
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- virtual void draw(QPainter & p, int offsetX, int offsetY) = 0;
-
void setPenFromSettings(QPainter & p);
virtual QFont font() const;
@@ -137,14 +126,14 @@
* Returns the height of widget.
*/
int height() const {
- return QGraphicsRectItem::rect().height();
+ return rect().height();
}
/**
* Returns the width of the widget.
*/
UMLSceneValue width() const {
- return QGraphicsRectItem::rect().width();
+ return rect().width();
}
void setSize(UMLSceneValue width,UMLSceneValue height);
@@ -280,6 +269,10 @@
void init();
+ QRectF rect() const;
+ void setRect(const QRectF& rect);
+ void setRect(qreal x, qreal y, qreal width, qreal height);
+
///////////////// Data Loaded/Saved /////////////////////////////////
/**
@@ -333,7 +326,6 @@
UMLWidgetController *m_widgetController;
public slots:
-
virtual void slotRemovePopupMenu();
virtual void updateWidget();
virtual void slotMenuSelection(QAction* action);
@@ -353,6 +345,8 @@
* @param id The id of the object behind the widget.
*/
void sigWidgetMoved(Uml::IDType id);
-};
+protected:
+ QRectF m_rect; ///< widget size
+};
#endif
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/widgetbase.cpp #1326035:1326036
@@ -23,11 +23,13 @@
* @param scene The view to be displayed on.
*/
WidgetBase::WidgetBase(UMLScene *scene, WidgetType type)
- : QObject(scene),
+ : QGraphicsObject(),
m_baseType(type),
m_scene(scene),
m_umlObject(0)
{
+ // TODO 310283
+ //setFlags(ItemIsSelectable | ItemIsMovable |ItemSendsGeometryChanges);
if (m_scene) {
m_usesDiagramLineColor = true;
m_usesDiagramLineWidth = true;
@@ -466,6 +468,34 @@
}
/**
+ * @return The bounding rectangle for this widget.
+ * @see setBoundingRect
+ */
+QRectF WidgetBase::boundingRect() const
+{
+ return m_boundingRect;
+}
+
+/**
+ * Draws the UMLWidget on the given paint device
+ *
+ * @param p The painter for the drawing device
+ * @param offsetX x position to start the drawing.
+ * @param offsetY y position to start the drawing.
+ *
+ */
+void WidgetBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option); Q_UNUSED(widget);
+ draw(*painter, 0, 0);
+}
+
+void WidgetBase::draw(QPainter & p, int offsetX, int offsetY)
+{
+ Q_UNUSED(p); Q_UNUSED(offsetX); Q_UNUSED(offsetY);
+}
+
+/**
* Helper function for debug output.
* Returns the given enum value as string.
* @param wt WidgetType of which a string representation is wanted
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/widgetbase.h #1326035:1326036
@@ -29,7 +29,7 @@
* @author Oliver Kellogg <okellogg at users.sourceforge.net>
* Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
*/
-class WidgetBase : public QObject
+class WidgetBase : public QGraphicsObject
{
Q_OBJECT
Q_ENUMS(WidgetType)
@@ -123,11 +123,17 @@
WidgetBase& operator=(const WidgetBase& other);
+ virtual QRectF boundingRect() const;
+
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ QT_DEPRECATED virtual void draw(QPainter & p, int offsetX, int offsetY);
+
protected:
WidgetType m_baseType; ///< Type of widget.
UMLScene *m_scene;
UMLObject *m_umlObject;
QString m_Doc; ///< Only used if m_umlObject is not set.
+ QRectF m_boundingRect;
/**
* This ID is only used when the widget does not have a
@@ -157,7 +163,6 @@
bool m_usesDiagramFillColor;
bool m_usesDiagramUseFillColor;
bool m_usesDiagramLineWidth;
-
};
#endif
More information about the umbrello-devel
mailing list