[Uml-devel] branches/work/soc-umbrello/umbrello

Gopala Krishna A krishna.ggk at gmail.com
Fri Jul 11 14:39:19 UTC 2008


SVN commit 830957 by gopala:

First version of BoxWidget port. Still got to make it work from toolbar.
First commit from kde.in monsoon hackathon, yay!!



 M  +39 -20    boxwidget.cpp  
 M  +8 -33     boxwidget.h  
 M  +1 -1      forkjoinwidget.cpp  
 M  +6 -2      newumlwidget.cpp  
 M  +8 -4      test.cpp  
 M  +1 -1      toolbarstateother.cpp  
 M  +3 -1      widget_factory.cpp  


--- branches/work/soc-umbrello/umbrello/boxwidget.cpp #830956:830957
@@ -11,39 +11,58 @@
 
 // own header
 #include "boxwidget.h"
-// qt/kde includes
-#include <qevent.h>
-#include <kdebug.h>
 
-BoxWidget::BoxWidget(UMLScene * scene, Uml::IDType id)
-        : NewUMLRectWidget(scene, id)
+/**
+ * @class BoxWidget
+ *
+ * Displays a rectangular box.  These widgets are diagram specific.
+ * They will still need a unique id from the @ref UMLDoc class for
+ * deletion and other purposes.
+ *
+ * @short Displays a box.
+ * @author Jonathan Riddell
+ * @see NewUMLRectWidget
+ * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
+ */
+
+
+/**
+ * Constructs a BoxWidget.
+ * @param id The ID to assign (-1 will prompt a new ID.)
+ */
+BoxWidget::BoxWidget(Uml::IDType id)
+    : NewUMLRectWidget(0, id),
+      m_minimumSize(100, 80)
 {
-    setSize(100, 80);
-    NewUMLRectWidget::setBaseType( Uml::wt_Box );
-    //NewUMLWidget::m_bUsesDiagramLineColour = false;  // boxes be black
+    m_baseType = Uml::wt_Box;
     setLineColor(Qt::black);
-    setZ(m_origZ = 0);
 }
 
-BoxWidget::~BoxWidget() {
+/**
+ * destructor
+ */
+BoxWidget::~BoxWidget()
+{
 }
 
+/**
+ * Draws a rectangle.
+ */
 void BoxWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *)
 {
-	QPainter &p = *painter;
-	qreal offsetX = 0, offsetY = 0;
+    painter->setPen(QPen(lineColor(), lineWidth()));
+    painter->setBrush(Qt::NoBrush);
 
-    NewUMLRectWidget::setPenFromSettings(p);
-    p.drawRect( offsetX, offsetY, getWidth(), getHeight() );
-
-    if (isSelected()) {
-        drawSelected(&p, offsetX, offsetY);
-    }
+    painter->drawRect(rect());
 }
 
-void BoxWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement) {
+/**
+ * Saves the widget to the "boxwidget" XMI element.
+ * @note For loading from XMI, the inherited parent method is used.
+ */
+void BoxWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
+{
     QDomElement boxElement = qDoc.createElement("boxwidget");
     NewUMLRectWidget::saveToXMI(qDoc, boxElement);
     qElement.appendChild(boxElement);
 }
-
--- branches/work/soc-umbrello/umbrello/boxwidget.h #830956:830957
@@ -11,51 +11,26 @@
 
 #ifndef BOXWIDGET_H
 #define BOXWIDGET_H
-//qt includes
-#include <qpainter.h>
+
 //app includes
-#include "umlwidget.h"
+#include "newumlrectwidget.h"
 
-// fwd decl.
-class UMLView;
+//qt includes
+#include <QtGui/QPainter>
 
-/**
- * Displays a rectangular box.
- * These widgets are diagram specific.  They will still need a unique id
- * from the @ref UMLDoc class for deletion and other purposes.
- *
- * @short Displays a box.
- * @author Jonathan Riddell
- * @see NewUMLRectWidget
- * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
- */
 class BoxWidget : public NewUMLRectWidget
 {
 public:
 
-    /**
-     * Constructs a BoxWidget.
-     *
-     * @param view              The parent to this widget.
-     * @param id                The ID to assign (-1 will prompt a new ID.)
-     */
-    explicit BoxWidget(UMLScene * scene, Uml::IDType id = Uml::id_None);
-
-    /**
-     * destructor
-     */
+    explicit BoxWidget(Uml::IDType id = Uml::id_None);
     virtual ~BoxWidget();
 
-    /**
-     * Draws a rectangle.
-     */
     void paint(QPainter *p, const QStyleOptionGraphicsItem *item, QWidget *w);
 
-    /**
-     * Saves the widget to the "boxwidget" XMI element.
-     * Note: For loading from XMI, the inherited parent method is used.
-     */
     void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
+
+private:
+    QSizeF m_minimumSize;
 };
 
 #endif
--- branches/work/soc-umbrello/umbrello/forkjoinwidget.cpp #830956:830957
@@ -22,7 +22,7 @@
 #include "umlscene.h"
 
 ForkJoinWidget::ForkJoinWidget(UMLScene * scene, bool drawVertical, Uml::IDType id)
-  : BoxWidget(scene, id), m_drawVertical(drawVertical)
+    : BoxWidget(id), m_drawVertical(drawVertical)
 {
     init();
 }
--- branches/work/soc-umbrello/umbrello/newumlwidget.cpp #830956:830957
@@ -854,7 +854,9 @@
     setFlags(ItemIsSelectable | ItemIsMovable);
     // Call init this way so that virtual methods may be called.
     QTimer::singleShot(0, this, SLOT(slotInit()));
-    scene->addItem(this);
+    if(scene) {
+        scene->addItem(this);
+    }
 }
 
 NewUMLWidget::NewUMLWidget(UMLScene *scene, const Uml::IDType &_id) :
