|
|
@ -1,6 +1,7 @@ |
|
|
|
#include "QGCRadioChannelDisplay.h" |
|
|
|
#include "QGCRadioChannelDisplay.h" |
|
|
|
#include <QPainter> |
|
|
|
#include <QPainter> |
|
|
|
QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent) |
|
|
|
QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent) |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_showMinMax = false; |
|
|
|
m_showMinMax = false; |
|
|
|
m_min = 0; |
|
|
|
m_min = 0; |
|
|
@ -8,6 +9,10 @@ QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent |
|
|
|
m_value = 1500; |
|
|
|
m_value = 1500; |
|
|
|
m_orientation = Qt::Vertical; |
|
|
|
m_orientation = Qt::Vertical; |
|
|
|
m_name = "Yaw"; |
|
|
|
m_name = "Yaw"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_fillBrush = QBrush(Qt::green, Qt::SolidPattern); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
void QGCRadioChannelDisplay::setName(QString name) |
|
|
|
void QGCRadioChannelDisplay::setName(QString name) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -26,81 +31,99 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) |
|
|
|
//1500 is the middle, static servo value.
|
|
|
|
//1500 is the middle, static servo value.
|
|
|
|
QPainter painter(this); |
|
|
|
QPainter painter(this); |
|
|
|
|
|
|
|
|
|
|
|
int currval = m_value; |
|
|
|
int fontHeight = painter.fontMetrics().height(); |
|
|
|
if (currval > m_max) |
|
|
|
int twiceFontHeight = fontHeight * 2; |
|
|
|
{ |
|
|
|
|
|
|
|
currval = m_max; |
|
|
|
painter.setBrush(Qt::Dense4Pattern); |
|
|
|
|
|
|
|
painter.setPen(QColor::fromRgb(128,128,64)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int curVal = m_value; |
|
|
|
|
|
|
|
if (curVal > m_max) { |
|
|
|
|
|
|
|
curVal = m_max; |
|
|
|
} |
|
|
|
} |
|
|
|
if (currval < m_min) |
|
|
|
if (curVal < m_min) { |
|
|
|
{ |
|
|
|
curVal = m_min; |
|
|
|
currval = m_min; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_orientation == Qt::Vertical) |
|
|
|
if (m_orientation == Qt::Vertical) |
|
|
|
{ |
|
|
|
{ |
|
|
|
painter.drawRect(0,0,width()-1,(height()-1) - (painter.fontMetrics().height() * 2)); |
|
|
|
//draw border
|
|
|
|
painter.setBrush(Qt::SolidPattern); |
|
|
|
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight); |
|
|
|
painter.setPen(QColor::fromRgb(50,255,50)); |
|
|
|
painter.setPen(QColor::fromRgb(50,255,50)); |
|
|
|
//m_value - m_min / m_max - m_min
|
|
|
|
painter.setBrush(Qt::SolidPattern); |
|
|
|
|
|
|
|
|
|
|
|
if (!m_showMinMax) |
|
|
|
//draw the text value of the widget, and its label
|
|
|
|
{ |
|
|
|
QString valStr = QString::number(m_value); |
|
|
|
int newval = (height()-2-(painter.fontMetrics().height() * 2)) * ((float)(currval - m_min) / ((m_max-m_min)+1)); |
|
|
|
painter.setPen(QColor::fromRgb(255,255,255)); |
|
|
|
int newvaly = (height()-2-(painter.fontMetrics().height() * 2)) - newval; |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name); |
|
|
|
painter.drawRect(1,newvaly,width()-3,((height()-2) - newvaly - (painter.fontMetrics().height() * 2))); |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valStr)/2.0),((height()-3) - (fontHeight * 0)),valStr); |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
painter.setPen(QColor::fromRgb(128,128,64)); |
|
|
|
int newval = (height()-2-(painter.fontMetrics().height() * 2)) * ((float)(currval / 3001.0)); |
|
|
|
painter.setBrush(m_fillBrush); |
|
|
|
int newvaly = (height()-2-(painter.fontMetrics().height() * 2)) - newval; |
|
|
|
|
|
|
|
painter.drawRect(1,newvaly,width()-3,((height()-2) - newvaly - (painter.fontMetrics().height() * 2))); |
|
|
|
if (!m_showMinMax) { |
|
|
|
|
|
|
|
//draw just the value
|
|
|
|
|
|
|
|
int newval = (height()-2-twiceFontHeight) * ((float)(curVal - m_min) / ((m_max-m_min)+1)); |
|
|
|
|
|
|
|
int yVal = (height()-2-twiceFontHeight) - newval; |
|
|
|
|
|
|
|
painter.drawRect(1,yVal,width()-3,((height()-2) - yVal - twiceFontHeight)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
//draw the value
|
|
|
|
|
|
|
|
int newval = (height()-2-twiceFontHeight) * ((float)(curVal / 3001.0)); |
|
|
|
|
|
|
|
int yVal = (height()-2-twiceFontHeight) - newval; |
|
|
|
|
|
|
|
painter.drawRect(1,yVal,width()-3,((height()-2) - yVal - twiceFontHeight)); |
|
|
|
|
|
|
|
|
|
|
|
QString valstr = QString::number(m_value); |
|
|
|
//draw min max indicator bars
|
|
|
|
painter.setPen(QColor::fromRgb(255,255,255)); |
|
|
|
|
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (painter.fontMetrics().height()*1)),m_name); |
|
|
|
|
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),valstr); |
|
|
|
|
|
|
|
if (m_showMinMax) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
|
|
|
|
painter.setPen(QColor::fromRgb(255,0,0)); |
|
|
|
painter.setPen(QColor::fromRgb(255,0,0)); |
|
|
|
int maxyval = (height()-3 - (painter.fontMetrics().height() * 2)) - (((height()-3-(painter.fontMetrics().height() * 2)) * ((float)m_max / 3000.0))); |
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
int minyval = (height()-3 - (painter.fontMetrics().height() * 2)) - (((height()-3-(painter.fontMetrics().height() * 2)) * ((float)m_min / 3000.0))); |
|
|
|
|
|
|
|
painter.drawRect(2,maxyval,width()-3,minyval - maxyval); |
|
|
|
int yMax = (height()-3 - twiceFontHeight) - (((height()-3-twiceFontHeight) * ((float)m_max / 3000.0))); |
|
|
|
|
|
|
|
int yMin = (height()-3 - twiceFontHeight) - (((height()-3-twiceFontHeight) * ((float)m_min / 3000.0))); |
|
|
|
|
|
|
|
painter.drawRect(2,yMax,width()-3,yMin - yMax); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//draw min and max labels
|
|
|
|
QString minstr = QString::number(m_min); |
|
|
|
QString minstr = QString::number(m_min); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width("min")/2.0),minyval,"min"); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width("min")/2.0),yMin,"min"); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width(minstr)/2.0),minyval + painter.fontMetrics().height(),minstr); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width(minstr)/2.0),yMin + fontHeight,minstr); |
|
|
|
|
|
|
|
|
|
|
|
QString maxstr = QString::number(m_max); |
|
|
|
QString maxstr = QString::number(m_max); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width("max")/2.0),maxyval,"max"); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width("max")/2.0),yMax,"max"); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width(maxstr)/2.0),maxyval + painter.fontMetrics().height(),maxstr); |
|
|
|
painter.drawText((width() / 2.0) - (painter.fontMetrics().width(maxstr)/2.0),yMax + fontHeight,maxstr); |
|
|
|
|
|
|
|
|
|
|
|
//painter.drawRect(width() * ,2,((width()-1) * ((float)m_max / 3000.0)) - (width() * ((float)m_min / 3000.0)),(height()-5) - (painter.fontMetrics().height() * 2));
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else //horizontal orientation
|
|
|
|
{ |
|
|
|
{ |
|
|
|
painter.drawRect(0,0,width()-1,(height()-1) - (painter.fontMetrics().height() * 2)); |
|
|
|
//draw the value
|
|
|
|
painter.setBrush(Qt::SolidPattern); |
|
|
|
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight); |
|
|
|
painter.setPen(QColor::fromRgb(50,255,50)); |
|
|
|
painter.setPen(QColor::fromRgb(50,255,50)); |
|
|
|
if (!m_showMinMax) |
|
|
|
painter.setBrush(m_fillBrush); |
|
|
|
{ |
|
|
|
|
|
|
|
painter.drawRect(1,1,(width()-3) * ((float)(currval-m_min) / (m_max-m_min)),(height()-3) - (painter.fontMetrics().height() * 2)); |
|
|
|
//draw the value string
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
painter.drawRect(1,1,(width()-3) * ((float)currval / 3000.0),(height()-3) - (painter.fontMetrics().height() * 2)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
painter.setPen(QColor::fromRgb(255,255,255)); |
|
|
|
painter.setPen(QColor::fromRgb(255,255,255)); |
|
|
|
QString valstr = QString::number(m_value); |
|
|
|
QString valstr = QString::number(m_value); |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (painter.fontMetrics().height()*1)),m_name); |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name); |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),valstr); |
|
|
|
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valstr)/2.0),((height()-3) - (fontHeight * 0)),valstr); |
|
|
|
if (m_showMinMax) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
painter.setPen(QColor::fromRgb(0,128,0)); |
|
|
|
|
|
|
|
painter.setBrush(m_fillBrush); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_showMinMax) { |
|
|
|
|
|
|
|
//draw just the value
|
|
|
|
|
|
|
|
painter.drawRect(1,1,(width()-3) * ((float)(curVal-m_min) / (m_max-m_min)),(height()-3) - twiceFontHeight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
//draw the value
|
|
|
|
|
|
|
|
painter.drawRect(1,1,(width()-3) * ((float)curVal / 3000.0),(height()-3) - twiceFontHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//draw the min and max bars
|
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
painter.setPen(QColor::fromRgb(255,0,0)); |
|
|
|
painter.setPen(QColor::fromRgb(255,0,0)); |
|
|
|
painter.drawRect(width() * ((float)m_min / 3000.0),2,((width()-1) * ((float)m_max / 3000.0)) - (width() * ((float)m_min / 3000.0)),(height()-5) - (painter.fontMetrics().height() * 2)); |
|
|
|
painter.drawRect(width() * ((float)m_min / 3000.0),2,((width()-1) * ((float)m_max / 3000.0)) - (width() * ((float)m_min / 3000.0)),(height()-5) - twiceFontHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//draw the min and max strings
|
|
|
|
QString minstr = QString::number(m_min); |
|
|
|
QString minstr = QString::number(m_min); |
|
|
|
painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width("min")/2.0),((height()-3) - (painter.fontMetrics().height()*1)),"min"); |
|
|
|
painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width("min")/2.0),((height()-3) - (painter.fontMetrics().height()*1)),"min"); |
|
|
|
painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width(minstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),minstr); |
|
|
|
painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width(minstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),minstr); |
|
|
|