[Uml-devel] KDE/kdesdk/umbrello/umbrello/widgets

Ralf Habacker ralf.habacker at gmail.com
Sat Mar 10 10:35:40 UTC 2012


SVN commit 1284788 by habacker:

Used fixed aspect ratio for initial, end, ...history, fork, join, choice and
junction state diagram widgets, which makes resizing much easier.

 M  +26 -0     statewidget.cpp  
 M  +1 -0      statewidget.h  
 M  +7 -0      umlwidget.cpp  
 M  +11 -0     umlwidget.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/statewidget.cpp #1284787:1284788
@@ -40,6 +40,7 @@
   : UMLWidget(scene, WidgetBase::wt_State, id)
 {
     m_stateType = stateType;
+    setAspectRatioMode();
     m_Text = "State";
 }
 
@@ -224,6 +225,29 @@
 }
 
 /**
+ * Set the aspect ratio mode.
+ * Some state types have a fixed aspect ratio
+ */
+void StateWidget::setAspectRatioMode()
+{
+    switch (m_stateType) {
+        case StateWidget::Initial:
+        case StateWidget::End:
+        case StateWidget::Choice:
+        case StateWidget::DeepHistory:
+        case StateWidget::ShallowHistory:
+        case StateWidget::Fork:
+        case StateWidget::Join:
+        case StateWidget::Junction:
+            setFixedAspectRatio(true);
+            break;
+        default:
+            setFixedAspectRatio(false);
+            break;
+    }
+}
+
+/**
  * Sets the name of the State.
  */
 void StateWidget::setName(const QString &strName)
@@ -255,6 +279,7 @@
 void StateWidget::setStateType(StateType stateType)
 {
     m_stateType = stateType;
+    setAspectRatioMode();
 }
 
 /**
@@ -415,6 +440,7 @@
     m_Doc = qElement.attribute( "documentation", "" );
     QString type = qElement.attribute( "statetype", "1" );
     m_stateType = (StateType)type.toInt();
+    setAspectRatioMode();
     //load states activities
     QDomNode node = qElement.firstChild();
     QDomElement tempElement = node.toElement();
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/statewidget.h #1284787:1284788
@@ -86,6 +86,7 @@
 
 protected:
     UMLSceneSize minimumSize();
+    void setAspectRatioMode();
 
 public slots:
     virtual void slotMenuSelection(QAction* action);
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/umlwidget.cpp #1284787:1284788
@@ -264,7 +264,13 @@
         width = maxSize.width();
     if (height > maxSize.height())
         height = maxSize.height();
+
+    if (fixedAspectRatio()) {
+        UMLSceneSize size = UMLSceneRectItem::size();
+        float aspectRatio = (float)size.height()/size.width();
+        height = width * aspectRatio;
 }
+}
 
 /**
  * Calls the method with the same name in UMLWidgetController.
@@ -310,6 +316,7 @@
     }
 
     m_resizable = true;
+    m_fixedAspectRatio = false;
 
     m_selected = false;
     m_startMove = false;
--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/umlwidget.h #1284787:1284788
@@ -266,6 +266,16 @@
     void setMaximumSize(const UMLSceneSize &size);
     void setMaximumSize(UMLSceneValue width, UMLSceneValue height);
 
+    bool fixedAspectRatio()
+    {
+        return m_fixedAspectRatio;
+    }
+
+    void setFixedAspectRatio(bool state)
+    {
+        m_fixedAspectRatio = state;
+    }
+
     typedef enum {
         FT_NORMAL = 0,
         FT_BOLD  = 1,
@@ -351,6 +361,7 @@
      */
     bool m_ignoreSnapToGrid;
     bool m_ignoreSnapComponentSizeToGrid;
+    bool m_fixedAspectRatio;
 
     /**
      * Controller for user interaction events.




More information about the umbrello-devel mailing list