@@ -873,7 +875,9 @@
     else {
         m_widgetInterfaceData->id = _id;
     }
-    scene->addItem(this);
+    if(scene) {
+        scene->addItem(this);
+    }
     setFlags(ItemIsSelectable | ItemIsMovable);
     // Call init this way so that virtual methods may be called.
     QTimer::singleShot(0, this, SLOT(slotInit()));
--- branches/work/soc-umbrello/umbrello/test.cpp #830956:830957
@@ -19,16 +19,17 @@
 
 #include "test.h"
 
+#include "boxwidget.h"
+#include "enum.h"
+#include "newenumwidget.h"
+#include "textitem.h"
 #include "umlscene.h"
 #include "umlview.h"
-#include "newenumwidget.h"
-#include "enum.h"
-#include "textitem.h"
 
 #include <QtCore/QMetaObject>
 #include <QtCore/QMetaProperty>
+#include <QtCore/QTime>
 #include <QtCore/QTimerEvent>
-#include <QtCore/QTime>
 
 #include <kdebug.h>
 
@@ -65,6 +66,9 @@
 {
     d->scene = scene;
 
+    BoxWidget *w = new BoxWidget("131313");
+    scene->addItem(w);
+
     TextItem *item = new TextItem("Notice loading of gradient brush from xmi in 3 secs");
 
     item->setFlag(QGraphicsItem::ItemIsMovable, true);
--- branches/work/soc-umbrello/umbrello/toolbarstateother.cpp #830956:830957
@@ -101,7 +101,7 @@
             break;
 
         case WorkToolBar::tbb_Box:
-            umlWidget = new BoxWidget(m_pUMLScene);
+            umlWidget = new BoxWidget();
             break;
 
         case WorkToolBar::tbb_Text:
--- branches/work/soc-umbrello/umbrello/widget_factory.cpp #830956:830957
@@ -151,6 +151,7 @@
     if (newWidget) {
         newWidget->setX( pos.x() );
         newWidget->setY( y );
+        uDebug() << "Added item";
         scene->addItem(newWidget);
     }
 
@@ -192,7 +193,7 @@
     } else if (tag == "notewidget" || tag == "UML:NoteWidget") {
         widget = new NoteWidget(scene, NoteWidget::Normal, Uml::id_Reserved);
     } else if (tag == "boxwidget") {
-        widget = new BoxWidget(scene, Uml::id_Reserved);
+        widget = new BoxWidget(Uml::id_Reserved);
     } else if (tag == "floatingtext" || tag == "UML:FloatingTextWidget") {
         widget = new FloatingTextWidget(scene, Uml::tr_Floating, "", Uml::id_Reserved);
     } else if (tag == "activitywidget" || tag == "UML:ActivityWidget") {
@@ -273,6 +274,7 @@
     }
 
     if(widget) {
+        uDebug() << "Added";
         scene->addItem(widget);
     }
     return widget;




More information about the umbrello-devel mailing list