[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: [Kde-pim] [PATCH] KOrganizer: squeezing text in monthview
From: Tim Jansen <ml () tjansen ! de>
Date: 2003-07-08 19:49:55
[Download RAW message or body]
Hi...
I would like to commit the attached patch. It makes sure that the event's text
in the Month View is cut off at a character boundary and adds three dots
(...), which looks better and less broken than just cutting it off in the
middle of the character.
bye...
["korg-squeeze.patch" (text/x-diff)]
Index: komonthview.cpp
===================================================================
RCS file: /home/kde/kdepim/korganizer/komonthview.cpp,v
retrieving revision 1.68
diff -u -3 -p -r1.68 komonthview.cpp
--- komonthview.cpp 9 Apr 2003 18:57:51 -0000 1.68
+++ komonthview.cpp 8 Jul 2003 19:44:37 -0000
@@ -165,7 +165,36 @@ void MonthViewItem::paint(QPainter *p)
yPos = pmheight/2 - fm.height()/2 + fm.ascent();
p->setPen( palette().color( QPalette::Normal, sel ? \
QColorGroup::HighlightedText : QColorGroup::Foreground ) );
- p->drawText( x, yPos, text() );
+
+ // try to cut off the text to fits into the cell, append '...' if cut off
+ QString t = text();
+ int maxW = listBox()->width() - x;
+ if ( fm.boundingRect( t ).width() > maxW ) {
+ QString cutT( i18n( "Three dots (...) or whatever in your language is used to \
show that a text has been cut off", "..." ) ); + if (fm.boundingRect(cutT).width() \
>= maxW ) + t = cutT;
+ else {
+ int wt;
+ int maxIterations = 25; // safety, usually needs <5, worst case <12
+ int offset = 1;
+ while ( maxIterations-- &&
+ ( ( wt = fm.boundingRect( t + cutT ).width() ) > maxW ) ) {
+ int approxW = ( ( ( t.length() + cutT.length() ) * maxW / wt ) ) -
+ cutT.length() + offset;
+ if ( ( approxW < (int) t.length() ) &&
+ ( fm.boundingRect( t.left( approxW ) + cutT ).width() > maxW ) ) {
+ t = t.left( approxW );
+ offset = ( offset > 1 ) ? ( offset / 2) : 1;
+ }
+ else {
+ t = t.left( t.length() - 1 );
+ offset = ( approxW >= (int) t.length() ) ? 1 : (offset * 2);
+ }
+ }
+ t += cutT;
+ }
+ }
+ p->drawText( x, yPos, t );
}
int MonthViewItem::height(const QListBox *lb) const
_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic