mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
Added widgetbar for RSSI indicator because QProgressBar going in large steps.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2925 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
1a83f0c461
commit
eb5b97ca3a
@ -18,6 +18,7 @@ HEADERS += pipxtremegadget.h \
|
|||||||
pipxtremegadgetoptionspage.h \
|
pipxtremegadgetoptionspage.h \
|
||||||
pipxtremegadgetwidget.h \
|
pipxtremegadgetwidget.h \
|
||||||
pipxtremeplugin.h \
|
pipxtremeplugin.h \
|
||||||
|
widgetbar.h
|
||||||
|
|
||||||
SOURCES += pipxtremegadget.cpp \
|
SOURCES += pipxtremegadget.cpp \
|
||||||
pipxtremegadgetconfiguration.cpp \
|
pipxtremegadgetconfiguration.cpp \
|
||||||
@ -25,6 +26,7 @@ SOURCES += pipxtremegadget.cpp \
|
|||||||
pipxtremegadgetoptionspage.cpp \
|
pipxtremegadgetoptionspage.cpp \
|
||||||
pipxtremegadgetwidget.cpp \
|
pipxtremegadgetwidget.cpp \
|
||||||
pipxtremeplugin.cpp \
|
pipxtremeplugin.cpp \
|
||||||
|
widgetbar.cpp
|
||||||
|
|
||||||
OTHER_FILES += pipxtreme.pluginspec
|
OTHER_FILES += pipxtreme.pluginspec
|
||||||
|
|
||||||
|
@ -439,36 +439,27 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1" colspan="2">
|
<item row="7" column="1" colspan="2">
|
||||||
<widget class="QProgressBar" name="progressBar_RSSI">
|
<widget class="WidgetBar" name="widgetRSSI" native="true">
|
||||||
<property name="font">
|
<property name="sizePolicy">
|
||||||
<font>
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<weight>75</weight>
|
<horstretch>0</horstretch>
|
||||||
<bold>true</bold>
|
<verstretch>0</verstretch>
|
||||||
</font>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="minimumSize">
|
||||||
<string>Received Signal Strength Indicator</string>
|
<size>
|
||||||
|
<width>1</width>
|
||||||
|
<height>1</height>
|
||||||
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimum">
|
<property name="mouseTracking">
|
||||||
<number>-120</number>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="autoFillBackground">
|
||||||
<number>0</number>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="styleSheet">
|
||||||
<number>-60</number>
|
<string notr="true">background-color: rgb(112, 112, 112);</string>
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="textVisible">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="textDirection">
|
|
||||||
<enum>QProgressBar::TopToBottom</enum>
|
|
||||||
</property>
|
|
||||||
<property name="format">
|
|
||||||
<string>%v</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -841,7 +832,7 @@
|
|||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>The AES encryption key - has to be the same key on the remote modem as well)</string>
|
<string>The AES encryption key - has to be the same key on the remote modem.</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
@ -1023,6 +1014,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>WidgetBar</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>widgetbar.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -132,11 +132,11 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) :
|
|||||||
m_widget = new Ui_PipXtremeWidget();
|
m_widget = new Ui_PipXtremeWidget();
|
||||||
m_widget->setupUi(this);
|
m_widget->setupUi(this);
|
||||||
|
|
||||||
#if QT_VERSION >= 0x040700
|
#if QT_VERSION >= 0x040700
|
||||||
qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch());
|
qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch());
|
||||||
#else
|
#else
|
||||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
device_input_buffer.size = 8192;
|
device_input_buffer.size = 8192;
|
||||||
device_input_buffer.used = 0;
|
device_input_buffer.used = 0;
|
||||||
@ -206,9 +206,9 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) :
|
|||||||
|
|
||||||
m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
||||||
|
|
||||||
m_widget->progressBar_RSSI->setMinimum(-120);
|
m_widget->widgetRSSI->setMinimum(-120);
|
||||||
m_widget->progressBar_RSSI->setMaximum(0);
|
m_widget->widgetRSSI->setMaximum(0);
|
||||||
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->label_RSSI->setText("RSSI");
|
||||||
|
|
||||||
@ -477,8 +477,11 @@ void PipXtremeGadgetWidget::enableTelemetry()
|
|||||||
|
|
||||||
void PipXtremeGadgetWidget::randomiseAESKey()
|
void PipXtremeGadgetWidget::randomiseAESKey()
|
||||||
{
|
{
|
||||||
// uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toMSecsSinceEpoch(); // only available with Qt 4.7.1 and later
|
#if QT_VERSION >= 0x040700
|
||||||
uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toTime_t();
|
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 = "";
|
QString key = "";
|
||||||
for (int i = 0; i < 4; i++)
|
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) + "]");
|
m_widget->lineEdit_LinkState->setText("Unknown [" + QString::number(pipx_config_state.link_state) + "]");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pipx_config_state.rssi < m_widget->progressBar_RSSI->minimum())
|
if (pipx_config_state.rssi < m_widget->widgetRSSI->minimum())
|
||||||
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum());
|
m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->minimum());
|
||||||
else
|
else
|
||||||
if (pipx_config_state.rssi > m_widget->progressBar_RSSI->maximum())
|
if (pipx_config_state.rssi > m_widget->widgetRSSI->maximum())
|
||||||
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->maximum());
|
m_widget->widgetRSSI->setValue(m_widget->widgetRSSI->maximum());
|
||||||
else
|
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->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_RxAFC->setText(QString::number(pipx_config_state.afc) + "Hz");
|
||||||
m_widget->lineEdit_Retries->setText(QString::number(pipx_config_state.retries));
|
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_MaxFrequency->setText("");
|
||||||
m_widget->lineEdit_FrequencyStepSize->setText("");
|
m_widget->lineEdit_FrequencyStepSize->setText("");
|
||||||
m_widget->lineEdit_LinkState->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->label_RSSI->setText("RSSI");
|
||||||
m_widget->lineEdit_RxAFC->setText("");
|
m_widget->lineEdit_RxAFC->setText("");
|
||||||
m_widget->lineEdit_Retries->setText("");
|
m_widget->lineEdit_Retries->setText("");
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
#include <QtCore/QLinkedList>
|
#include <QtCore/QLinkedList>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
#include "widgetbar.h"
|
||||||
|
|
||||||
// *************************
|
// *************************
|
||||||
// pipx config comms packets
|
// pipx config comms packets
|
||||||
@ -138,7 +139,6 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void onTelemetryStart();
|
void onTelemetryStart();
|
||||||
void onTelemetryStop();
|
void onTelemetryStop();
|
||||||
|
|
||||||
void onTelemetryConnect();
|
void onTelemetryConnect();
|
||||||
void onTelemetryDisconnect();
|
void onTelemetryDisconnect();
|
||||||
|
|
||||||
|
157
ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.cpp
Normal file
157
ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.cpp
Normal file
@ -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 <QtGui>
|
||||||
|
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
77
ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.h
Normal file
77
ground/openpilotgcs/src/plugins/pipxtreme/widgetbar.h
Normal file
@ -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 <QBrush>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user