mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +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 \
|
||||
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
|
||||
|
||||
|
@ -439,36 +439,27 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="2">
|
||||
<widget class="QProgressBar" name="progressBar_RSSI">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
<widget class="WidgetBar" name="widgetRSSI" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Received Signal Strength Indicator</string>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-120</number>
|
||||
<property name="mouseTracking">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>0</number>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>-60</number>
|
||||
</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 name="styleSheet">
|
||||
<string notr="true">background-color: rgb(112, 112, 112);</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -841,7 +832,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<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 name="styleSheet">
|
||||
<string notr="true"/>
|
||||
@ -1023,6 +1014,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>WidgetBar</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgetbar.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -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("");
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <QtCore/QLinkedList>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include "widgetbar.h"
|
||||
|
||||
// *************************
|
||||
// pipx config comms packets
|
||||
@ -138,7 +139,6 @@ public:
|
||||
public slots:
|
||||
void onTelemetryStart();
|
||||
void onTelemetryStop();
|
||||
|
||||
void onTelemetryConnect();
|
||||
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…
Reference in New Issue
Block a user