[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: Re: [Kde-pim] [PATCH] KOrganizer: squeezing text in monthview, 2nd
From: Tim Jansen <ml () tjansen ! de>
Date: 2003-07-09 0:05:13
[Download RAW message or body]
On Wednesday 09 July 2003 00:07, Aaron J. Seigo wrote:
> fading out the text ala the buttons in the taskbar would be ubernice. best
> of both worlds: show some text from the summary and that it's cutoff....
Did this, see patch & screenshot. Not sure whether I like it. Maybe I should
try some small, emacs-like marker...
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 9 Jul 2003 00:00:12 -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()
@@ -128,18 +138,25 @@ MonthViewItem::MonthViewItem( Incidence
mReply = false;
}
+static QColor mixColors(double p1, QColor c1, QColor c2) {
+ return QColor(int(c1.red() * p1 + c2.red() * (1.0-p1)),
+ int(c1.green() * p1 + c2.green() * (1.0-p1)),
+ int(c1.blue() * p1 + c2.blue() * (1.0-p1)));
+}
+
void MonthViewItem::paint(QPainter *p)
{
#if QT_VERSION >= 0x030000
bool sel = isSelected();
#else
bool sel = selected();
-#endif
-
+#endif
+
+ QColor bgColor = palette().color( QPalette::Normal, \
+ sel ? QColorGroup::Highlight : QColorGroup::Background );
if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
{
- p->setBackgroundColor( palette().color( QPalette::Normal, \
- sel ? QColorGroup::Highlight : QColorGroup::Background ) );
+ p->setBackgroundColor( bgColor );
p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
}
int x = 3;
@@ -163,9 +180,45 @@ void MonthViewItem::paint(QPainter *p)
yPos = fm.ascent() + fm.leading()/2;
else
yPos = pmheight/2 - fm.height()/2 + fm.ascent();
- p->setPen( palette().color( QPalette::Normal, sel ? \
- QColorGroup::HighlightedText : QColorGroup::Foreground ) );
- p->drawText( x, yPos, text() );
+ QColor textColor = palette().color( QPalette::Normal, sel ? \
+ QColorGroup::HighlightedText : QColorGroup::Foreground );
+ p->setPen( textColor );
+
+ // try to fade out the text if it does not fit
+ QString t = text();
+ int maxW = listBox()->width() - x;
+ if ( ( fm.boundingRect( t ).width() > maxW ) && ( t.length() > 1 ) ) {
+ int wt;
+ int maxIterations = 25; // safety, usually needs <5, worst case <12
+ int offset = 1;
+ while ( maxIterations-- &&
+ ( ( wt = fm.boundingRect( t ).width() ) > maxW ) ) {
+ int approxW = ( t.length() * maxW / wt ) + offset;
+ if ( ( approxW < (int) t.length() ) &&
+ ( fm.boundingRect( t.left( approxW ) ).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);
+ }
+ }
+
+ if (t.length() > 3) {
+ p->drawText( x, yPos, t.left( t.length() - 3 ) );
+ x += fm.width( t.left( t.length() - 3 ) );
+ }
+ int n = QMIN( t.length(), 3);
+ for (int i = 0; i < n; i++) {
+ p->setPen( mixColors( 0.70 - i * 0.25, textColor, bgColor ) );
+ QString s( t.at( t.length() - n + i) );
+ p->drawText( x, yPos, s );
+ x += fm.width( s );
+ }
+ }
+ else
+ p->drawText( x, yPos, t );
}
int MonthViewItem::height(const QListBox *lb) const
@@ -187,7 +240,7 @@ int MonthViewItem::width(const QListBox
x += mReplyPixmap.width()+2;
}
- return( x + lb->fontMetrics().width( text() ) + 1 );
+ return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 );
}
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 9 Jul 2003 00:00:12 -0000
@@ -52,6 +52,10 @@ class KNoScrollListBox: public QListBox
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
void mousePressEvent(QMouseEvent *);
+ void resizeEvent(QResizeEvent *);
+
+ private:
+ bool mSqueezing;
};
["korg-squeeze.png" (image/png)]
_______________________________________________
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