3 * Copyright (C) 2011 Roman Moravcik
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "satellitesignalstrength.h"
24 void SatelliteSignalStrength::updateWidget(const QList<QGeoSatelliteInfo> &satellites, bool inUseList)
27 m_satellitesInUse = satellites;
29 m_satellitesInView = satellites;
34 void SatelliteSignalStrength::showTitle(bool show)
39 void SatelliteSignalStrength::paintEvent(QPaintEvent * /* event */)
41 QPainter painter(this);
42 painter.setRenderHint(QPainter::Antialiasing);
46 int title_x = rect().x() + m_margin;
47 int title_y = rect().y() + m_margin;
48 int title_width = rect().width() - (2 * m_margin);
49 title_height = painter.fontMetrics().height();
50 QRectF titleArea(title_x, title_y, title_width, title_height);
53 paintTitle(painter, titleArea);
56 /* Signal strength graph */
57 int graph_x = rect().x();
58 int graph_y = rect().y() + title_height + m_spacing;
59 int graph_width = rect().width();
60 int graph_height = rect().height() - title_height - m_spacing;
61 QRectF graphArea(graph_x, graph_y, graph_width, graph_height);
63 /* Signal strength bar graphs */
64 for (int index = 1; index <= m_numOfSatellites; ++index) {
65 paintBarGraph(painter, graphArea, index);
69 void SatelliteSignalStrength::paintTitle(QPainter &painter, const QRectF &area)
71 painter.setPen(QApplication::palette().color(QPalette::Text));
72 painter.drawText(area, Qt::AlignLeft, tr("Signal strength:"));
75 void SatelliteSignalStrength::paintBarGraph(QPainter &painter, const QRectF &area, int index)
77 /* Bar graph backround */
78 double barGraphBackground_x;
79 double barGraphBackground_y;
80 double barGraphBackground_width = (double) (area.width() - (2.0 * m_margin) -
81 (m_spacing * (m_numOfSatellitesInRow - 1))) / (double) m_numOfSatellitesInRow;
82 double barGraphBackground_height = (double) (area.height() - (2.0 * m_margin) -
83 (2.0 * m_spacing)) / (double) m_numOfRows;
85 if (index <= m_numOfSatellitesInRow) {
86 barGraphBackground_x = area.x() + m_margin +
87 ((index - 1) * (barGraphBackground_width + m_spacing));
88 barGraphBackground_y = area.y() + m_margin;
90 barGraphBackground_x = area.x() + m_margin +
91 (((index - 1) - m_numOfSatellitesInRow) * (barGraphBackground_width + m_spacing));
92 barGraphBackground_y = area.y() + m_margin + (2.0 * m_spacing) + barGraphBackground_height;
94 QRectF barGraphBackgroundArea(barGraphBackground_x, barGraphBackground_y,
95 barGraphBackground_width, barGraphBackground_height);
97 painter.setPen(m_barGraphBorderColor);
98 painter.setBrush(m_barGraphBackgroundColor);
99 painter.drawRect(barGraphBackgroundArea);
102 int signalStrength = 0;
104 for (int iter = 0; iter < m_satellitesInView.count(); iter++) {
105 if (m_satellitesInView.at(iter).prnNumber() == index) {
106 signalStrength = m_satellitesInView.at(iter).signalStrength();
110 for (int iter = 0; iter < m_satellitesInUse.count(); iter++) {
111 if (m_satellitesInUse.at(iter).prnNumber() == index) {
112 signalStrength = m_satellitesInUse.at(iter).signalStrength();
118 if (signalStrength > 0) {
120 painter.setPen(m_barGraphInUseColor);
121 painter.setBrush(m_barGraphInUseColor);
123 painter.setPen(m_barGraphInViewColor);
124 painter.setBrush(m_barGraphInViewColor);
127 double level_width = barGraphBackground_width - 2.0;
128 double level_height = (double) signalStrength * (barGraphBackground_height - 2.0) / 100.0;
129 double level_x = barGraphBackground_x + 1.0;
130 double level_y = barGraphBackground_y + barGraphBackground_height - level_height - 1.0;
132 QRectF barGraphLevelArea(level_x, level_y, level_width, level_height);
133 painter.drawRect(barGraphLevelArea);
136 /* Satellite's PRN must be painter over the level bar */
137 QFont font = QApplication::font();
138 font.setPixelSize(12);
139 painter.setFont(font);
140 painter.setPen(QApplication::palette().color(QPalette::Text));
141 painter.drawText(barGraphBackgroundArea, Qt::AlignCenter, QString::number(index));
144 SatelliteSignalStrength::SatelliteSignalStrength(QWidget *parent) : QWidget(parent)
146 m_barGraphBorderColor = QColor(0, 0, 0);
147 m_barGraphBackgroundColor = QColor(74, 69, 66);
148 m_barGraphInViewColor = QColor(153, 153, 153);
149 m_barGraphInUseColor = QColor(51, 191, 51);