[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/koffice/1.5/koffice/kspread trunk/koffice/kspread
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2006-04-06 12:34:03
Message-ID: 1144326843.799196.7656.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 526982 by nikolaus:

UI	Wrap cell content and comment separately. Otherwise it leads to crappy line breaks.
BUGS: 120204,120860


 M  +36 -28    branches/koffice/1.5/koffice/kspread/kspread_canvas.cc  
 M  +38 -30    trunk/koffice/kspread/kspread_canvas.cc  


--- branches/koffice/1.5/koffice/kspread/kspread_canvas.cc #526981:526982
@@ -6069,7 +6069,7 @@
     int row = sheet->topRow( (m_canvas->doc()->unzoomItY( p.y() ) +
                                    m_canvas->yOffset()), ypos );
 
-    Cell* cell = sheet->visibleCellAt( col, row );
+    const Cell* cell = sheet->visibleCellAt( col, row );
     if ( !cell )
         return;
 
@@ -6083,44 +6083,31 @@
     //  - cell comment
     //  - hyperlink
     QString tipText;
+    QString comment = cell->format()->comment( col, row );
 
     // If cell is too small, show the content
     if ( cell->testFlag( Cell::Flag_CellTooShortX ) ||
          cell->testFlag( Cell::Flag_CellTooShortY ) )
     {
         tipText = cell->strOutText();
-
-        //Add 2 extra lines and a text, when both should be in the tooltip
-        QString comment = cell->format()->comment( col, row );
-        if ( !comment.isEmpty() )
-            comment = "\n\n" + i18n("Comment:") + "\n" + comment;
-
-        tipText += comment;
     }
 
-    // Show comment, if any
-    if( tipText.isEmpty() )
-    {
-      tipText = cell->format()->comment( col, row );
-    }
-
     // Show hyperlink, if any
-    if( tipText.isEmpty() )
+    if ( tipText.isEmpty() )
     {
-        tipText = cell->link();
+      tipText = cell->link();
     }
 
     // Nothing to display, bail out
-    if( tipText.isEmpty() )
+    if ( tipText.isEmpty() && comment.isEmpty() )
       return;
 
     // Cut if the tip is ridiculously long
-    unsigned maxLen = 256;
-    if(tipText.length() > maxLen )
+    const unsigned maxLen = 256;
+    if ( tipText.length() > maxLen )
         tipText = tipText.left(maxLen).append("...");
 
     // Determine position and width of the current cell.
-    cell = sheet->cellAt( col, row );
     double u = cell->dblWidth( col );
     double v = cell->dblHeight( row );
 
@@ -6128,8 +6115,8 @@
     if ( cell->isObscured() && cell->isPartOfMerged() )
     {
       cell = cell->obscuringCells().first();
-      int moveX = cell->column();
-      int moveY = cell->row();
+      const int moveX = cell->column();
+      const int moveY = cell->row();
 
       // Use the obscuring cells dimensions
       u = cell->dblWidth( moveX );
@@ -6164,7 +6151,7 @@
     }
 
     // No use if mouse is somewhere else
-    if( !insideMarker )
+    if ( !insideMarker )
         return;
 
     // Find the tipLabel
@@ -6173,25 +6160,46 @@
 
     // Ensure that it is plain text
     // Not funny if (intentional or not) <a> appears as hyperlink
-    if( tipLabel )
+    if ( tipLabel )
          tipLabel->setTextFormat( Qt::PlainText );
 
+    QFontMetrics fm = tipLabel ? tipLabel->fontMetrics() : m_canvas->fontMetrics();
+    const QRect r( 0, 0, 200, -1 );
     // Wrap the text if too long
-    if( tipText.length() > 16 )
+    if ( tipText.length() > 16 )
     {
-        QFontMetrics fm = tipLabel? tipLabel->fontMetrics() : m_canvas->fontMetrics();
-        QRect r( 0, 0, 200, -1 );
         KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, tipText );
         tipText = wrap->wrappedString();
         delete wrap;
     }
+    // Wrap the comment if too long
+    if ( comment.length() > 16 )
+    {
+      KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, comment );
+      comment = wrap->wrappedString();
+      delete wrap;
+    }
 
+    // Show comment, if any
+    if ( tipText.isEmpty() )
+    {
+      tipText = comment;
+    }
+    else if ( !comment.isEmpty() )
+    {
+      //Add 2 extra lines and a text, when both should be in the tooltip
+      if ( !comment.isEmpty() )
+        comment = "\n\n" + i18n("Comment:") + "\n" + comment;
+
+      tipText += comment;
+    }
+
     // Now we shows the tip
     tip( marker, tipText );
 
     // Here we try to find the tip label again
     // Reason: the previous tip_findLabel might fail if no tip has ever shown yet
