[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: [Kde-pim] [PATCH] KOrganizer: squeezing text in monthview, 2nd try
From: Tim Jansen <ml () tjansen ! de>
Date: 2003-07-08 21:59:23
[Download RAW message or body]
Hi...
Again the patch to improve cutting off texts in month view. With this version
resizing the view works as well.
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 21:54:34 -0000
@@ -48,7 +48,8 @@
#include "komonthview.moc"
KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
- : QListBox(parent, name)
+ : QListBox(parent, name),
+ mSqueezing(false)
{
}
@@ -110,6 +111,15 @@ void KNoScrollListBox::mousePressEvent(Q
}
}
+void KNoScrollListBox::resizeEvent(QResizeEvent *e)
+{
+ bool s = count() && ( maxItemWidth() > e->size().width() );
+ if (mSqueezing || s)
+ triggerUpdate(false);
+
+ mSqueezing = s;
+ QListBox::resizeEvent(e);
+}
MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
: QListBoxItem()
@@ -165,7 +175,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 fit 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
Index: komonthview.h
===================================================================
RCS file: /home/kde/kdepim/korganizer/komonthview.h,v
retrieving revision 1.33
diff -u -3 -p -r1.33 komonthview.h
--- komonthview.h 7 Mar 2003 22:06:22 -0000 1.33
+++ komonthview.h 8 Jul 2003 21:54:34 -0000
@@ -52,6 +52,10 @@ class KNoScrollListBox: public QListBox
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
void mousePressEvent(QMouseEvent *);
+ void resizeEvent(QResizeEvent *);
+
+ private:
+ bool mSqueezing;
};
_______________________________________________
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