36 : QGraphicsView(parent)
50 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
51 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
53 QSvgRenderer *renderer =
new QSvgRenderer();
54 renderer->load(QString(
":/gpsgadget/images/gpsSky.svg"));
56 world =
new QGraphicsSvgItem();
57 world->setSharedRenderer(renderer);
58 world->setElementId(
"map");
60 scene =
new QGraphicsScene(
this);
61 scene->addItem(world);
62 scene->setSceneRect(world->boundingRect());
66 for (
int i = 0;
i < MAX_SATELLITES;
i++) {
72 satIcons[
i] =
new QGraphicsSvgItem(world);
73 satIcons[
i]->setSharedRenderer(renderer);
74 satIcons[
i]->setElementId(
"gpssatellite");
77 satTexts[
i] =
new QGraphicsSimpleTextItem(
"##", satIcons[
i]);
78 satTexts[
i]->setBrush(QColor(
"Black"));
79 satTexts[
i]->setFont(QFont(
"Courier", -1, QFont::Bold));
98 fitInView(world, Qt::KeepAspectRatio);
108 fitInView(world, Qt::KeepAspectRatio);
113 if (index >= MAX_SATELLITES) {
119 satellites[index][0] = prn;
120 satellites[index][1] = elevation;
121 satellites[index][2] = azimuth;
122 satellites[index][3] = snr;
124 if (prn && elevation >= 0) {
127 satIcons[index]->setElementId(
"gpssatellite");
128 }
else if ((prn >= 120) && (prn <= 158)) {
129 satIcons[index]->setElementId(
"sbassatellite");
131 satIcons[index]->setElementId(
"othersat");
134 QPointF opd = polarToCoord(elevation, azimuth);
135 opd += QPointF(-satIcons[index]->boundingRect().center().
x(),
136 -satIcons[index]->boundingRect().center().
y());
137 satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(), opd.y()),
false);
140 satIcons[index]->setOpacity(1.0);
141 satIcons[index]->setZValue(1.0);
143 satIcons[index]->setOpacity(0.53);
144 satIcons[index]->setZValue(0);
146 satIcons[index]->show();
148 QRectF iconRect = satIcons[index]->boundingRect();
149 QString prnString = QString().number(prn);
150 if (prnString.length() == 1) {
151 prnString =
"0" + prnString;
153 satTexts[index]->setText(prnString);
154 QRectF textRect = satTexts[index]->boundingRect();
157 qreal scale = 0.65 * (iconRect.width() / textRect.width());
158 matrix.translate(iconRect.width() / 2, iconRect.height() / 2);
159 matrix.scale(scale, scale);
160 matrix.translate(-textRect.width() / 2, -textRect.height() / 2);
161 satTexts[index]->setTransform(matrix,
false);
163 satIcons[index]->hide();
171 QPointF GpsConstellationWidget::polarToCoord(
int elevation,
int azimuth)
175 double rad_elevation;
178 rad_elevation = M_PI * elevation / 180;
179 rad_azimuth = M_PI * azimuth / 180;
181 x = cos(rad_elevation) * sin(rad_azimuth);
182 y = -cos(rad_elevation) * cos(rad_azimuth);
184 x = world->boundingRect().width() / 2 *
x;
185 y = world->boundingRect().height() / 2 *
y;
187 x = (world->boundingRect().width() / 2) + x;
188 y = (world->boundingRect().height() / 2) + y;
190 return QPointF(x, y);
~GpsConstellationWidget()
void showEvent(QShowEvent *event)
void updateSat(int index, int prn, int elevation, int azimuth, int snr)
GpsConstellationWidget(QWidget *parent=nullptr)
void resizeEvent(QResizeEvent *event)