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

List:       kde-devel
Subject:    [PATCH] Bug 88964 - Highlighting of files in Detailed List View
From:       Andre Moreira Magalhaes <andrunko () yahoo ! com ! br>
Date:       2004-10-15 23:19:20
Message-ID: 20041015231920.74503.qmail () web51906 ! mail ! yahoo ! com
[Download RAW message or body]

I did the following patch to the bug 88964 (it only fills all the col
space if allColumnsShowFocus is true (??). 
However SOME applications (knode, amarok ...) that reimplement
"QListViewItem::paintCell", paint the focus rect with wrong size. This
happens because today the draw of the item selection is done in
"paintCell" and the focus rect is draw in "drawContentsOffset". 

I have some ideas what can be done and would like to know what you
think about:
 1) Make the draw of the focus rect be responsibility of the function
paintCell. All the apps that reimplement paintCell to really draw the
item (this is not all the cases), should draw the focus rect if
appropriate. I believe that there is not a lot of apps that need this,
and the change is simple.
 2) All the apps that reimplement paintCell to really draw the item
(this is not all the cases), should reimplement the function
QListViewItem::width, so the function drawContentsOffset will know what
is the correct size of the focus rect (since the current patch uses the
width of the item to draw the focus).

I believe that the first solution is more appropriate since it does not
break binary compatibility, but i'm not sure if it is going to work.

Any other ideas??

Cheers,
Andrunko

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
["bug88964.diff" (text/x-diff)]

--- qt-x11-free-3.3.3/src/widgets/qlistview_orig.cpp	2004-10-14 12:27:18.000000000 \
                -0300
+++ qt-x11-free-3.3.3/src/widgets/qlistview.cpp	2004-10-15 19:12:12.000000000 -0300
@@ -1995,7 +1995,7 @@
 */
 
 void QListViewItem::paintCell( QPainter * p, const QColorGroup & cg,
-			       int column, int width, int align )
+			       int column, int w, int align )
 {
     // Change width() if you change this.
 
@@ -2031,26 +2031,26 @@
 	}
 
 	// if the column width changed and this item was not painted since this change