-    if( !tipLabel )
+    if ( !tipLabel )
     {
       tipLabel = tip_findLabel();
       if( tipLabel )
--- trunk/koffice/kspread/kspread_canvas.cc #526981:526982
@@ -5999,7 +5999,7 @@
     int row = sheet->topRow( (doc()->unzoomItY( p.y() ) +
                                    yOffset()), ypos );
 
-    Cell* cell = sheet->visibleCellAt( col, row );
+    const Cell* cell = sheet->visibleCellAt( col, row );
     if ( !cell )
         return;
 
@@ -6013,44 +6013,31 @@
     //  - cell comment
     //  - hyperlink
     QString tipText;
+    QString comment = cell->format()->comment( col, row );
 
     // If cell is too small, show the content
     if ( cell->testFlag( Cell::Flag_CellTooShortX ) ||
          cell->testFlag( Cell::Flag_CellTooShortY ) )
     {
         tipText = cell->strOutText();
-
-        //Add 2 extra lines and a text, when both should be in the tooltip
-        QString comment = cell->format()->comment( col, row );
-        if ( !comment.isEmpty() )
-            comment = "\n\n" + i18n("Comment:") + "\n" + comment;
-
-        tipText += comment;
     }
 
-    // Show comment, if any
-    if( tipText.isEmpty() )
-    {
-      tipText = cell->format()->comment( col, row );
-    }
-
     // Show hyperlink, if any
-    if( tipText.isEmpty() )
+    if ( tipText.isEmpty() )
     {
-        tipText = cell->link();
+      tipText = cell->link();
     }
 
     // Nothing to display, bail out
-    if( tipText.isEmpty() )
+    if ( tipText.isEmpty() && comment.isEmpty() )
       return;
 
     // Cut if the tip is ridiculously long
-    unsigned maxLen = 256;
-    if(tipText.length() > maxLen )
+    const unsigned maxLen = 256;
+    if ( tipText.length() > maxLen )
         tipText = tipText.left(maxLen).append("...");
 
     // Determine position and width of the current cell.
-    cell = sheet->cellAt( col, row );
     double u = cell->dblWidth( col );
     double v = cell->dblHeight( row );
 
@@ -6058,8 +6045,8 @@
     if ( cell->isObscured() && cell->isPartOfMerged() )
     {
       cell = cell->obscuringCells().first();
-      int moveX = cell->column();
-      int moveY = cell->row();
+      const int moveX = cell->column();
+      const int moveY = cell->row();
 
       // Use the obscuring cells dimensions
       u = cell->dblWidth( moveX );
@@ -6094,7 +6081,7 @@
     }
 
     // No use if mouse is somewhere else
-    if( !insideMarker )
+    if ( !insideMarker )
         return;
 
     // Find the tipLabel
@@ -6103,29 +6090,50 @@
 
     // Ensure that it is plain text
     // Not funny if (intentional or not) <a> appears as hyperlink
-    if( tipLabel )
+    if ( tipLabel )
          tipLabel->setTextFormat( Qt::PlainText );
 
+    QFontMetrics fm = tipLabel? tipLabel->fontMetrics() : fontMetrics();
+    const QRect r( 0, 0, 200, -1 );
     // Wrap the text if too long
-    if( tipText.length() > 16 )
+    if ( tipText.length() > 16 )
     {
-        QFontMetrics fm = tipLabel? tipLabel->fontMetrics() : fontMetrics();
-        QRect r( 0, 0, 200, -1 );
         KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, tipText );
         tipText = wrap->wrappedString();
         delete wrap;
     }
+    // Wrap the comment if too long
+    if ( comment.length() > 16 )
+    {
+      KWordWrap* wrap = KWordWrap::formatText( fm, r, 0, comment );
+      comment = wrap->wrappedString();
+      delete wrap;
+    }
 
+    // Show comment, if any
+    if ( tipText.isEmpty() )
+    {
+      tipText = comment;
+    }
+    else if ( !comment.isEmpty() )
+    {
+      //Add 2 extra lines and a text, when both should be in the tooltip
+      if ( !comment.isEmpty() )
+        comment = "\n\n" + i18n("Comment:") + "\n" + comment;
+
+      tipText += comment;
+    }
+
     // Now we shows the tip
     QToolTip::showText( marker.bottomRight(), tipText, this );
 
     // Here we try to find the tip label again
     // Reason: the previous tip_findLabel might fail if no tip has ever shown yet
-    if( !tipLabel )
+    if ( !tipLabel )
     {
       tipLabel = tip_findLabel();
-      if( tipLabel )
-            tipLabel->setTextFormat( Qt::PlainText );
+      if ( tipLabel )
+        tipLabel->setTextFormat( Qt::PlainText );
     }
 
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic