Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Graphics
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
"
8
#include "
GraphicsArcItemRelay.h
"
9
#include <QDebug>
10
#include <QGraphicsScene>
11
#include <qmath.h>
12
#include <QObject>
13
#include <QPainter>
14
#include "
QtToString.h
"
15
16
const
int
TICS_PER_CYCLE
= 360 * 16;
17
const
double
RADIANS_TO_TICS
=
TICS_PER_CYCLE
/ (2.0 * M_PI);
18
19
GraphicsArcItemRelay::GraphicsArcItemRelay
(QObject *caller,
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
29
GraphicsArcItemRelay::~GraphicsArcItemRelay
()
30
{
31
// Calling code is responsible for deallocating graphics item
32
}
33
34
void
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
}
RADIANS_TO_TICS
const double RADIANS_TO_TICS
Definition
DlgSettingsGuideline.cpp:50
TICS_PER_CYCLE
const int TICS_PER_CYCLE
Definition
GraphicsArcItemRelay.cpp:16
GraphicsArcItemRelay.h
GraphicsArcItem.h
QtToString.h
GraphicsArcItemRelay::GraphicsArcItemRelay
GraphicsArcItemRelay(QObject *caller, GraphicsArcItem *graphicsItem)
Single constructor with associated GraphicsArcItem.
Definition
GraphicsArcItemRelay.cpp:19
GraphicsArcItemRelay::slotUpdateAngles
void slotUpdateAngles(QPointF posTangentialLow, QPointF posTangentialCenter, QPointF posTangentialHigh, double widthToHeight, double scaling)
Slot inputs to QGraphicsEllipseItem::setStartAngle and QGraphicsEllipseItem::setSpanAngle.
Definition
GraphicsArcItemRelay.cpp:34
GraphicsArcItemRelay::~GraphicsArcItemRelay
virtual ~GraphicsArcItemRelay()
Definition
GraphicsArcItemRelay.cpp:29
GraphicsArcItem
Draw an arc as an ellipse but without lines from the center to the start and end points.
Definition
GraphicsArcItem.h:20
Generated on
for Engauge Digitizer by
1.17.0