Results 1 to 9 of 9

Thread: Converting MFC CDC::Arc(..) to QPainter->drawArc

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Converting MFC CDC::Arc(..) to QPainter->drawArc

    Hi guys,

    I have to convert MFC code to Qt.
    I have a problem with creating arcs.

    I have the MFC code:
    Qt Code:
    1. pDC->Arc(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y, dxStart, dyStart, dxEnd, dyEnd);
    To copy to clipboard, switch view to plain text mode 
    Here are docs for MFC arc:
    http://msdn2.microsoft.com/en-us/lib...k5(VS.80).aspx
    I need to paint the arc using this Qt method:
    Qt Code:
    1. void QPainter::drawChord ( const QRectF & rectangle, int startAngle, int spanAngle )
    To copy to clipboard, switch view to plain text mode 

    But I have a problem with startAngle/span Angle. I have the coordinates(dxStart.....DyEnd), but don't know howto interpret them to create a startAngle in the Qt method.

    Any ideas? Thanks

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Seems that this is a simple trygonometric issue. In MFC you pass the end point and in Qt you pass the end angle. The point lies on the line that crosses the horizontal "diameter" with the angle specified. Thus knowing the horizontal and vertical distance of the point from the horizontal "diameter", you can use arcus tangent to calculate the angle.

    tg(alpha) = y/x => alpha = arctg(y/x)

    I hope I didn't mix tangent and cotangent, but this is your business to check that

  3. The following user says thank you to wysota for this useful post:

    maverick_pol (24th September 2007)

  4. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Thanks,

    Ok so I can get the StartAngle using trygonometric function.
    But which angle is the SPANangle?
    Thank you for you help.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Span is the difference between end angle (which you can calculate in a similar manner) and start angle. Just remember that tangent and cotangent operate on (-pi/2; pi/2) range, thus you might have to calculate the final angle by watching the signs of arguments, like taught in school

  6. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Hi,

    I have tried using the hints you have given me and the situation is not so bright. Yes you are right, that some simple math methods can be used, but it does not solve my problem. Here is the link that show how to use MFC method CDC::arc(...)
    http://www.ucancode.net/faq/CDC_Arc_Pie_Chord.htm

    What interest me is how can I know, having start/end points and the rect, what is the inclination(slope) of the line. It is possible to an infinite number of arcs having the bounding rect and start/end point, am I right?

    I am stuck and do know know what to do now.

    Before hand thank you.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    The slope is determined by the tangent of the end point. There is only one arc (defined as a portion of an ellipse) with given bounding rect and end points. I wanted to make a drawing, but I seem to lack an idiot proof enough tool to do it here (anyone knows how to draw a straight line in Karbon?).

  8. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Hi,

    I tried converting this from MFC to Qt:

    pDC->Arc(20, 20, 226, 144, 202, 115, 105, 32);

    but can't get a good result.

    If you have time, please help with this one.

    Thank you.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Here you go. I must have made some mistake as the arc is a bit wrong, but it's probably a matter of adjusting something. If you look at the result, you'll see that the coordinates of end points (red and green dots) are not exactly on the arc. I can't explain that - either MFC arc drawing works differently (maybe its not an arc but a curve?) or coordinates are extrapolated to match the bounding rect.
    Attached Images Attached Images
    Attached Files Attached Files

  10. The following user says thank you to wysota for this useful post:

    maverick_pol (26th September 2007)

  11. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting MFC CDC::Arc(..) to QPainter->drawArc

    Hi,

    Thanks for the code I will try to test it in my app. As I remember, the msdn docs point that the start/end points do no have to lay exactly on the arc.

    The arc looks fine.

    Thanks
    Last edited by maverick_pol; 26th September 2007 at 12:16.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.