-	if ( ci && ( ci->width != width || ci->text != t || ci->dirty ) ) {
+	if ( ci && ( ci->width != w || ci->text != t || ci->dirty ) ) {
 	    ci->text = t;
 	    ci->dirty = FALSE;
-	    ci->width = width;
+	    ci->width = w;
 	    ci->truncated = FALSE;
 	    // if we have to do the ellipsis thingy calc the truncated text
 	    int pw = lv->itemMargin()*2 - lv->d->minLeftBearing - lv->d->minRightBearing;
 	    pw += pixmap( column ) ? pixmap( column )->width() + lv->itemMargin() : 0;
-	    if ( !mlenabled && fm.width( t ) + pw > width ) {
+	    if ( !mlenabled && fm.width( t ) + pw > w ) {
 		// take care of arabic shaping in width calculation (lars)
 		ci->truncated = TRUE;
-		ci->tmpText = qEllipsisText( t, fm, width - pw, align );
-	    } else if ( mlenabled && fm.width( t ) + pw > width ) {
+		ci->tmpText = qEllipsisText( t, fm, w - pw, align );
+	    } else if ( mlenabled && fm.width( t ) + pw > w ) {
 #ifndef QT_NO_STRINGLIST
 		QStringList list = QStringList::split( QChar('\n'), t, TRUE );
 		for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
 		    QString z = *it;
-		    if ( fm.width( z ) + pw > width ) {
+		    if ( fm.width( z ) + pw > w ) {
 			ci->truncated = TRUE;
-			*it = qEllipsisText( z, fm, width - pw, align );
+			*it = qEllipsisText( z, fm, w - pw, align );
 		    }
 		}
 
@@ -2072,9 +2072,9 @@
     const BackgroundMode bgmode = lv->viewport()->backgroundMode();
     const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );
     if ( cg.brush( crole ) != lv->colorGroup().brush( crole ) )
-	p->fillRect( 0, 0, width, height(), cg.brush( crole ) );
+	p->fillRect( 0, 0, w, height(), cg.brush( crole ) );
     else
-	lv->paintEmptyArea( p, QRect( 0, 0, width, height() ) );
+	lv->paintEmptyArea( p, QRect( 0, 0, w, height() ) );
 
 
     // (lars) what does this do???
@@ -2084,8 +2084,16 @@
 #endif
     if ( isSelected() &&
 	 (column == 0 || lv->allColumnsShowFocus()) ) {
-	p->fillRect( r - marg, 0, width - r + marg, height(),
-		     cg.brush( QColorGroup::Highlight ) );
+	if ( lv->allColumnsShowFocus() )
+	{
+	    p->fillRect( r - marg, 0, w - r + marg, height(),
+	                 cg.brush( QColorGroup::Highlight ) );
+	}
+	else
+	{
+	    p->fillRect( r - marg, 0, width( fm, lv, column ) - r + marg, height(),
+	                 cg.brush( QColorGroup::Highlight ) );
+	}
 	if ( enabled || !lv )
 	    p->setPen( cg.highlightedText() );
 	else if ( !enabled && lv)
@@ -2120,12 +2128,12 @@
 	// respect horizontal alignment when there is no text for an item.
 	if ( text(column).isEmpty() ) {
 	    if ( align & AlignRight )
-		xo = width - 2 * marg - iconWidth;
+		xo = w - 2 * marg - iconWidth;
 	    else if ( align & AlignHCenter )
-		xo = ( width - iconWidth ) / 2;
+		xo = ( w - iconWidth ) / 2;
 	}
 	if ( reverse )
-		xo = width - 2 * marg - iconWidth;
+		xo = w - 2 * marg - iconWidth;
 	p->drawPixmap( xo, yo, *icon );
     }
 
@@ -2141,9 +2149,9 @@
 	    r += iconWidth;
 
 	if ( !mlenabled ) {
-	    p->drawText( r, 0, width-marg-r, height(), align, t );
+	    p->drawText( r, 0, w - marg - r, height(), align, t );
 	} else {
-	    p->drawText( r, marg, width-marg-r, height(), align, t );
+	    p->drawText( r, marg, w - marg - r, height(), align, t );
 	}
     }
 
@@ -2853,6 +2861,7 @@
     int tx = -1;
     QListViewPrivate::DrawableItem * current;
 
+    bool fillAll = allColumnsShowFocus();
     while ( (current = it.current()) != 0 ) {
 	++it;
 	if ( !current->i->isVisible() )
@@ -2933,12 +2942,18 @@
 	    }
 
 	    if ( current->i == d->focusItem && hasFocus() &&
-		 !d->allColumnsShowFocus ) {
+		 !fillAll) {
 		p->save();
 		int cell = d->h->mapToActual( 0 );
-		QRect r( d->h->cellPos( cell ) - ox, current->y - oy, d->h->cellSize( cell ), ih \
                );
-		if ( current->i->parentItem )
-		    r.setLeft( r.left() + current->l * treeStepSize() );
+		QRect r( d->h->cellPos( cell ) - ox, current->y - oy, current->i->width( \
fontMetrics(), this, cell ), ih ); +		if ( current->i->parentItem ) {
+		    int offset = current->l * treeStepSize();
+		    r.setLeft( r.left() + offset );
+		    r.setWidth( r.width() + offset );
+
+		    if ( r.right() > d->h->sectionRect( cell ).right() )
+		        r.setRight( d->h->sectionRect( cell ).right() - 1 );
+		}
 		if ( r.left() < r.right() )
 		    current->i->paintFocus( p, colorGroup(), r );
 		p->restore();
@@ -2949,7 +2964,7 @@
 
 	// does current need focus indication?
 	if ( current->i == d->focusItem && hasFocus() &&
-	     d->allColumnsShowFocus ) {
+	     fillAll ) {
 	    p->save();
 	    int x = -contentsX();
 	    int w = header()->cellPos( header()->count() - 1 ) +



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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