26#include "ko_color_wheel.h"
30KoColorWheel::KoColorWheel( TQWidget *parent,
const char *name ):
KXYSelector( parent,
name )
35void KoColorWheel::resizeEvent( TQResizeEvent * )
38 setRange( 0, 0, contentsRect().width(), contentsRect().height() );
41void KoColorWheel::drawContents( TQPainter *painter )
43 painter->drawPixmap( contentsRect().x(), contentsRect().y(), m_pixmap );
46void KoColorWheel::drawWheel( TQPixmap *pixmap )
48 int size = TQMIN(contentsRect().width(), contentsRect().height());
49 TQPoint center(size/2, size/2);
51 TQImage image( size, size, 32 );
52 image.fill(colorGroup ().background().pixel());
58 for ( a = size-1; a >= 0; a-- )
60 p = (uint*) image.scanLine( size - a - 1 );
61 for( b = 0; b < size; b++ )
63 s = (int)(sqrt(pow(a-center.y(), 2) + pow(b-center.x(), 2))/(size/2)*255);
66 h = (int)(atan2( b-center.x(), a-center.y())* 180.0 / pi);
70 col.setHsv( h, s, 210 );
76 pixmap->convertFromImage( image );
79void KoColorWheel::mousePressEvent( TQMouseEvent *e )
81 int size = TQMIN(contentsRect().width(), contentsRect().height());
82 TQPoint center(size/2, size/2);
85 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
86 setValues( xVal, yVal );
90 s = (int)(sqrt(pow(yVal-center.y(), 2) + pow(xVal-center.x(), 2))/(size/2)*255);
93 h = (int)(atan2( xVal-center.x(), yVal-center.y())* 180.0 / pi);
97 m_color.setHSV( h, s, 255);
98 emit valueChanged(m_color);
101void KoColorWheel::mouseMoveEvent( TQMouseEvent *e )
103 mousePressEvent( e );
106void KoColorWheel::slotSetValue(
const KoColor& c)
108 int size = TQMIN(contentsRect().width(), contentsRect().height());
109 TQPoint center(size/2, size/2);
112 xVal = (int)(sin(c.H() * pi /180) * c.S() / 255 * (size/2) + center.x());
113 yVal = (int)(cos(c.H() * pi /180) * c.S() / 255 * (size/2) + center.y());
114 setValues( xVal, yVal );
117#include "ko_color_wheel.moc"
const char * name(StdAction id)