From: mkr Date: Fri, 4 Apr 2008 13:49:01 +0000 (+0000) Subject: Fix for bug IPAL19450 : QT4 porting: corrupted spinbox in preferences - set color. X-Git-Tag: V5_0_0~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1a9a1fb9a88d18a24c331d104c11cf3de69b8ed2;p=modules%2Fgui.git Fix for bug IPAL19450 : QT4 porting: corrupted spinbox in preferences - set color. --- diff --git a/src/Style/Style_Salome.cxx b/src/Style/Style_Salome.cxx index fa27e9af0..58b302c2a 100644 --- a/src/Style/Style_Salome.cxx +++ b/src/Style/Style_Salome.cxx @@ -278,7 +278,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp pe = (spin->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus : PE_IndicatorSpinUp); copy.rect = aBtnRect; - drawPrimitive(PE_IndicatorSpinUp, ©, p, w); + drawPrimitive(pe, ©, p, w); } if (spin->subControls & SC_SpinBoxDown) { copy.subControls = SC_SpinBoxDown; @@ -1362,7 +1362,9 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorSpinUp: - case PE_IndicatorSpinDown: { + case PE_IndicatorSpinDown: + case PE_IndicatorSpinPlus: + case PE_IndicatorSpinMinus: { QRect rect = opt->rect; QColor pen, brush; if ( opt->state & State_Enabled ) { @@ -1374,7 +1376,10 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, pen = opt->palette.mid().color(); brush = pen; } - Style_Tools::drawArrow( pe, p, rect, pen, brush ); + if ( pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinMinus ) + Style_Tools::drawSign( pe, p, rect, pen, brush ); + else + Style_Tools::drawArrow( pe, p, rect, pen, brush ); break; } case PE_IndicatorCheckBox: { diff --git a/src/Style/Style_Tools.cxx b/src/Style/Style_Tools.cxx index 08e0abe56..390fa1332 100644 --- a/src/Style/Style_Tools.cxx +++ b/src/Style/Style_Tools.cxx @@ -338,6 +338,77 @@ void Style_Tools::drawArrow( QStyle::PrimitiveElement type, QPainter* p, const Q p->restore(); } +void Style_Tools::drawSign( QStyle::PrimitiveElement type, QPainter* p, const QRect& r, + const QColor& pen, const QColor& brush ) +{ + p->save(); + QPainterPath sign; + int x = r.x(), y = r.y(), w = r.right()-x, h = r.bottom()-y; + int x11 = 0, x12 = 0, y11 = 0, y12 = 0; + int aDelta = qMin( (int)(w/3.5), (int)(h/3.5) ); + int deltaX = aDelta, deltaY = aDelta; + QLineF line( 0, 0, 1, 0 ); + int xc = r.center().x(), yc = r.center().y(); + p->translate( xc, yc ); + bool correct = false; + switch( type ) { + case QStyle::PE_IndicatorSpinMinus: + correct = true; + case QStyle::PE_IndicatorSpinPlus: { + aDelta = (int)(deltaY/2); + if ( correct ) { + aDelta = -aDelta; + deltaY = -deltaY; + } + if ( correct ) + sign.moveTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) ); + else { + sign.moveTo( aDelta/3, -aDelta/2 ); + sign.lineTo( aDelta/3, -aDelta/2-(deltaY/2-aDelta/3) ); + sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) ); + } + + sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 ); + + if ( !correct ) { + sign.lineTo( aDelta/3, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 ); + sign.lineTo( aDelta/3, -aDelta/2-deltaY ); + sign.lineTo( -aDelta/3, -aDelta/2-deltaY ); + sign.lineTo( -aDelta/3, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 ); + } + + sign.lineTo( -deltaY/2, -aDelta/2-(deltaY/2-aDelta/3)-2*aDelta/3 ); + sign.lineTo( -deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) ); + + if ( correct ) + sign.lineTo( deltaY/2, -aDelta/2-(deltaY/2-aDelta/3) ); + else { + sign.lineTo( -aDelta/3, -aDelta/2-(deltaY/2-aDelta/3) ); + sign.lineTo( -aDelta/3, -aDelta/2 ); + sign.lineTo( aDelta/3, -aDelta/2); + } + + if ( correct ) + deltaX = -deltaX; + x11 = -deltaX, y11 = -deltaY, x12 = deltaX, y12 = 0; + break; + } + default: + p->restore(); + return; + } + p->setPen( pen ); + p->setBrush( brush ); + + QLinearGradient gr( x11, y11, x12, y12 ); + gr.setColorAt( 0.0, pen ); // grayer + gr.setColorAt( 1.0, brush); // lighter + p->fillPath( sign, gr ); + p->strokePath( sign, QPen( pen, Qt::SolidLine ) ); + + p->restore(); +} + QPainterPath Style_Tools::tabRect( QPainter* p, const QRect& r, const int position, const double rad, const double delta, const QColor& light, const QColor& dark, const QColor& border_top, const QColor& border_bot, diff --git a/src/Style/Style_Tools.h b/src/Style/Style_Tools.h index 381c5a3d2..06ddc54b3 100644 --- a/src/Style/Style_Tools.h +++ b/src/Style/Style_Tools.h @@ -68,6 +68,8 @@ public: const QColor&, const int = 255 ); static void drawArrow( QStyle::PrimitiveElement, QPainter*, const QRect&, const QColor&, const QColor& ); + static void drawSign( QStyle::PrimitiveElement, QPainter*, const QRect&, + const QColor&, const QColor& ); static QPainterPath tabRect( QPainter*, const QRect&, const int, const double, const double, const QColor&, const QColor&, const QColor&, const QColor&,