From 9ff89e1768d9c0d3ecb08d40ead320d9b4edbafc Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Sat, 14 Nov 2009 04:19:09 +0000 Subject: [PATCH] Added contrast pixel on titlebar text. This creates 'carved-in' font, as a possible replacement to bold. Implemented after discussion with pinheiro. svn path=/trunk/KDE/kdebase/workspace/; revision=1048886 --- clients/oxygen/oxygenclient.cpp | 53 +++++++++++++++++++++++++++++---- clients/oxygen/oxygenclient.h | 12 ++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index b0f730e727..b4f5fc169b 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -391,6 +391,21 @@ namespace Oxygen } + + //_________________________________________________________ + QColor OxygenClient::titlebarContrastColor(const QPalette &palette) + { + if( timeLineIsRunning() ) return KColorUtils::mix( + titlebarContrastColor( palette, false ), + titlebarContrastColor( palette, true ), + opacity() ); + else return titlebarContrastColor( palette, isActive() ); + } + + //_________________________________________________________ + QColor OxygenClient::titlebarContrastColor(const QPalette &palette, bool active) + { return helper().calcLightColor( palette.color( widget()->window()->backgroundRole() ) ); } + //_________________________________________________________ void OxygenClient::renderWindowBackground( QPainter* painter, const QRect& rect, const QWidget* widget, const QPalette& palette ) const { @@ -611,29 +626,53 @@ namespace Oxygen } //_________________________________________________________ - void OxygenClient::renderTitleText( QPainter* painter, const QRect& rect, QColor color ) const + void OxygenClient::renderTitleText( QPainter* painter, const QRect& rect, const QColor& color, const QColor& contrast ) const { if( titleTimeLineIsRunning() ) { - if( !oldCaption().isEmpty() ) renderTitleText( painter, rect, oldCaption(), helper().alphaColor( color, 1.0 - titleOpacity() ) ); - if( !caption().isEmpty() ) renderTitleText( painter, rect, caption(), helper().alphaColor( color, titleOpacity() ) ); + if( !oldCaption().isEmpty() ) { + + renderTitleText( + painter, rect, oldCaption(), + helper().alphaColor( color, 1.0 - titleOpacity() ), + contrast.isValid() ? helper().alphaColor( contrast, 1.0 - titleOpacity() ):contrast ); + + } + + if( !caption().isEmpty() ) { + + renderTitleText( + painter, rect, caption(), + helper().alphaColor( color, titleOpacity() ), + contrast.isValid() ? helper().alphaColor( contrast, titleOpacity() ):contrast ); + + } } else if( !caption().isEmpty() ) { - renderTitleText( painter, rect, caption(), color ); + renderTitleText( painter, rect, caption(), color, contrast ); } } //_______________________________________________________________________ - void OxygenClient::renderTitleText( QPainter* painter, const QRect& rect, const QString& caption, const QColor& color ) const + void OxygenClient::renderTitleText( QPainter* painter, const QRect& rect, const QString& caption, const QColor& color, const QColor& contrast ) const { Qt::Alignment alignment( configuration().titleAlignment() | Qt::AlignVCenter ); QString local( QFontMetrics( painter->font() ).elidedText( caption, Qt::ElideRight, rect.width() ) ); + + if( contrast.isValid() ) + { + painter->setPen( contrast ); + painter->translate( 0, 1 ); + painter->drawText( rect, alignment, local ); + painter->translate( 0, -1 ); + } + painter->setPen( color ); painter->drawText( rect, alignment, local ); @@ -983,7 +1022,9 @@ namespace Oxygen } // title text - renderTitleText( &painter, boundingRect, titlebarTextColor( backgroundPalette( widget(), palette ) ) ); + renderTitleText( &painter, boundingRect, + titlebarTextColor( palette ), + titlebarContrastColor( palette ) ); // separator if( drawSeparator() ) renderSeparator(&painter, frame, widget(), color ); diff --git a/clients/oxygen/oxygenclient.h b/clients/oxygen/oxygenclient.h index 357a75feb1..01a947091a 100644 --- a/clients/oxygen/oxygenclient.h +++ b/clients/oxygen/oxygenclient.h @@ -192,10 +192,12 @@ namespace Oxygen virtual void renderTitleOutline( QPainter*, const QRect&, const QPalette& ) const; //! title text - virtual void renderTitleText( QPainter*, const QRect&, QColor ) const; + /*! second color, if valid, is for contrast pixel */ + virtual void renderTitleText( QPainter*, const QRect&, const QColor&, const QColor& = QColor() ) const; //! title text - virtual void renderTitleText( QPainter*, const QRect&, const QString&, const QColor& ) const; + /*! second color, if valid, is for contrast pixel */ + virtual void renderTitleText( QPainter*, const QRect&, const QString&, const QColor&, const QColor& = QColor() ) const; //! render float frame virtual void renderFloatFrame( QPainter*, const QRect&, const QPalette& ) const; @@ -244,6 +246,12 @@ namespace Oxygen //! text color QColor titlebarTextColor(const QPalette&, bool active); + //! text color + QColor titlebarContrastColor(const QPalette&); + + //! text color + QColor titlebarContrastColor(const QPalette&, bool active); + //!@name size grip //@{