From 7997df83e41cc06c829f8b5f340a14724bac197c Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 22 Sep 2006 06:08:02 +0000 Subject: [PATCH] PAL12492 - if the font of dockwindow title is greater than height of title, than text will be partly cropped --- src/Style/SalomeStyle.cxx | 36 +++++++++++++++++++++++------------- src/Style/SalomeStyle.h | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Style/SalomeStyle.cxx b/src/Style/SalomeStyle.cxx index d35196cf5..724bf32fb 100644 --- a/src/Style/SalomeStyle.cxx +++ b/src/Style/SalomeStyle.cxx @@ -483,22 +483,25 @@ void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& int textW = flags & Style_Horizontal ? rt.height() : rt.width(); int textH = flags & Style_Horizontal ? rt.width() : rt.height(); - QString title = titleText( wnd->caption(), textW, p->fontMetrics() ); - - if ( wnd ) + QFont old_font = p->font(), f = old_font; + + QString title = titleText( wnd->caption(), textW, textH, f ); + p->setFont( f ); + if ( wnd ) { - QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive(); - p->setPen( cgroup.highlightedText() ); + QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive(); + p->setPen( cgroup.highlightedText() ); - if ( flags & Style_Horizontal ) + if ( flags & Style_Horizontal ) { - p->rotate( 270.0 ); - p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) ); - p->drawText( 0, 0, title ); - } + p->rotate( 270.0 ); + p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) ); + p->drawText( 0, 0, title ); + } else - p->drawText( 2, 2, textW, textH, AlignLeft, title ); - } + p->drawText( 2, 2, textW, textH, AlignLeft, title ); + } + p->setFont( old_font ); } break; } @@ -1279,10 +1282,17 @@ int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const \param w - possible width \param fm - font metrics */ -QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const +QString SalomeStyle::titleText( const QString& txt, const int W, const int H, QFont& f ) const { QString res = txt.stripWhiteSpace(); + QFontMetrics fm( f ); + while( fm.height() > H ) + { + f.setPointSize( f.pointSize()-1 ); + fm = QFontMetrics( f ); + } + if ( fm.width( res ) > W ) { QString end( "..." ); diff --git a/src/Style/SalomeStyle.h b/src/Style/SalomeStyle.h index e6cdd5807..e87ebf16d 100644 --- a/src/Style/SalomeStyle.h +++ b/src/Style/SalomeStyle.h @@ -92,7 +92,7 @@ protected: void drawGradient( QPainter*, const QRect&, const QColor&, const QColor&, const Direction, gradient_func ) const; - QString titleText( const QString&, const int, const QFontMetrics& ) const; + QString titleText( const QString&, const int, const int, QFont& f ) const; private: QWidget* myTitleParent; -- 2.39.2