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

Andi Fischer andi.fischer at hispeed.ch
Fri Jul 16 10:26:17 UTC 2010


SVN commit 1150609 by fischer:

Resizing when new text is entered fixed.

 M  +21 -8     notewidget.cpp  


--- trunk/KDE/kdesdk/umbrello/umbrello/widgets/notewidget.cpp #1150608:1150609
@@ -116,6 +116,9 @@
 void NoteWidget::setDocumentation(const QString &newText)
 {
     m_Text = newText;
+    QSize size = calculateSize();
+    setSize(size.width(), size.height());
+    //uDebug() << "new size [" << size.width() << ", " << size.height() << "]";
 }
 
 void NoteWidget::draw(QPainter & p, int offsetX, int offsetY)
@@ -169,28 +172,38 @@
 
 QSize NoteWidget::calculateSize()
 {
-    int width = 50, height = 50;
+    int width = 50;
+    int height = 50;
     const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
-    //const int fontHeight  = fm.lineSpacing();
     const int textWidth = fm.width(m_Text);
-    if (m_NoteType == PreCondition)
-    {
+    if (m_NoteType == PreCondition) {
         const int widthtemp = fm.width("<< precondition >>");
                 width = textWidth > widthtemp ? textWidth : widthtemp;
         width += 10;
     }
-    else if (m_NoteType == PostCondition)
-    {
+    else if (m_NoteType == PostCondition) {
         const int widthtemp = fm.width("<< postcondition >>");
                 width = textWidth > widthtemp ? textWidth : widthtemp;
         width += 10;
     }
-    else if (m_NoteType == Transformation)
-    {
+    else if (m_NoteType == Transformation) {
         const int widthtemp = fm.width("<< transformation >>");
                 width = textWidth > widthtemp ? textWidth : widthtemp;
         width += 10;
     }
+    else {
+        if (!m_Text.isEmpty()) {
+            QSize textSize = fm.size(Qt::TextExpandTabs, m_Text);
+            int textWidth = textSize.width() + 45;
+            if (width < textWidth) {
+                width = textWidth;
+            }
+            int textHeight = textSize.height() + 10;
+            if (height < textHeight) {
+                height = textHeight;
+            }
+        }
+    }
     return QSize(width, height);
 }
 




More information about the umbrello-devel mailing list