diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.pro b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.pro index 5d03fd233..cd3d2f230 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.pro +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.pro @@ -18,6 +18,7 @@ HEADERS += pipxtremegadget.h \ pipxtremegadgetoptionspage.h \ pipxtremegadgetwidget.h \ pipxtremeplugin.h \ + widgetbar.h SOURCES += pipxtremegadget.cpp \ pipxtremegadgetconfiguration.cpp \ @@ -25,6 +26,7 @@ SOURCES += pipxtremegadget.cpp \ pipxtremegadgetoptionspage.cpp \ pipxtremegadgetwidget.cpp \ pipxtremeplugin.cpp \ + widgetbar.cpp OTHER_FILES += pipxtreme.pluginspec diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui index 4c24a7581..d5547494d 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtreme.ui @@ -439,36 +439,27 @@ - - - - 75 - true - + + + + 0 + 0 + - - Received Signal Strength Indicator + + + 1 + 1 + - - -120 + + false - - 0 + + false - - -60 - - - Qt::AlignCenter - - - true - - - QProgressBar::TopToBottom - - - %v + + background-color: rgb(112, 112, 112); @@ -841,7 +832,7 @@ - The AES encryption key - has to be the same key on the remote modem as well) + The AES encryption key - has to be the same key on the remote modem. @@ -1023,6 +1014,13 @@ + + + WidgetBar + QWidget +
widgetbar.h
+
+
diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp index f25952e63..bd9c0175b 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.cpp @@ -132,11 +132,11 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : m_widget = new Ui_PipXtremeWidget(); m_widget->setupUi(this); -#if QT_VERSION >= 0x040700 - qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch()); -#else - qsrand(QDateTime::currentDateTime().toTime_t()); -#endif + #if QT_VERSION >= 0x040700 + qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch()); + #else + qsrand(QDateTime::currentDateTime().toTime_t()); + #endif device_input_buffer.size = 8192; device_input_buffer.used = 0; @@ -206,9 +206,9 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625); - m_widget->progressBar_RSSI->setMinimum(-120); - m_widget->progressBar_RSSI->setMaximum(0); - m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum()); + m_widget->widgetRSSI->setMinimum(-120); + m_widget->widgetRSSI->setMaximum(0); + m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->minimum()); m_widget->label_RSSI->setText("RSSI"); @@ -477,8 +477,11 @@ void PipXtremeGadgetWidget::enableTelemetry() void PipXtremeGadgetWidget::randomiseAESKey() { -// uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toMSecsSinceEpoch(); // only available with Qt 4.7.1 and later - uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toTime_t(); + #if QT_VERSION >= 0x040700 + uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toMSecsSinceEpoch(); // only available with Qt 4.7.1 and later + #else + uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toTime_t(); + #endif QString key = ""; for (int i = 0; i < 4; i++) @@ -977,13 +980,13 @@ void PipXtremeGadgetWidget::processRxPacket(quint8 *packet, int packet_size) m_widget->lineEdit_LinkState->setText("Unknown [" + QString::number(pipx_config_state.link_state) + "]"); break; } - if (pipx_config_state.rssi < m_widget->progressBar_RSSI->minimum()) - m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum()); + if (pipx_config_state.rssi < m_widget->widgetRSSI->minimum()) + m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->minimum()); else - if (pipx_config_state.rssi > m_widget->progressBar_RSSI->maximum()) - m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->maximum()); + if (pipx_config_state.rssi > m_widget->widgetRSSI->maximum()) + m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->maximum()); else - m_widget->progressBar_RSSI->setValue(pipx_config_state.rssi); + m_widget->widgetRSSI->setValue(pipx_config_state.rssi); m_widget->label_RSSI->setText("RSSI " + QString::number(pipx_config_state.rssi) + "dBm"); m_widget->lineEdit_RxAFC->setText(QString::number(pipx_config_state.afc) + "Hz"); m_widget->lineEdit_Retries->setText(QString::number(pipx_config_state.retries)); @@ -1135,7 +1138,7 @@ void PipXtremeGadgetWidget::disconnectPort(bool enable_telemetry, bool lock_stuf m_widget->lineEdit_MaxFrequency->setText(""); m_widget->lineEdit_FrequencyStepSize->setText(""); m_widget->lineEdit_LinkState->setText(""); - m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum()); + m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->minimum()); m_widget->label_RSSI->setText("RSSI"); m_widget->lineEdit_RxAFC->setText(""); m_widget->lineEdit_Retries->setText(""); diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h index 6af22d9fa..25b0e7ccb 100644 --- a/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/pipxtreme/pipxtremegadgetwidget.h @@ -52,6 +52,7 @@ #include #include #include +#include "widgetbar.h" // ************************* // pipx config comms packets @@ -138,7 +139,6 @@ public: public slots: void onTelemetryStart(); void onTelemetryStop(); - void onTelemetryConnect(); void onTelemetryDisconnect(); diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.cpp b/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.cpp new file mode 100644 index 000000000..cebb68c01 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.cpp @@ -0,0 +1,157 @@ +/** + ****************************************************************************** + * + * @file widgetbar.cpp + * @author Cathy Moss Copyright (C) 2011. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup ConfigPlugin Configuration Plugin + * @{ + * @brief A bar display widget + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + #include + + #include "widgetbar.h" + + WidgetBar::WidgetBar(QWidget *parent) + : QWidget(parent) + { + m_maximum = 0; + m_minimum = -120; + m_value = -60; + +// m_orientation = Qt::Vertical; + m_orientation = Qt::Horizontal; + + setBackgroundRole(QPalette::Base); + setAutoFillBackground(true); + } + + QSize WidgetBar::minimumSizeHint() const + { + return QSize(8, 8); + } + +// QSize WidgetBar::sizeHint() const +// { +// return QSize(200, 400); +// } + + void WidgetBar::setMaximum(int value) + { + m_maximum = value; + update(); + } + + void WidgetBar::setMinimum(int value) + { + m_minimum = value; + update(); + } + + void WidgetBar::setValue(int value) + { + if (value < m_minimum) value = m_minimum; + else + if (value > m_maximum) value = m_maximum; + + m_value = value; + update(); + } + +void WidgetBar::setOrientation(Qt::Orientation orientation) +{ + m_orientation = orientation; + update(); +} + +void WidgetBar::paintEvent(QPaintEvent * /* event */) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, false); + + int range = abs(m_maximum - m_minimum); + if (range < 1) range = 1; + + int value = m_value; + if (value < m_minimum) value = m_minimum; + else + if (value > m_maximum) value = m_maximum; + + float level = (float)(value - m_minimum) / range; // 0.0 to +1.0 + + int length = 0; + QRect rect; + + switch (m_orientation) + { + case Qt::Horizontal: + { + length = (int)((width() - 5) * level + 0.5f); + rect.setLeft(2); + rect.setTop(2); + rect.setWidth(length); + rect.setHeight(height() - 5); + } + break; + + case Qt::Vertical: + { + length = (int)((height() - 5) * level + 0.5f); + rect.setLeft(2); + rect.setTop(height() - 3 - length); + rect.setWidth(width() - 5); + rect.setHeight(length); + } + break; + } + + // background + painter.setPen(QColor(160, 160, 160)); + painter.setBrush(QColor(255, 255, 255)); +// painter.setPen(QColor(80, 80, 80)); +// painter.setPen(QColor(160, 160, 160)); +// painter.setBrush(QColor(160, 160, 160)); + painter.drawRect(QRect(0, 0, width() - 1, height() - 1)); + + if ((m_maximum - m_minimum) > 0) + { + // solid bar + painter.setPen(QColor(128, 128, 255)); + painter.setBrush(QColor(128, 128, 255)); + painter.drawRoundRect(rect, 3, 3); +/* + // colourful bar + for (int i = 0; i < length; i++) + { + if (!(i & 1)) + painter.setPen(QColor(0, 0, 0)); // black + else + painter.setPen(QColor(128, 255, 128)); // green +// painter.setPen(QColor(128, 128, 255)); // blue + + if (m_orientation == Qt::Horizontal) + painter.drawLine(rect.left() + i, rect.top(), rect.left() + i, rect.bottom() + 1); // horizontal bar + else + painter.drawLine(rect.left(), rect.bottom() + 1 - i, rect.right() + 1, rect.bottom() + 1 - i); // vertical bar + } +*/ + } +} diff --git a/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.h b/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.h new file mode 100644 index 000000000..22e84b4d2 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.h @@ -0,0 +1,77 @@ +/** + ****************************************************************************** + * + * @file widgetbar.h + * @author Cathy Moss Copyright (C) 2011. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup ConfigPlugin Configuration Plugin + * @{ + * @brief A bar display widget + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef WIDGETBAR_H +#define WIDGETBAR_H + +#include +#include +#include +#include + +QT_MODULE(Gui) + +class WidgetBar : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(int maximum READ maximum WRITE setMaximum) + Q_PROPERTY(int minimum READ minimum WRITE setMinimum) + Q_PROPERTY(int value READ value WRITE setValue) + + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + +public: + WidgetBar(QWidget *parent = 0); + + QSize minimumSizeHint() const; +// QSize sizeHint() const; + + void setMaximum(int value); + void setMinimum(int value); + void setValue(int value); + + int maximum() { return m_maximum; } + int minimum() { return m_minimum; } + int value() { return m_value; } + + Qt::Orientation orientation() const { return m_orientation; } + void setOrientation(Qt::Orientation orientation); + +protected: + void paintEvent(QPaintEvent *event); + +private: + int m_maximum; + int m_minimum; + int m_value; + + Qt::Orientation m_orientation; +}; + +#endif