Author: kmachalkova Date: Fri Mar 27 13:10:41 2009 New Revision: 56441 URL: http://svn.opensuse.org/viewcvs/yast?rev=56441&view=rev Log: Show the text only when it fits the segment (clipped strings in too narrow segments look silly) It'll be still available via tooltip anyway Modified: trunk/qt/src/YQBarGraph.cc Modified: trunk/qt/src/YQBarGraph.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQBarGraph.cc?rev=56441&r1=56440&r2=56441&view=diff ============================================================================== --- trunk/qt/src/YQBarGraph.cc (original) +++ trunk/qt/src/YQBarGraph.cc Fri Mar 27 13:10:41 2009 @@ -96,6 +96,8 @@ int x_off = YQBarGraphOuterMargin; int y_off = YQBarGraphOuterMargin; int valueTotal = 0; + QFontMetrics fm = painter.fontMetrics(); + toolTips.clear(); for ( int i=0; i < segments(); i++ ) @@ -108,6 +110,7 @@ { const YBarGraphSegment & seg = segment(i); int segWidth = ( (long) totalWidth * seg.value() ) / valueTotal; + int stringWidth = 0; if ( i == segments()-1 ) { @@ -155,14 +158,21 @@ if ( txt.contains( "%1" ) ) txt = txt.arg( seg.value() ); // substitute variable - painter.drawText( x_off + YQBarGraphLabelHorizontalMargin, + stringWidth = fm.size(0,txt).width(); + + // draw the text only if it fits the current segment width ... + if (stringWidth < segWidth) + { + painter.drawText( x_off + YQBarGraphLabelHorizontalMargin, y_off + YQBarGraphLabelVerticalMargin, segWidth - 2 * YQBarGraphLabelHorizontalMargin + 1, segHeight - 2 * YQBarGraphLabelVerticalMargin + 1, Qt::AlignCenter, txt ); + } - + // ... but always make it available via tooltip toolTips.insert(make_pair( x_off, txt)); + // Prepare for the next segment x_off += segWidth; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org