25 #include <QMouseEvent> 28 #include <QDragEnterEvent> 62 : w(widget), hue(0), sat(0), val(0),
63 wheel_width(20), mouse_status(
Nothing),
71 return qMin(w->geometry().width(), w->geometry().height())/2;
101 return QLineF (w->geometry().width()/2, w->geometry().height()/2, p.x(), p.y());
107 QSize
size(width, width);
108 inner_selector = QImage(size, QImage::Format_RGB32);
110 for (
int y = 0;
y < width; ++
y )
112 for (
int x = 0;
x < width; ++
x )
114 inner_selector.setPixel(
x,
y,
115 color_from(hue,
double(
x)/width,
double(
y)/width,1).rgb());
128 size *= max_size / size.height();
130 qreal ycenter = size.height()/2;
131 inner_selector = QImage(size.toSize(), QImage::Format_RGB32);
133 for (
int x = 0;
x < inner_selector.width();
x++ )
135 qreal pval =
x / size.height();
136 qreal slice_h = size.height() * pval;
137 for (
int y = 0;
y < inner_selector.height();
y++ )
139 qreal ymin = ycenter-slice_h/2;
140 qreal psat = qBound(0.0,(
y-ymin)/slice_h,1.0);
142 inner_selector.setPixel(
x,
y,
color_from(hue,psat,pval,1).rgb());
197 hue_ring.fill(Qt::transparent);
198 QPainter painter(&hue_ring);
199 painter.setRenderHint(QPainter::Antialiasing);
200 painter.setCompositionMode(QPainter::CompositionMode_Source);
203 const int hue_stops = 24;
204 QConicalGradient gradient_hue(0, 0, 0);
205 if ( gradient_hue.stops().size() < hue_stops )
207 for (
double a = 0;
a < 1.0;
a+=1.0/(hue_stops-1) )
216 painter.setPen(Qt::NoPen);
217 painter.setBrush(QBrush(gradient_hue));
220 painter.setBrush(Qt::transparent);
228 hue = qMax(0.0, c.hsvHueF());
229 sat = c.hsvSaturationF();
234 hue = qMax(0.0, c.hueF());
240 hue = qMax(0.0, c.hsvHueF());
248 QWidget(parent),
p(new
Private(this))
251 setAcceptDrops(
true);
272 return color().hueF();
278 return color().hsvSaturationF();
283 return color().valueF();
300 QPainter painter(
this);
301 painter.setRenderHint(QPainter::Antialiasing);
302 painter.translate(geometry().width()/2,geometry().height()/2);
311 painter.setPen(QPen(Qt::black,3));
312 painter.setBrush(Qt::NoBrush);
314 ray.setAngle(
p->
hue*360);
315 QPointF h1 = ray.p2();
317 QPointF h2 = ray.p2();
318 painter.drawLine(h1,h2);
327 QPointF selector_position;
331 selector_position = QPointF(
p->
sat*side,
p->
val*side);
337 qreal slice_h = side *
p->
val;
338 qreal ymin = side/2-slice_h/2;
340 selector_position = QPointF(
p->
val*height, ymin +
p->
sat*slice_h);
342 triangle.append(QPointF(0,side/2));
343 triangle.append(QPointF(height,0));
344 triangle.append(QPointF(height,side));
346 clip.addPolygon(triangle);
347 painter.setClipPath(clip);
351 painter.setClipping(
false);
354 painter.setPen(QPen(
p->
val > 0.5 ? Qt::black : Qt::white, 3));
355 painter.setBrush(Qt::NoBrush);
356 painter.drawEllipse(selector_position, selector_radius, selector_radius);
374 QLineF center_mouse_ln ( QPointF(0,0),
375 glob_mouse_ln.p2() - glob_mouse_ln.p1() );
387 QPointF pt = center_mouse_ln.p2();
391 qreal slice_h = side *
p->
val;
393 qreal ycenter = side/2;
394 qreal ymin = ycenter-slice_h/2;
397 p->
sat = qBound(0.0, (pt.y()-ymin)/slice_h, 1.0);
408 if ( ev->buttons() & Qt::LeftButton )
438 if (!qFuzzyCompare(oldh+1,
p->
hue+1))
446 p->
hue = qBound(0.0, h, 1.0);
453 p->
sat = qBound(0.0, s, 1.0);
459 p->
val = qBound(0.0, v, 1.0);
475 QColor old_col =
color();
478 p->
hue = old_col.hueF();
486 p->
hue = old_col.hueF();
494 p->
hue = old_col.hsvHueF();
495 p->
sat = old_col.hsvSaturationF();
496 p->
val = old_col.valueF();
522 default_flags = flags;
527 return default_flags & mask;
537 if ( event->mimeData()->hasColor() ||
538 (
event->mimeData()->hasText() && QColor(event->mimeData()->text()).isValid() ) )
539 event->acceptProposedAction();
544 if ( event->mimeData()->hasColor() )
546 setColor(event->mimeData()->colorData().value<QColor>());
549 else if ( event->mimeData()->hasText() )
551 QColor col(event->mimeData()->text());
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
TFSIMD_FORCE_INLINE const tfScalar & x() const