30 #include <QStringList>
33 #include <QVBoxLayout>
34 #include <QPushButton>
35 #include <QMouseEvent>
42 : QGraphicsView(parent)
44 setMinimumSize(64, 64);
45 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
46 setScene(
new QGraphicsScene(
this));
47 setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
49 m_renderer =
new QSvgRenderer();
50 bool retval = m_renderer->load(QString(
":/magicwaypoint/images/positionfield.svg"));
55 m_background =
new QGraphicsSvgItem();
56 m_background->setSharedRenderer(m_renderer);
57 m_background->setElementId(QString(
"background"));
59 m_positiondesired =
new QGraphicsSvgItem();
60 m_positiondesired->setSharedRenderer(m_renderer);
61 m_positiondesired->setElementId(QString(
"desiredPosition"));
62 m_positiondesired->setPos(0, 0);
64 m_positionactual =
new QGraphicsSvgItem();
65 m_positionactual->setSharedRenderer(m_renderer);
66 m_positionactual->setElementId(QString(
"actualPosition"));
67 m_positionactual->setPos(0, 0);
69 QGraphicsScene *l_scene = scene();
71 l_scene->addItem(m_background);
72 l_scene->addItem(m_positiondesired);
73 l_scene->addItem(m_positionactual);
74 l_scene->setSceneRect(m_background->boundingRect());
86 QRectF sceneSize = scene()->sceneRect();
88 m_positiondesired->setPos(
89 (east + 1) / 2 * sceneSize.width() - m_positiondesired->boundingRect().width() / 2,
90 (-north + 1) / 2 * sceneSize.height() - m_positiondesired->boundingRect().height() / 2);
95 QRectF sceneSize = scene()->sceneRect();
97 m_positionactual->setPos(
98 (east + 1) / 2 * sceneSize.width() - m_positionactual->boundingRect().width() / 2,
99 (-north + 1) / 2 * sceneSize.height() - m_positionactual->boundingRect().height() / 2);
107 QPointF point = mapToScene(event->pos());
108 QRectF sceneSize = scene()->sceneRect();
110 double north = -(point.y() / sceneSize.height() - .5) * 2;
111 double east = (point.x() / sceneSize.width() - .5) * 2;
120 if (event->button() == Qt::LeftButton) {
133 if (!m_renderer->isValid()) {
134 qDebug() <<
"Image file not loaded, not rendering";
137 QGraphicsView::paintEvent(event);
143 fitInView(m_background, Qt::IgnoreAspectRatio);
void mousePressEvent(QMouseEvent *event)
Redirect mouse move clicks to control position.
void updateDesiredIndicator(double north, double east)
Update aircraft position on image (values go from -1 to 1)
void updateActualIndicator(double north, double east)
void paintEvent(QPaintEvent *event)
void mouseMoveEvent(QMouseEvent *event)
Redirect mouse move events to control position.
void resizeEvent(QResizeEvent *event)
PositionField(QWidget *parent=nullptr)
Constructor for JoystickControl widget. Sets up the image of a joystick.
void positionClicked(double north, double east)