Пример #1
0
void Color_Wheel::mousePressEvent(QMouseEvent *ev)
{
    if ( ev->buttons() & Qt::LeftButton )
    {
        QLineF ray = line_to_point(ev->pos());
        if ( ray.length() <= inner_radius() )
            mouse_status = Drag_Square;
        else if ( ray.length() <= outer_radius() )
            mouse_status = Drag_Circle;
    }
}
Пример #2
0
void Color_Wheel::mouseMoveEvent(QMouseEvent *ev)
{
    if ( mouse_status == Drag_Circle )
    {
        huem = line_to_point(ev->pos()).angle()/360.0;
        render_rectangle();

        emit colorSelected(color());
        emit colorChanged(color());
        update();
    }
    else if ( mouse_status == Drag_Square )
    {
        QLineF glob_mouse_ln = line_to_point(ev->pos());
        QLineF center_mouse_ln ( QPointF(0,0),
                                 glob_mouse_ln.p2() - glob_mouse_ln.p1() );
        center_mouse_ln.setAngle(center_mouse_ln.angle()-huem*360-45);

        sat = center_mouse_ln.x2()/square_size()+0.5;

        val = center_mouse_ln.y2()/square_size()+0.5;

        if ( sat > 1 )
            sat = 1;
        else if ( sat < 0 )
            sat = 0;

        if ( val > 1 )
            val = 1;
        else if ( val < 0 )
            val = 0;

        emit colorSelected(color());
        emit colorChanged(color());
        update();
    }
}
Пример #3
0
/* Compute a circular arc fillet between lines L1 (p1 to p2)
   and L2 (p3 to p4) with radius r.
   The circle center is c.
   The start angle is pa
   The end angle is aa,
   The points p1-p4 will be modified as necessary */
gboolean
fillet(Point *p1, Point *p2, Point *p3, Point *p4,
       real r, Point *c, real *pa, real *aa)
{
  real a1, b1, c1;  /* Coefficients for L1 */
  real a2, b2, c2;  /* Coefficients for L2 */
  real d, d1, d2;
  real c1p, c2p;
  real rr;
  real start_angle, stop_angle;
  Point mp,gv1,gv2;
  gboolean righthand = FALSE;

  line_coef(&a1,&b1,&c1,p1,p2);
  line_coef(&a2,&b2,&c2,p3,p4);

  if ( (a1*b2) == (a2*b1) ) /* Parallel or coincident lines */
    return FALSE;

  mp.x = (p3->x + p4->x) / 2.0;          /* Find midpoint of p3 p4 */
  mp.y = (p3->y + p4->y) / 2.0;
  d1 = line_to_point(a1, b1, c1, &mp);    /* Find distance p1 p2 to
                                             midpoint p3 p4 */
  if ( d1 == 0.0 ) return FALSE;          /* p1p2 to p3 */

  mp.x = (p1->x + p2->x) / 2.0;          /* Find midpoint of p1 p2 */
  mp.y = (p1->y + p2->y) / 2.0;
  d2 = line_to_point(a2, b2, c2, &mp);    /* Find distance p3 p4 to
                                             midpoint p1 p2 */
  if ( d2 == 0.0 ) return FALSE;

  rr = r;
  if ( d1 <= 0.0 ) rr = -rr;

  c1p = c1-rr*sqrt((a1*a1)+(b1*b1));     /* Line parallell l1 at d */
  rr = r;

  if ( d2 <= 0.0 ) rr = -rr;
  c2p = c2-rr*sqrt((a2*a2)+(b2*b2));     /* Line parallell l2 at d */
  d = a1*b2-a2*b1;

  c->x = ( c2p*b1-c1p*b2 ) / d;          /* Intersect constructed lines */
  c->y = ( c1p*a2-c2p*a1 ) / d;          /* to find center of arc */

  point_perp(c,a1,b1,c1,p2);             /* Clip or extend lines as required */
  point_perp(c,a2,b2,c2,p3);

  /* need to negate the y coords to calculate angles correctly */
  gv1.x = p2->x-c->x; gv1.y = -(p2->y-c->y);
  gv2.x = p3->x-c->x; gv2.y = -(p3->y-c->y);

  start_angle = atan2(gv1.y,gv1.x);   /* Beginning angle for arc */
  stop_angle = dot2(&gv1,&gv2);
  if ( point_cross(&gv1,&gv2) < 0.0 ) {
    stop_angle = -stop_angle; /* Angle subtended by arc */
    /* also this means we need to swap our angles later on */
    righthand = TRUE;
  }
  /* now calculate the actual angles in a form that the draw arc function
     of the renderer can use */
  start_angle = start_angle*180.0/G_PI;
  stop_angle  = start_angle + stop_angle*180.0/G_PI;
  while (start_angle < 0.0) start_angle += 360.0;
  while (stop_angle < 0.0)  stop_angle += 360.0;
  /* swap the start and stop if we had to negate the cross product */
  if ( righthand ) {
    real tmp = start_angle;
    start_angle = stop_angle;
    stop_angle = tmp;
  }
  *pa = start_angle;
  *aa = stop_angle;
  return TRUE;
}