From kde-core-devel Sat May 28 14:32:04 2005 From: Luciano Montanaro Date: Sat, 28 May 2005 14:32:04 +0000 To: kde-core-devel Subject: [PATCH] make kselect, kxyselect widgets use a styled border Message-Id: <200505281632.10069.mikelima () cirulla ! net> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=111729049927039 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart14904785.GMnysi9Onf" --nextPart14904785.GMnysi9Onf Content-Type: multipart/mixed; boundary="Boundary-01=_kDImCtzgi0TwC8t" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_kDImCtzgi0TwC8t Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Currently, these classes simply draw a bevel around their contents. This patch makes them use the sunken PE_Panel primitive. You can check the effect it has on the widgets using the colors kcm module. Additionally, it makes the KXYSelect border at least as wide as the KSelect frame. These classes are often used together, and I think that makes them l= ook=20 a bit better in this case. I had to change much more than what I thought it wuld need... There are other classes that could use the same treatment. With styles like highcontrast, unstyled widgets pop out quite a lot. I'd like to commit this change, is it ok with everybody? =2D-=20 Luciano Montanaro // \X/ mikelima@cirulla.net --Boundary-01=_kDImCtzgi0TwC8t Content-Type: text/x-diff; charset="us-ascii"; name="kselect.cpp.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kselect.cpp.patch" Index: kselect.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kselect.cpp (revision 418955) +++ kselect.cpp (working copy) @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "kselect.h" =20 @@ -52,8 +53,9 @@ =20 void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) { =2D px =3D 2; =2D py =3D 2; + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + px =3D w; + py =3D w; minX =3D _minX; minY =3D _minY; maxX =3D _maxX; @@ -72,6 +74,9 @@ =20 void KXYSelector::setValues( int _xPos, int _yPos ) { + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + if (w < 5) w =3D 5; + xPos =3D _xPos; yPos =3D _yPos; =20 @@ -85,28 +90,41 @@ else if ( yPos < minY ) yPos =3D minY; =20 =2D int xp =3D 2 + (width() - 4) * xPos / (maxX - minX); =2D int yp =3D height() - 2 - (height() - 4) * yPos / (maxY - minY); + int xp =3D w + (width() - 2 * w) * xPos / (maxX - minX); + int yp =3D height() - w - (height() - 2 * w) * yPos / (maxY - minY); =20 setPosition( xp, yp ); } =20 QRect KXYSelector::contentsRect() const { =2D return QRect( 2, 2, width()-4, height()-4 ); + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + if (w < 5) { + w =3D 5; + } + QRect contents(rect()); + contents.addCoords(w, w, -w, -w); + return contents; } =20 void KXYSelector::paintEvent( QPaintEvent *ev ) { QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); QRect paintRect =3D ev->rect(); + QRect borderRect =3D rect(); =20 + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + if (w < 5) { + w =3D 5 - w; + } + borderRect.addCoords(w, w, -w, -w); + QPainter painter; painter.begin( this ); =20 =2D QBrush brush; =2D qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), =2D true, 2, &brush ); + style().drawPrimitive(QStyle::PE_Panel, &painter,=20 + borderRect, colorGroup(),=20 + QStyle::Style_Sunken); =20 drawContents( &painter ); if (paintRect.contains(cursorRect)) @@ -125,19 +143,18 @@ =20 void KXYSelector::mousePressEvent( QMouseEvent *e ) { =2D int xVal, yVal; =2D valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); =2D setValues( xVal, yVal ); =2D =2D emit valueChanged( xPos, yPos ); + mouseMoveEvent(e); } =20 void KXYSelector::mouseMoveEvent( QMouseEvent *e ) { int xVal, yVal; =2D valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); + + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + valuesFromPosition( e->pos().x() - w, e->pos().y() - w, xVal, yVal ); +=09 setValues( xVal, yVal ); =2D=09 + emit valueChanged( xPos, yPos ); } =20 @@ -153,8 +170,10 @@ =20 void KXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal )= const { =2D xVal =3D ( (maxX-minX) * (x-2) ) / ( width()-4 ); =2D yVal =3D maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + if (w < 5) w =3D 5; + xVal =3D ( (maxX-minX) * (x-w) ) / ( width()-2*w ); + yVal =3D maxY - ( ( (maxY-minY) * (y-w) ) / ( height()-2*w ) ); =09 if ( xVal > maxX ) xVal =3D maxX; @@ -169,15 +188,17 @@ =20 void KXYSelector::setPosition( int xp, int yp ) { =2D if ( xp < 2 ) =2D xp =3D 2; =2D else if ( xp > width() - 2 ) =2D xp =3D width() - 2; + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + if (w < 5) w =3D 5; + if ( xp < w ) + xp =3D w; + else if ( xp > width() - w ) + xp =3D width() - w; =20 =2D if ( yp < 2 ) =2D yp =3D 2; =2D else if ( yp > height() - 2 ) =2D yp =3D height() - 2; + if ( yp < w ) + yp =3D w; + else if ( yp > height() - w ) + yp =3D height() - w; =20 QPainter painter; painter.begin( this ); @@ -235,30 +256,34 @@ =20 QRect KSelector::contentsRect() const { + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + int iw =3D (w < 5) ? 5 : w; if ( orientation() =3D=3D Vertical ) =2D return QRect( 2, 5, width()-9, height()-10 ); + return QRect( w, iw, width() - w * 2 - 5, height() - 2 * iw ); else =2D return QRect( 5, 2, width()-10, height()-9 ); + return QRect( iw, w, width() - 2 * iw, height() - w * 2 - 5 ); } =20 void KSelector::paintEvent( QPaintEvent * ) { QPainter painter; + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + int iw =3D (w < 5) ? 5 : w; =20 painter.begin( this ); =20 drawContents( &painter ); =20 =2D QBrush brush; =2D if ( indent() ) { + QRect r =3D rect(); if ( orientation() =3D=3D Vertical ) =2D qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, =2D colorGroup(), true, 2, &brush ); + r.addCoords(0, iw - w, -iw, w - iw); else =2D qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, =2D colorGroup(), true, 2, &brush ); + r.addCoords(iw - w, 0, w - iw, -iw); + style().drawPrimitive(QStyle::PE_Panel, &painter,=20 + r, colorGroup(),=20 + QStyle::Style_Sunken); } =20 QPoint pos =3D calcArrowPos( value() ); @@ -304,13 +329,15 @@ void KSelector::moveArrow( const QPoint &pos ) { int val; + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + int iw =3D (w < 5) ? 5 : w; =20 if ( orientation() =3D=3D Vertical ) =2D val =3D ( maxValue() - minValue() ) * (height()-pos.y()-3) =2D / (height()-10) + minValue(); + val =3D ( maxValue() - minValue() ) * (height()-pos.y()-5+w) + / (height()-iw*2) + minValue(); else =2D val =3D ( maxValue() - minValue() ) * (width()-pos.x()-3) =2D / (width()-10) + minValue(); + val =3D ( maxValue() - minValue() ) * (width()-pos.x()-5+w) + / (width()-iw*2) + minValue(); =20 setValue( val ); } @@ -319,15 +346,17 @@ { QPoint p; =20 + int w =3D style().pixelMetric(QStyle::PM_DefaultFrameWidth); + int iw =3D (w < 5) ? 5 : w; if ( orientation() =3D=3D Vertical ) { =2D p.setY( height() - ( (height()-10) * val + p.setY( height() - ( (height()-2*iw) * val / ( maxValue() - minValue() ) + 5 ) ); p.setX( width() - 5 ); } else { =2D p.setX( width() - ( (width()-10) * val + p.setX( width() - ( (width()-2*iw) * val / ( maxValue() - minValue() ) + 5 ) ); p.setY( height() - 5 ); } @@ -346,16 +375,14 @@ =20 painter->setPen( QPen() ); painter->setBrush( QBrush( colorGroup().buttonText() ) ); + array.setPoint( 0, pos.x()+0, pos.y()+0 ); + array.setPoint( 1, pos.x()+5, pos.y()+5 ); if ( orientation() =3D=3D Vertical ) { =2D array.setPoint( 0, pos.x()+0, pos.y()+0 ); =2D array.setPoint( 1, pos.x()+5, pos.y()+5 ); array.setPoint( 2, pos.x()+5, pos.y()-5 ); } else { =2D array.setPoint( 0, pos.x()+0, pos.y()+0 ); =2D array.setPoint( 1, pos.x()+5, pos.y()+5 ); array.setPoint( 2, pos.x()-5, pos.y()+5 ); } =20 @@ -421,8 +448,8 @@ { scale =3D 1.0 * y / image.height(); col.setRgb( color1.red() + int(redDiff*scale), =2D color1.green() + int(greenDiff*scale), =2D color1.blue() + int(blueDiff*scale) ); + color1.green() + int(greenDiff*scale), + color1.blue() + int(blueDiff*scale) ); =20 unsigned int *p =3D (uint *) image.scanLine( y ); for ( int x =3D 0; x < image.width(); x++ ) @@ -437,8 +464,8 @@ { scale =3D 1.0 * x / image.width(); col.setRgb( color1.red() + int(redDiff*scale), =2D color1.green() + int(greenDiff*scale), =2D color1.blue() + int(blueDiff*scale) ); + color1.green() + int(greenDiff*scale), + color1.blue() + int(blueDiff*scale) ); *p++ =3D col.rgb(); } =20 @@ -451,8 +478,8 @@ =20 for ( int s =3D 0; s < 8; s++ ) ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, =2D color1.green() + greenDiff * s / 8, =2D color1.blue() + blueDiff * s / 8 ); + color1.green() + greenDiff * s / 8, + color1.blue() + blueDiff * s / 8 ); =20 KImageEffect::dither( image, ditherPalette, 8 ); =20 --Boundary-01=_kDImCtzgi0TwC8t-- --nextPart14904785.GMnysi9Onf Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQBCmIDqaeOY6B53J4URArL4AKCENSeT8RFscRYh73dRHEzmh6leuQCeITH8 bZt4+o5bUmVYMmu7TEdmK40= =vInf -----END PGP SIGNATURE----- --nextPart14904785.GMnysi9Onf--