From a6425b78e205c830426238fea1115d6d1fbd938c Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Wed, 29 Dec 2010 10:26:54 +0000 Subject: [PATCH] properly set title position for "Center (Full Width)" configuration. Simplified title centering logic. svn path=/trunk/KDE/kdebase/workspace/; revision=1210060 --- clients/oxygen/oxygenclient.cpp | 45 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index 4fee1b7c8e..1310758cd8 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -376,15 +376,25 @@ namespace Oxygen { QRect titleRect( this->titleRect().adjusted( 0, -layoutMetric( LM_TitleEdgeTop ), 0, 0 ) ); + + // when drawing title outline, shrink the rect so that it matches the actual caption size if( active && configuration().drawTitleOutline() && isActive() ) { + + if( configuration().centerTitleOnFullWidth() ) + { + titleRect.setLeft( widget()->rect().left() + layoutMetric( LM_OuterPaddingLeft ) ); + titleRect.setRight( widget()->rect().right() - layoutMetric( LM_OuterPaddingRight ) ); + } + const QRect textRect( titleBoundingRect( options()->font( true, false), titleRect, caption() ) ); titleRect.setLeft( textRect.left() - layoutMetric( LM_TitleBorderLeft ) ); titleRect.setRight( textRect.right() + layoutMetric( LM_TitleBorderRight ) ); } else { + // buttons are properly accounted for in titleBoundingRect method titleRect.setLeft( widget()->rect().left() + layoutMetric( LM_OuterPaddingLeft ) ); titleRect.setRight( widget()->rect().right() - layoutMetric( LM_OuterPaddingRight ) ); @@ -408,8 +418,19 @@ namespace Oxygen boundingRect.setBottom( rect.bottom() ); // check bounding rect against input rect - if( rect.left() > boundingRect.left() ) { boundingRect.setLeft( rect.left() ); } - if( rect.right() < boundingRect.right() ) { boundingRect.setRight( rect.right() ); } + boundingRect.setLeft( qMax( rect.left(), boundingRect.left() ) ); + boundingRect.setRight( qMin( rect.right(), boundingRect.right() ) ); + + if( configuration().centerTitleOnFullWidth() ) + { + /* + check bounding rect against max available space, for buttons + this is not needed if centerTitleOnFullWidth flag is set to false, + because it was already done before calling titleBoundingRect + */ + boundingRect.setLeft( qMax( titleRect().left(), boundingRect.left() ) ); + boundingRect.setRight( qMin( titleRect().right(), boundingRect.right() ) ); + } return boundingRect; @@ -879,7 +900,7 @@ namespace Oxygen // see if tag is active const int itemCount( itemData_.count() ); - // + // check item bounding rect if( !item.boundingRect_.isValid() ) return; // create rect in which text is to be drawn @@ -900,10 +921,16 @@ namespace Oxygen const QList< ClientGroupItem >& items( clientGroupItems() ); const QString caption( itemCount == 1 ? this->caption() : items[index].title() ); - // always make sure that titleRect never conflicts with window buttons - QRect titleRect( this->titleRect() ); - if( titleRect.left() > textRect.left() ) { textRect.setLeft( titleRect.left() ); } - if( titleRect.right() < textRect.right() ) { textRect.setRight( titleRect.right() ); } + if( !configuration().centerTitleOnFullWidth() ) + { + // always make sure that titleRect never conflicts with window buttons + QRect titleRect( this->titleRect() ); + if( titleRect.left() > textRect.left() ) { textRect.setLeft( titleRect.left() ); } + if( titleRect.right() < textRect.right() ) { textRect.setRight( titleRect.right() ); } + } + + // adjust textRect + textRect = titleBoundingRect( painter->font(), textRect, caption ); // title outline if( itemCount == 1 ) @@ -914,14 +941,10 @@ namespace Oxygen { if( itemData_.isAnimated() ) { - textRect = titleBoundingRect( painter->font(), textRect, caption ); renderTitleOutline( painter, item.boundingRect_, palette ); } else if( (isActive()||glowIsAnimated()) && configuration().drawTitleOutline() ) { - // adjust textRect - textRect = titleBoundingRect( painter->font(), textRect, caption ); - // adjusts boundingRect accordingly QRect boundingRect( item.boundingRect_ ); boundingRect.setLeft( textRect.left() - layoutMetric( LM_TitleBorderLeft ) );