21 #include <tqpainter.h>
22 #include <tqdrawutil.h>
24 #include <kimageeffect.h>
25 #include "tdeselect.h"
28 #define STORE_W2 STORE_W * 2
37 : TQWidget( parent, name )
45 store.setOptimization( TQPixmap::BestOptim );
46 store.resize( STORE_W2, STORE_W2 );
56 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
77 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
85 else if ( xPos < minX )
90 else if ( yPos < minY )
93 int xp = w + (width() - 2 * w) * xPos / (maxX - minX);
94 int yp = height() - w - (height() - 2 * w) * yPos / (maxY - minY);
96 setPosition( xp, yp );
101 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
105 TQRect contents(rect());
106 contents.addCoords(w, w, -w, -w);
110 void KXYSelector::paintEvent( TQPaintEvent *ev )
112 TQRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2);
113 TQRect paintRect = ev->rect();
114 TQRect borderRect = rect();
116 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
120 borderRect.addCoords(w, w, -w, -w);
123 painter.begin(
this );
125 style().drawPrimitive(TQStyle::PE_Panel, &painter,
126 borderRect, colorGroup(),
127 TQStyle::Style_Sunken);
130 if (paintRect.contains(cursorRect))
132 bitBlt( &store, 0, 0,
this, px - STORE_W, py - STORE_W,
133 STORE_W2, STORE_W2, CopyROP );
136 else if (paintRect.intersects(cursorRect))
138 repaint( cursorRect,
false);
144 void KXYSelector::mousePressEvent( TQMouseEvent *e )
149 void KXYSelector::mouseMoveEvent( TQMouseEvent *e )
153 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
161 void KXYSelector::wheelEvent( TQWheelEvent *e )
163 if ( e->orientation() == TQt::Horizontal )
173 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
175 xVal = ( (maxX-minX) * (x-w) ) / ( width()-2*w );
176 yVal = maxY - ( ( (maxY-minY) * (y-w) ) / ( height()-2*w ) );
180 else if ( xVal < minX )
185 else if ( yVal < minY )
189 void KXYSelector::setPosition(
int xp,
int yp )
191 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
195 else if ( xp > width() - w )
200 else if ( yp > height() - w )
204 painter.begin(
this );
206 bitBlt(
this, px - STORE_W, py - STORE_W, &store, 0, 0,
207 STORE_W2, STORE_W2, CopyROP );
208 bitBlt( &store, 0, 0,
this, xp - STORE_W, yp - STORE_W,
209 STORE_W2, STORE_W2, CopyROP );
223 p->setPen( TQPen( white ) );
225 p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
226 p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 );
227 p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 );
228 p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 );
239 : TQWidget( parent, name ), TQRangeControl()
241 _orientation = TQt::Horizontal;
246 : TQWidget( parent, name ), TQRangeControl()
253 TDESelector::~TDESelector()
259 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
260 int iw = (w < 5) ? 5 : w;
262 return TQRect( w, iw, width() - w * 2 - 5, height() - 2 * iw );
264 return TQRect( iw, w, width() - 2 * iw, height() - w * 2 - 5 );
267 void TDESelector::paintEvent( TQPaintEvent * )
270 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
271 int iw = (w < 5) ? 5 : w;
273 painter.begin(
this );
281 r.addCoords(0, iw - w, -iw, w - iw);
283 r.addCoords(iw - w, 0, w - iw, -iw);
284 style().drawPrimitive(TQStyle::PE_Panel, &painter,
286 TQStyle::Style_Sunken);
289 TQPoint pos = calcArrowPos(
value() );
295 void TDESelector::mousePressEvent( TQMouseEvent *e )
297 moveArrow( e->pos() );
300 void TDESelector::mouseMoveEvent( TQMouseEvent *e )
302 moveArrow( e->pos() );
305 void TDESelector::wheelEvent( TQWheelEvent *e )
307 int val =
value() + e->delta()/120;
311 void TDESelector::valueChange()
316 painter.begin(
this );
318 pos = calcArrowPos( prevValue() );
321 pos = calcArrowPos(
value() );
329 void TDESelector::moveArrow(
const TQPoint &pos )
332 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
333 int iw = (w < 5) ? 5 : w;
345 TQPoint TDESelector::calcArrowPos(
int val )
349 int w = style().pixelMetric(TQStyle::PM_DefaultFrameWidth);
350 int iw = (w < 5) ? 5 : w;
353 p.setY( height() - ( (height()-2*iw) * val
355 p.setX( width() - 5 );
359 p.setX( width() - ( (width()-2*iw) * val
361 p.setY( height() - 5 );
374 TQPointArray array(3);
376 painter->setPen( TQPen() );
377 painter->setBrush( TQBrush( colorGroup().buttonText() ) );
378 array.setPoint( 0, pos.x()+0, pos.y()+0 );
379 array.setPoint( 1, pos.x()+5, pos.y()+5 );
382 array.setPoint( 2, pos.x()+5, pos.y()-5 );
386 array.setPoint( 2, pos.x()-5, pos.y()+5 );
389 painter->drawPolygon( array );
395 repaint(pos.x(), pos.y()-5, 6, 11,
true);
399 repaint(pos.x()-5, pos.y(), 11, 6,
true);
425 void KGradientSelector::init()
427 color1.setRgb( 0, 0, 0 );
428 color2.setRgb( 255, 255, 255 );
441 int redDiff = color2.red() - color1.red();
442 int greenDiff = color2.green() - color1.green();
443 int blueDiff = color2.blue() - color1.blue();
447 for (
int y = 0; y < image.height(); y++ )
449 scale = 1.0 * y / image.height();
450 col.setRgb( color1.red() +
int(redDiff*scale),
451 color1.green() +
int(greenDiff*scale),
452 color1.blue() +
int(blueDiff*scale) );
454 unsigned int *p = (uint *) image.scanLine( y );
455 for (
int x = 0; x < image.width(); x++ )
461 unsigned int *p = (uint *) image.scanLine( 0 );
463 for (
int x = 0; x < image.width(); x++ )
465 scale = 1.0 * x / image.width();
466 col.setRgb( color1.red() + int(redDiff*scale),
467 color1.green() + int(greenDiff*scale),
468 color1.blue() + int(blueDiff*scale) );
472 for (
int y = 1; y < image.height(); y++ )
473 memcpy( image.scanLine( y ), image.scanLine( y - 1),
474 sizeof(
unsigned int ) * image.width() );
477 TQColor ditherPalette[8];
479 for (
int s = 0; s < 8; s++ )
480 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
481 color1.green() + greenDiff * s / 8,
482 color1.blue() + blueDiff * s / 8 );
487 p.convertFromImage( image );
493 int yPos =
contentsRect().top() + painter->fontMetrics().ascent() + 2;
495 painter->fontMetrics().width( text2 )) / 2;
497 painter->setPen( pen );
498 painter->drawText( xPos, yPos, text2 );
500 yPos =
contentsRect().bottom() - painter->fontMetrics().descent() - 2;
502 painter->fontMetrics().width( text1 )) / 2;
503 pen.setColor( color1 );
504 painter->setPen( pen );
505 painter->drawText( xPos, yPos, text1 );
509 int yPos =
contentsRect().bottom()-painter->fontMetrics().descent()-2;
512 painter->setPen( pen );
513 painter->drawText(
contentsRect().left() + 2, yPos, text1 );
515 pen.setColor( color1 );
516 painter->setPen( pen );
518 painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
524 void KXYSelector::virtual_hook(
int,
void* )
527 void TDESelector::virtual_hook(
int,
void* )
530 void KGradientSelector::virtual_hook(
int id,
void* data )
531 { TDESelector::virtual_hook(
id, data ); }
533 #include "tdeselect.moc"