Engauge Digitizer 2
Loading...
Searching...
No Matches
GraphicsArcItemRelay.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2020 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "GraphicsArcItem.h"
9#include <QDebug>
10#include <QGraphicsScene>
11#include <qmath.h>
12#include <QObject>
13#include <QPainter>
14#include "QtToString.h"
15
16const int TICS_PER_CYCLE = 360 * 16;
17const double RADIANS_TO_TICS = TICS_PER_CYCLE / (2.0 * M_PI);
18
20 GraphicsArcItem *graphicsItem) :
21 m_graphicsItem (graphicsItem)
22{
23 // Queue for later by including Qt::QueuedConnection
24 connect (caller, SIGNAL (signalUpdateAngles (QPointF, QPointF, QPointF, double, double)),
25 this, SLOT (slotUpdateAngles (QPointF, QPointF, QPointF, double, double)),
26 Qt::QueuedConnection);
27}
28
30{
31 // Calling code is responsible for deallocating graphics item
32}
33
34void GraphicsArcItemRelay::slotUpdateAngles (QPointF posTangentialLow,
35 QPointF posTangentialCenter,
36 QPointF posTangentialHigh,
37 double widthToHeight,
38 double scaling)
39{
40 // Rotate into ellipse reference frame (where x and y axis are aligned with
41 // semimajor/semiminor axes. The QTransform supplied by m_graphicsItem is
42 // just the identity transform and therefore not useful
43 double angleRotation = -1.0 * m_graphicsItem->rotation();
44 QTransform rotateTransform;
45 rotateTransform.rotate (angleRotation);
46 QPointF posLowInEllipseFrame = rotateTransform.map (posTangentialLow);
47 QPointF posCenterInEllipseFrame = rotateTransform.map (posTangentialCenter);
48 QPointF posHighInEllipseFrame = rotateTransform.map (posTangentialHigh);
49
50 // Compensate for y scale being different than x scale using widthToHeight
51 double angleLow = -1.0 * qAtan2 (posLowInEllipseFrame.y() * widthToHeight,
52 posLowInEllipseFrame.x());
53 double angleCenter = -1.0 * qAtan2 (posCenterInEllipseFrame.y() * widthToHeight,
54 posCenterInEllipseFrame.x());
55 double angleHigh = -1.0 * qAtan2 (posHighInEllipseFrame.y() * widthToHeight,
56 posHighInEllipseFrame.x());
57
58 int lowTics = (int) (RADIANS_TO_TICS * (angleCenter + scaling * (angleLow - angleCenter)));
59 int highTics = (int) (RADIANS_TO_TICS * (angleCenter + scaling * (angleHigh - angleCenter)));
60
61 m_graphicsItem->setStartAngle (lowTics);
62 m_graphicsItem->setSpanAngle (highTics - lowTics);
63}
const double RADIANS_TO_TICS
const int TICS_PER_CYCLE
GraphicsArcItemRelay(QObject *caller, GraphicsArcItem *graphicsItem)
Single constructor with associated GraphicsArcItem.
void slotUpdateAngles(QPointF posTangentialLow, QPointF posTangentialCenter, QPointF posTangentialHigh, double widthToHeight, double scaling)
Slot inputs to QGraphicsEllipseItem::setStartAngle and QGraphicsEllipseItem::setSpanAngle.
Draw an arc as an ellipse but without lines from the center to the start and end points.