Commit 0dbb002d authored by Don Gagne's avatar Don Gagne

Custom tool widgets discontinued

Will be replaced by Qml + FactSystem tool widget support
parent 21e80f46
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCActionButton</class>
<widget class="QWidget" name="QGCActionButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>111</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,100,50">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QComboBox" name="editActionComboBox"/>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="editActionsRefreshButton">
<property name="text">
<string>Refresh Actions</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="editButtonName">
<property name="placeholderText">
<string>Button name</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLineEdit" name="editNameLabel">
<property name="placeholderText">
<string>Description</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="actionButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Button name</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>editNameLabel</sender>
<signal>textChanged(QString)</signal>
<receiver>nameLabel</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>55</y>
</hint>
</hints>
</connection>
</connections>
</ui>
This diff is collapsed.
#ifndef QGCCOMMANDBUTTON_H
#define QGCCOMMANDBUTTON_H
#include "QGCToolWidgetItem.h"
namespace Ui
{
class QGCCommandButton;
}
class UASInterface;
class QGCCommandButton : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCCommandButton(QWidget *parent = 0);
~QGCCommandButton();
virtual void setEditMode(bool editMode);
public slots:
void sendCommand();
void setCommandButtonName(QString text);
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
signals:
void showLabel(QString name, int num);
private:
int responsenum;
int responsecount;
QString showlabelname;
Ui::QGCCommandButton *ui;
UASInterface* uas;
};
#endif // QGCCOMMANDBUTTON_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCCommandButton</class>
<widget class="QWidget" name="QGCCommandButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1235</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,0,0,0">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="7" column="0" colspan="3">
<widget class="QComboBox" name="editCommandComboBox">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="3">
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="editButtonName">
<property name="text">
<string>&lt;Button Label&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QLineEdit" name="editNameLabel">
<property name="placeholderText">
<string>Button Description</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QPushButton" name="commandButton">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Unnamed</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QSpinBox" name="editComponentSpinBox">
<property name="prefix">
<string>Component ID: </string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="6" column="2" colspan="2">
<widget class="QCheckBox" name="editConfirmationCheckBox">
<property name="toolTip">
<string>Set the confirm flag for this button. Some commands require that first one command is sent without confirm flag and then a second, equal command with confirm flag. This ensures safety.</string>
</property>
<property name="text">
<string>Set CONFIRM flag</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="editParam1SpinBox">
<property name="toolTip">
<string>PARAM1 Value as defined in MAV_CMD list</string>
</property>
<property name="statusTip">
<string>PARAM1 Value as defined in MAV_CMD list</string>
</property>
<property name="prefix">
<string>P1 </string>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam2SpinBox">
<property name="toolTip">
<string>PARAM2 Value as defined in MAV_CMD list</string>
</property>
<property name="statusTip">
<string>PARAM2 Value as defined in MAV_CMD list</string>
</property>
<property name="prefix">
<string>P2: </string>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam3SpinBox">
<property name="toolTip">
<string>PARAM3 Value as defined in MAV_CMD list</string>
</property>
<property name="statusTip">
<string>PARAM3 Value as defined in MAV_CMD list</string>
</property>
<property name="prefix">
<string>P3: </string>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam4SpinBox">
<property name="toolTip">
<string>PARAM4 Value as defined in MAV_CMD list</string>
</property>
<property name="statusTip">
<string>PARAM4 Value as defined in MAV_CMD list</string>
</property>
<property name="prefix">
<string>P4: </string>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam5SpinBox">
<property name="prefix">
<string>P5: </string>
</property>
<property name="decimals">
<number>7</number>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam6SpinBox">
<property name="prefix">
<string>P6: </string>
</property>
<property name="decimals">
<number>7</number>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="editParam7SpinBox">
<property name="prefix">
<string>P7: </string>
</property>
<property name="minimum">
<double>-2147483647.000000000000000</double>
</property>
<property name="maximum">
<double>2147483647.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="3">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="editParamsVisibleCheckBox">
<property name="text">
<string>Keep parameters visible</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="Line" name="editLine1">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="4">
<widget class="Line" name="editLine2">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>editNameLabel</sender>
<signal>textChanged(QString)</signal>
<receiver>nameLabel</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>55</y>
</hint>
</hints>
</connection>
</connections>
</ui>
This diff is collapsed.
#ifndef QGCPARAMSLIDER_H
#define QGCPARAMSLIDER_H
#include <QWidget>
#include <QAction>
#ifndef __android__
#include <QtDesigner/QDesignerExportWidget>
#endif
#include "QGCToolWidgetItem.h"
namespace Ui
{
class QGCParamSlider;
}
class QGCParamSlider : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCParamSlider(QWidget *parent = 0);
~QGCParamSlider();
virtual void setEditMode(bool editMode);
public slots:
/** @brief Queue parameter for sending to the MAV (add to pending list)*/
void setParamPending();
/** @brief Set the slider value as parameter value */
void setSliderValue(int sliderValue);
/** @brief Update the UI with the new parameter value */
void setParameterValue(int uas, int componentId, int paramCount, int paramIndex, QString parameterName, const QVariant value);
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void refreshParamList();
void setActiveUAS(UASInterface *uas);
void selectComponent(int componentIndex);
void selectParameter(int paramIndex);
/** @brief Set a double parameter value */
void setParamValue(double value);
/** @brief Set an integer parameter value */
void setParamValue(int value);
/** @brief Show descriptive text next to slider */
void showInfo(bool enable);
/** @brief Show tool tip of calling element */
void showTooltip();
protected slots:
/** @brief Request the parameter of this widget from the MAV */
void requestParameter();
protected:
bool visibleEnabled;
QString visibleParam;
int visibleVal;
//The below variables, and usage in QGCParamSlider.cc are a bit of a hack, since disconnect() does not seem to take effect
//immediatly (perhaps it is put into the event loop?) - MLC
bool valueModLock; ///< Used to keep the slider/spinboxes from updating each other during user input
bool valueModLockParam; ///< Used to keep the slider/spinboxes from udpating each other when a new parametervalue comes in
QString parameterName; ///< Key/Name of the parameter
QVariant parameterValue; ///< Value of the parameter
double parameterScalingFactor; ///< Factor to scale the parameter between slider and true value
float parameterMin;
float parameterMax;
int componentId; ///< ID of the MAV component to address
double scaledInt;
void changeEvent(QEvent *e);
/** @brief Convert scaled int to float */
float scaledIntToFloat(int sliderValue);
int floatToScaledInt(float value);
private:
Ui::QGCParamSlider *ui;
};
#endif // QGCPARAMSLIDER_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCParamSlider</class>
<widget class="QWidget" name="QGCParamSlider">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>789</width>
<height>244</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="10,0,0,0,0,0,0,0,0,0,0">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="2" column="6">
<widget class="QSpinBox" name="intValueSpinBox">
<property name="minimum">
<number>-999999999</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="3" column="6" colspan="3">
<widget class="QComboBox" name="editSelectParamComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select parameter</string>
</property>
<property name="statusTip">
<string>Select parameter</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="11">
<widget class="Line" name="editLine1">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="7" colspan="2">
<widget class="QSlider" name="valueSlider">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="10">
<widget class="QPushButton" name="editDoneButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="11">
<widget class="Line" name="editLine2">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="9">
<widget class="QCheckBox" name="editInfoCheckBox">
<property name="text">
<string>Show Info</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="10">
<widget class="QPushButton" name="editRefreshParamsButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="2" column="10">
<widget class="QPushButton" name="readButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Read the current parameter value on the system</string>
</property>
<property name="statusTip">
<string>Read the current parameter value on the system</string>
</property>
<property name="text">
<string>Get</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="5">
<widget class="QComboBox" name="editSelectComponentComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select component</string>
</property>
<property name="statusTip">
<string>Select component</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="7">
<widget class="QLineEdit" name="editNameLabel">
<property name="placeholderText">
<string>Parameter Name / Label</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="8">
<widget class="QLabel" name="editStatusLabel">
<property name="text">
<string>Please click first on refresh to update selection menus..</string>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="writeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="statusTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="text">
<string>Set</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QDoubleSpinBox" name="doubleValueSpinBox">
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="8">
<widget class="QDoubleSpinBox" name="editMinSpinBox">
<property name="prefix">
<string>MIN: </string>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="9" colspan="2">
<widget class="QDoubleSpinBox" name="editMaxSpinBox">
<property name="prefix">
<string>MAX: </string>
</property>
<property name="minimum">
<double>-999999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QToolButton" name="infoLabel">
<property name="text">
<string>?</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="11">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "QGCParamSliderPlugin.h"
#include "QGCParamSlider.h"
#include <QtPlugin>
QGCParamSliderPlugin::QGCParamSliderPlugin(QObject *parent) :
QObject(parent)
{
initialized = false;
}
void QGCParamSliderPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
if (initialized)
return;
initialized = true;
}
bool QGCParamSliderPlugin::isInitialized() const
{
return initialized;
}
QWidget *QGCParamSliderPlugin::createWidget(QWidget *parent)
{
return new QGCParamSlider(parent);
}
QString QGCParamSliderPlugin::name() const
{
return "QGCParamSlider";
}
QString QGCParamSliderPlugin::group() const
{
return "QGroundControl";
}
QIcon QGCParamSliderPlugin::icon() const
{
return QIcon();
}
QString QGCParamSliderPlugin::toolTip() const
{
return "";
}
QString QGCParamSliderPlugin::whatsThis() const
{
return "";
}
bool QGCParamSliderPlugin::isContainer() const
{
return false;
}
QString QGCParamSliderPlugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"QGCParamSlider\" name=\"paramSlider\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>150</width>\n"
" <height>16</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>";
}
QString QGCParamSliderPlugin::includeFile() const
{
return "QGCParamSlider.h";
}
Q_EXPORT_PLUGIN2(qgcparamsliderplugin, QGCParamSliderPlugin)
#include "QGCRadioChannelDisplay.h"
#include <QPainter>
#define DIMMEST_COLOR QColor::fromRgb(0,100,0)
#define MIDBRIGHT_COLOR QColor::fromRgb(0,180,0)
#define BRIGHTEST_COLOR QColor::fromRgb(64,255,0)
QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent)
{
m_showMinMax = false;
m_min = 0;
m_max = 1;
m_value = 1500;
m_orientation = Qt::Vertical;
m_name = "Yaw";
m_fillBrush = QBrush(Qt::green, Qt::SolidPattern);
}
void QGCRadioChannelDisplay::setName(QString name)
{
m_name = name;
update();
}
void QGCRadioChannelDisplay::setOrientation(Qt::Orientation orient)
{
m_orientation = orient;
update();
}
void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
//Values range from 0-3000.
//1500 is the middle, static servo value.
QPainter painter(this);
int fontHeight = painter.fontMetrics().height();
int twiceFontHeight = fontHeight * 2;
painter.setBrush(Qt::Dense4Pattern);
painter.setPen(QColor::fromRgb(128,128,64));
int curVal = m_value;
if (curVal > m_max) {
curVal = m_max;
}
if (curVal < m_min) {
curVal = m_min;
}
if (m_orientation == Qt::Vertical)
{
QLinearGradient gradientBrush(0, 0, this->width(), this->height());
gradientBrush.setColorAt(1.0,DIMMEST_COLOR);
gradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
gradientBrush.setColorAt(0.0, BRIGHTEST_COLOR);
//draw border
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
painter.setPen(QColor::fromRgb(50,255,50));
painter.setBrush(Qt::SolidPattern);
//draw the text value of the widget, and its label
painter.setPen(QColor::fromRgb(255,255,255));
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name);
if (isEnabled()) {
QString valStr = QString::number(m_value);
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valStr)/2.0),((height()-3) - (fontHeight * 0)),valStr);
painter.setPen(QColor::fromRgb(128,128,64));
painter.setBrush(gradientBrush);
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));
//draw min max indicator bars
painter.setPen(QColor::fromRgb(255,0,0));
painter.setBrush(Qt::NoBrush);
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);
painter.drawText((width() / 2.0) - (painter.fontMetrics().width("min")/2.0),yMin,"min");
painter.drawText((width() / 2.0) - (painter.fontMetrics().width(minstr)/2.0),yMin + fontHeight,minstr);
QString maxstr = QString::number(m_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),yMax + fontHeight,maxstr);
}
}
}
else //horizontal orientation
{
QLinearGradient hGradientBrush(0, 0, this->width(), this->height());
hGradientBrush.setColorAt(0.0,DIMMEST_COLOR);
hGradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
hGradientBrush.setColorAt(1.0, BRIGHTEST_COLOR);
//draw the value
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
painter.setPen(QColor::fromRgb(50,255,50));
painter.setBrush(hGradientBrush);
//draw the value string
painter.setPen(QColor::fromRgb(255,255,255));
painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name);
if (isEnabled()) {
QString valstr = QString::number(m_value);
painter.drawText((width()/2.0) - (painter.fontMetrics().width(valstr)/2.0),((height()-3) - (fontHeight * 0)),valstr);
painter.setPen(QColor::fromRgb(0,128,0));
painter.setBrush(hGradientBrush);
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.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) - twiceFontHeight);
//draw the min and max strings
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(minstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),minstr);
QString maxstr = QString::number(m_max);
painter.drawText((width() * ((float)m_max / 3000.0)) - (painter.fontMetrics().width("max")/2.0),((height()-3) - (painter.fontMetrics().height()*1)),"max");
painter.drawText((width() * ((float)m_max / 3000.0)) - (painter.fontMetrics().width(maxstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),maxstr);
}
}
}
}
void QGCRadioChannelDisplay::setValue(int value)
{
if (value < 0)
{
m_value = 0;
}
else if (value > 3000)
{
m_value = 3000;
}
else
{
m_value = value;
}
update();
}
void QGCRadioChannelDisplay::showMinMax(bool show)
{
m_showMinMax = show;
update();
}
void QGCRadioChannelDisplay::hideMinMax()
{
m_showMinMax = false;
update();
}
void QGCRadioChannelDisplay::setValueAndRange(int val, int min, int max)
{
setValue(val);
setMinMax(min,max);
}
void QGCRadioChannelDisplay::setMinMax(int min, int max)
{
setMin(min);
setMax(max);
}
void QGCRadioChannelDisplay::setMin(int value)
{
m_min = value;
if (m_min == m_max)
{
m_min--;
}
update();
}
void QGCRadioChannelDisplay::setMax(int value)
{
m_max = value;
if (m_min == m_max)
{
m_max++;
}
update();
}
#ifndef QGCRADIOCHANNELDISPLAY_H
#define QGCRADIOCHANNELDISPLAY_H
#include <QWidget>
class QGCRadioChannelDisplay : public QWidget
{
Q_OBJECT
public:
explicit QGCRadioChannelDisplay(QWidget *parent = 0);
void setOrientation(Qt::Orientation orient);
void setValue(int value);
void showMinMax(bool show = true);
void hideMinMax();
bool isMinMaxShown() { return m_showMinMax; }
void setValueAndRange(int val, int min, int max);
void setMinMax(int min, int max);
void setMin(int value);
void setMax(int value);
void setName(QString name);
int value() { return m_value; }
int min() { return m_min; }
int max() { return m_max; }
protected:
void paintEvent(QPaintEvent *event);
private:
Qt::Orientation m_orientation;
int m_value;
int m_min;
int m_max;
bool m_showMinMax;
QString m_name;
QBrush m_fillBrush;
signals:
public slots:
};
#endif // QGCRADIOCHANNELDISPLAY_H
#include <QDockWidget>
#include "QGCTextLabel.h"
#include "ui_QGCTextLabel.h"
#include "MAVLinkProtocol.h"
#include "UASManager.h"
QGCTextLabel::QGCTextLabel(QWidget *parent) :
QGCToolWidgetItem("Text Label", parent),
ui(new Ui::QGCTextLabel)
{
uas = 0;
enabledNum = -1;
ui->setupUi(this);
connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
connect(ui->isMavCommand, SIGNAL(toggled(bool)), this, SLOT(update_isMavCommand()));
// Hide all edit items
ui->editFinishButton->hide();
ui->editNameLabel->hide();
ui->editLine1->hide();
ui->editLine2->hide();
ui->isMavCommand->hide();
ui->textLabel->setText(QString());
init();
}
QGCTextLabel::~QGCTextLabel()
{
delete ui;
}
void QGCTextLabel::setEditMode(bool editMode)
{
if(!editMode)
update_isMavCommand();
ui->editFinishButton->setVisible(editMode);
ui->editNameLabel->setVisible(editMode);
ui->editLine1->setVisible(editMode);
ui->editLine2->setVisible(editMode);
ui->isMavCommand->setVisible(editMode);
QGCToolWidgetItem::setEditMode(editMode);
}
void QGCTextLabel::writeSettings(QSettings& settings)
{
settings.setValue("TYPE", "TEXT");
settings.setValue("QGC_TEXT_TEXT", ui->editNameLabel->text());
settings.setValue("QGC_TEXT_SOURCE", ui->isMavCommand->isChecked()?"MAV":"NONE");
settings.sync();
}
void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings)
{
ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString());
ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
update_isMavCommand();
}
void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message)
{
Q_UNUSED(uasid);
Q_UNUSED(component);
Q_UNUSED(severity);
if (enabledNum != -1)
{
//SUCCESS: Executed CMD: 241
if (message.contains("SUCCESS"))
{
if (message.trimmed().endsWith(QString::number(enabledNum)))
{
enabledNum = -1;
ui->textLabel->setText(ui->textLabel->text() + " Complete");
}
}
else
{
ui->textLabel->setText(message);
}
}
}
void QGCTextLabel::readSettings(const QSettings& settings)
{
ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); //Place this before setting isMavCommand
ui->isMavCommand->setChecked(settings.value("QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
update_isMavCommand();
}
void QGCTextLabel::enableText(int num)
{
enabledNum = num;
}
void QGCTextLabel::setActiveUAS(UASInterface *uas)
{
if(this->uas)
this->uas->disconnect(this);
this->uas = uas;
update_isMavCommand(); //Might need to update the signal connections
}
void QGCTextLabel::update_isMavCommand()
{
ui->textLabel->setText("");
if (!ui->isMavCommand->isChecked())
{
ui->nameLabel->setText(ui->editNameLabel->text());
if(this->uas)
disconnect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString)));
if(ui->nameLabel->text().isEmpty())
ui->nameLabel->setText(tr("Text Label")); //Show something, so that we don't end up with just an empty label
}
else
{
//MAV command text
ui->nameLabel->setText(ui->editNameLabel->text());
if(this->uas)
connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString)));
}
}
#ifndef QGCTEXTLABEL_H
#define QGCTEXTLABEL_H
#include "QGCToolWidgetItem.h"
namespace Ui
{
class QGCTextLabel;
}
class UASInterface;
class QGCTextLabel : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCTextLabel(QWidget *parent = 0);
~QGCTextLabel();
void setActiveUAS(UASInterface *uas);
void enableText(int num);
virtual void setEditMode(bool editMode);
public slots:
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void textMessageReceived(int uasid, int componentId, int severity, QString message);
private slots:
void update_isMavCommand();
private:
int enabledNum;
Ui::QGCTextLabel *ui;
};
#endif // QGCTEXTLABEL_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCTextLabel</class>
<widget class="QWidget" name="QGCTextLabel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>554</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Line" name="editLine1">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="editNameLabel">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Label Description</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="isMavCommand">
<property name="toolTip">
<string>This is only for advanced use, and allows a label to display the results of a Command Button.</string>
</property>
<property name="text">
<string>Mav Command</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Text Label</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel">
<property name="text">
<string>mav result</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="editLine2">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>editNameLabel</sender>
<signal>textChanged(QString)</signal>
<receiver>nameLabel</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>280</x>
<y>32</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>55</y>
</hint>
</hints>
</connection>
<connection>
<sender>editNameLabel</sender>
<signal>returnPressed()</signal>
<receiver>editFinishButton</receiver>
<slot>animateClick()</slot>
<hints>
<hint type="sourcelabel">
<x>136</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>498</x>
<y>86</y>
</hint>
</hints>
</connection>
</connections>
</ui>
This diff is collapsed.
#ifndef QGCTOOLWIDGET_H
#define QGCTOOLWIDGET_H
#include <QWidget>
#include <QAction>
#include <QMap>
#include <QVBoxLayout>
#include "QGCToolWidgetItem.h"
#include "UAS.h"
namespace Ui
{
class QGCToolWidget;
}
class QGCToolWidget : public QWidget
{
Q_OBJECT
public:
explicit QGCToolWidget(const QString& objectName, const QString& title, QWidget *parent = 0, QSettings* settings = 0);
~QGCToolWidget();
/** @brief Factory method to instantiate all tool widgets */
static QList<QGCToolWidget*> createWidgetsFromSettings(QWidget* parent, QString settingsFile=QString());
/** @Give the tool widget a reference to its action in the main menu */
void setMainMenuAction(QAction* action);
/** @brief All instances of this class */
static QMap<QString, QGCToolWidget*>* instances();
/** @brief Get title of widget */
QString getTitle() const;
int isVisible(int view) const { return viewVisible.value(view, false); }
Qt::DockWidgetArea getDockWidgetArea(int view) { return dockWidgetArea.value(view, Qt::BottomDockWidgetArea); }
void setParent(QWidget *parent);
/** @brief Store all widgets of this type to QSettings */
static void storeWidgetsToSettings(QSettings &settingsFile);
public slots:
void addUAS(UASInterface* uas);
/** @brief Delete this widget */
void deleteWidget();
/** @brief Export this widget to a file */
void exportWidget();
/** @brief Import settings for this widget from a file */
void importWidget();
/** @brief Store all widgets of this type to QSettings */
void storeWidgetsToSettings() { QSettings settings; QGCToolWidget::storeWidgetsToSettings(settings); }
void showLabel(QString name,int num);
public:
void loadSettings(QVariantMap& settings);
/** @brief Load this widget from a QSettings object */
void loadSettings(QSettings& settings);
/** @brief Load this widget from a settings file */
bool loadSettings(const QString& settings, bool singleinstance=false);
/** @brief Store the view id and dock widget area */
void setViewVisibilityAndDockWidgetArea(int view, bool visible, Qt::DockWidgetArea area);
void setSettings(QVariantMap& settings);
QList<QString> getParamList();
void setParameterValue(int uas, int component, QString parameterName, const QVariant value);
bool fromMetaData() const { return isFromMetaData; }
signals:
void titleChanged(const QString &title);
protected:
bool isFromMetaData;
QMap<QString,QGCToolWidgetItem*> paramToItemMap;
QList<QGCToolWidgetItem*> toolItemList;
QList<QString> paramList;
QVariantMap settingsMap;
QAction* addParamAction;
QAction* addCommandAction;
QAction* addPlotAction;
QAction* addLabelAction;
QAction* setTitleAction;
QAction* deleteAction;
QAction* exportAction;
QAction* importAction;
QVBoxLayout* toolLayout;
UAS* mav;
QAction* mainMenuAction; ///< Main menu action
QMap<int, Qt::DockWidgetArea> dockWidgetArea; ///< Dock widget area desired by this widget
QMap<int, bool> viewVisible; ///< Visibility in one view
QString widgetTitle;
void contextMenuEvent(QContextMenuEvent* event);
void createActions();
/** @brief Add an existing tool widget */
void addToolWidget(QGCToolWidgetItem* widget);
/** @brief Add an existing tool widget and set it to edit mode */
void addToolWidgetAndEdit(QGCToolWidgetItem* widget);
void hideEvent(QHideEvent* event);
public slots:
void setTitle(const QString &title);
void addParam(int uas,int component,QString paramname,QVariant value);
protected slots:
void addParam();
void addCommand();
void addPlot();
void addLabel();
void setTitle();
void widgetRemoved();
private:
/** Do not use this from outside the class to set the object name,
* because we cannot track changes to the object name, and the
* QObject::setObjectName() function is not virtual. Instead only
* pass in the object name to the constructor, or use the , then
* never change it again. */
void setObjectName(const QString &name) { QWidget::setObjectName(name); }
/** Helper for storeWidgetsToSettings() */
void storeSettings(QSettings& settings);
Ui::QGCToolWidget *ui;
};
#endif // QGCTOOLWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCToolWidget</class>
<widget class="QWidget" name="QGCToolWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="toolLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="hintLabel">
<property name="text">
<string>Right-click into the widget to customize</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
#ifndef QGCToolWidgetComboBox_H
#define QGCToolWidgetComboBox_H
#include <QWidget>
#include <QAction>
#ifndef __android__
#include <QtDesigner/QDesignerExportWidget>
#endif
#include "QGCToolWidgetItem.h"
class QGCUASParamManagerInterface;
namespace Ui
{
class QGCToolWidgetComboBox;
}
class QGCToolWidgetComboBox : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCToolWidgetComboBox(QWidget *parent = 0);
~QGCToolWidgetComboBox();
virtual void setEditMode(bool editMode);
public slots:
/** @brief Queue parameter for sending to the MAV (add to pending list)*/
void setParamPending();
/** @brief Update the UI with the new parameter value */
void setParameterValue(int uas, int componentId, int paramCount, int paramIndex, QString parameterName, const QVariant value);
void writeSettings(QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void readSettings(const QSettings& settings);
/** @brief request that the parameter for this widget be refreshed */
void refreshParameter();
void setActiveUAS(UASInterface *uas);
void selectComponent(int componentIndex);
void selectParameter(int paramIndex);
/** @brief Show descriptive text next to slider */
void showInfo(bool enable);
/** @brief Show tool tip of calling element */
void showTooltip();
protected slots:
/** @brief Request the parameter of this widget from the MAV */
void requestParameter();
/** @brief Button click to add a new item to the combobox */
void addButtonClicked();
/** @brief Button click to remove the currently selected item from the combobox */
void delButtonClicked();
/** @brief Updates current parameter based on new combobox value */
void comboBoxIndexChanged(QString val);
protected:
QGCUASParamManagerInterface *paramMgr; ///< Access to parameter manager
bool visibleEnabled;
QString visibleParam;
int visibleVal;
QMap<QString,QString> comboBoxTextToParamMap;
QMap<int,QPixmap> comboBoxIndexToPixmap;
QMap<QString,int> comboBoxTextToValMap; ///< Comboboxtext/parameter value map
QString parameterName; ///< Key/Name of the parameter
QVariant parameterValue; ///< Value of the parameter
double parameterScalingFactor; ///< Factor to scale the parameter between slider and true value
float parameterMin;
bool isDisabled;
float parameterMax;
int componentId; ///< ID of the MAV component to address
//double scaledInt;
void changeEvent(QEvent *e);
private:
Ui::QGCToolWidgetComboBox *ui;
};
#endif // QGCToolWidgetComboBox_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCToolWidgetComboBox</class>
<widget class="QWidget" name="QGCToolWidgetComboBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>789</width>
<height>244</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="10,0,0,0,0,0,0,0,0,0,0,0">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="4" column="7">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="8">
<widget class="QToolButton" name="infoLabel">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>?</string>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonIconOnly</enum>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item row="1" column="9">
<widget class="QLineEdit" name="editNameLabel">
<property name="placeholderText">
<string>Parameter Name</string>
</property>
</widget>
</item>
<item row="7" column="9">
<widget class="QLineEdit" name="editItemNameLabel"/>
</item>
<item row="7" column="7">
<widget class="QSpinBox" name="editItemValueSpinBox"/>
</item>
<item row="4" column="9">
<widget class="QComboBox" name="editOptionComboBox"/>
</item>
<item row="7" column="8">
<widget class="QLabel" name="itemNameLabel">
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="8">
<widget class="QComboBox" name="editSelectComponentComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select component</string>
</property>
<property name="statusTip">
<string>Select component</string>
</property>
</widget>
</item>
<item row="7" column="10">
<widget class="QPushButton" name="editAddItemButton">
<property name="text">
<string>Add Item</string>
</property>
</widget>
</item>
<item row="7" column="11">
<widget class="QPushButton" name="editRemoveItemButton">
<property name="text">
<string>Delete Item</string>
</property>
</widget>
</item>
<item row="7" column="6">
<widget class="QLabel" name="itemValueLabel">
<property name="text">
<string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="9">
<widget class="QComboBox" name="editSelectParamComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Select parameter</string>
</property>
<property name="statusTip">
<string>Select parameter</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="12">
<widget class="Line" name="editLine1">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="11">
<widget class="QPushButton" name="readButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Read the current parameter value on the system</string>
</property>
<property name="statusTip">
<string>Read the current parameter value on the system</string>
</property>
<property name="text">
<string>Get</string>
</property>
</widget>
</item>
<item row="11" column="11">
<widget class="QPushButton" name="editDoneButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="4" column="10">
<widget class="QPushButton" name="writeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="statusTip">
<string>Transmit the current slider value to the system</string>
</property>
<property name="text">
<string>Set</string>
</property>
</widget>
</item>
<item row="8" column="10">
<widget class="QCheckBox" name="editInfoCheckBox">
<property name="text">
<string>Show Info</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="13" column="0" colspan="12">
<widget class="Line" name="editLine2">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="12" column="2" colspan="10">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="11" column="3" colspan="7">
<widget class="QLabel" name="editStatusLabel">
<property name="text">
<string>Please click first on refresh to update selection menus..</string>
</property>
</widget>
</item>
<item row="8" column="11">
<widget class="QPushButton" name="editRefreshParamsButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="12">
<widget class="QLabel" name="imageLabel">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>150</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "QGCToolWidgetItem.h"
#include <QMenu>
#include <QContextMenuEvent>
#include "QGCToolWidget.h"
#include "UASManager.h"
#include <QDockWidget>
QGCToolWidgetItem::QGCToolWidgetItem(const QString& name, QWidget *parent) :
QWidget(parent),
uas(NULL),
isInEditMode(false),
qgcToolWidgetItemName(name),
_component(-1)
{
startEditAction = new QAction(tr("Edit %1").arg(qgcToolWidgetItemName), this);
stopEditAction = new QAction(tr("Finish Editing %1").arg(qgcToolWidgetItemName), this);
deleteAction = new QAction(tr("Delete %1").arg(qgcToolWidgetItemName), this);
}
void QGCToolWidgetItem::init()
{
connect(startEditAction, SIGNAL(triggered()), this, SLOT(startEditMode()));
connect(stopEditAction, SIGNAL(triggered()), this, SLOT(endEditMode()));
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteLater()));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*)));
// Set first UAS if it exists
setActiveUAS(UASManager::instance()->getActiveUAS());
}
QGCToolWidgetItem::~QGCToolWidgetItem()
{
delete startEditAction;
delete stopEditAction;
delete deleteAction;
}
void QGCToolWidgetItem::contextMenuEvent (QContextMenuEvent* event)
{
QMenu menu(this);
if (!isInEditMode) {
menu.addAction(startEditAction);
menu.addAction(deleteAction);
} else {
menu.addAction(stopEditAction);
}
menu.exec(event->globalPos());
}
void QGCToolWidgetItem::setActiveUAS(UASInterface *uas)
{
this->uas = uas;
}
void QGCToolWidgetItem::setEditMode(bool editMode)
{
isInEditMode = editMode;
// Attempt to undock the dock widget
QWidget* p = this;
QDockWidget* dock;
do {
p = p->parentWidget();
dock = dynamic_cast<QDockWidget*>(p);
if (dock)
{
dock->setFloating(editMode);
break;
}
} while (p && !dock);
emit editingFinished();
}
#ifndef QGCTOOLWIDGETITEM_H
#define QGCTOOLWIDGETITEM_H
#include <QWidget>
#include <QAction>
#include <QSettings>
#include "UASInterface.h"
class QGCToolWidgetItem : public QWidget
{
Q_OBJECT
public:
QGCToolWidgetItem(const QString& name, QWidget *parent = 0);
~QGCToolWidgetItem();
int componentId() {
return _component;
}
virtual void setEditMode(bool editMode);
bool isEditMode() const { return isInEditMode; }
public slots:
void startEditMode() { setEditMode(true); }
void endEditMode() { setEditMode(false); }
virtual void setComponent(int comp) {
_component = comp;
}
virtual void writeSettings(QSettings& settings) = 0;
virtual void readSettings(const QSettings& settings) = 0;
virtual void readSettings(const QString& pre,const QVariantMap& settings) = 0;
virtual void setActiveUAS(UASInterface *uas);
signals:
void editingFinished();
protected:
void contextMenuEvent (QContextMenuEvent* event);
void init();
UASInterface* uas;
private:
QAction* startEditAction;
QAction* stopEditAction;
QAction* deleteAction;
bool isInEditMode;
QString qgcToolWidgetItemName;
int _component; ///< The MAV component (the process or device ID)
};
#endif // QGCTOOLWIDGETITEM_H
This diff is collapsed.
#ifndef QGCXYPLOT_H
#define QGCXYPLOT_H
#include "QGCToolWidgetItem.h"
namespace Ui
{
class QGCXYPlot;
}
class UASInterface;
class QwtPlot;
class XYPlotCurve;
class QGCXYPlot : public QGCToolWidgetItem
{
Q_OBJECT
public:
explicit QGCXYPlot(QWidget *parent = 0);
~QGCXYPlot();
virtual void setEditMode(bool editMode);
public slots:
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void appendData(int uasId, const QString& curve, const QString& unit, const QVariant& variant, quint64 usec);
void clearPlot();
void styleChanged(bool styleIsDark);
void updateMinMaxSettings();
private slots:
void on_maxDataShowSpinBox_valueChanged(int value);
void on_stopStartButton_toggled(bool checked);
void setTimeAxis();
void on_timeScrollBar_valueChanged(int value);
private:
Ui::QGCXYPlot *ui;
QwtPlot *plot;
XYPlotCurve* xycurve;
bool autoScaleTime;
double x; /**< Last unused value for the x-coordinate */
quint64 x_timestamp_us; /**< Timestamp that we last recieved a value for x */
bool x_valid; /**< Whether we have recieved an x value but so far no corresponding y value */
double y; /**< Last unused value for the x-coordinate */
quint64 y_timestamp_us; /**< Timestamp that we last recieved a value for x */
bool y_valid; /**< Whether we have recieved an x value but so far no corresponding y value */
quint64 max_timestamp_diff_us; /**< Only combine x and y to a data point if the timestamp for both doesn't differ by more than this */
};
#endif // QGCXYPLOT_H
This diff is collapsed.
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "RCChannelWidget.h"
#include <QPainter>
#define DIMMEST_COLOR QColor::fromRgb(0,100,0)
#define MIDBRIGHT_COLOR QColor::fromRgb(0,180,0)
#define BRIGHTEST_COLOR QColor::fromRgb(64,255,0)
RCChannelWidget::RCChannelWidget(QWidget *parent) :
QGroupBox(parent),
_value(_centerValue),
_min(_centerValue),
_max(_centerValue),
_trim(_centerValue),
_minValid(false),
_maxValid(false),
_showMinMax(false),
_showTrim(false)
{
}
/// @brief Draws the control
void RCChannelWidget::paintEvent(QPaintEvent *event)
{
// Let the group box draw the outer border
QGroupBox::paintEvent(event);
// Now we draw the innner contents
QPainter painter(this);
int fontHeight = painter.fontMetrics().height();
int rowHeigth = fontHeight + 2;
painter.setBrush(Qt::Dense4Pattern);
painter.setPen(QColor::fromRgb(128,128,64));
int curVal = _value;
if (curVal > _maxRange) {
curVal = _maxRange;
}
if (curVal < _minRange) {
curVal = _minRange;
}
if (isEnabled()) {
QLinearGradient hGradientBrush(0, 0, this->width(), this->height());
hGradientBrush.setColorAt(0.0,DIMMEST_COLOR);
hGradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
hGradientBrush.setColorAt(1.0, BRIGHTEST_COLOR);
// Calculate how much horizontal space we need to show a min/max value. We must be able to display four numeric
// digits for the rc value, plus we add another digit for spacing.
int minMaxDisplayWidth = painter.fontMetrics().width("00000");
// Draw the value axis line with center and end point tick marks. We need to leave enough space on the left and the right
// for the Min/Max value displays.
QRect rcValueAxis(minMaxDisplayWidth, rowHeigth * 2, width() - (minMaxDisplayWidth * 2), rowHeigth);
int yLine = rcValueAxis.y() + rcValueAxis.height() / 2;
painter.drawLine(rcValueAxis.left(), yLine, rcValueAxis.right(), yLine);
painter.drawLine(rcValueAxis.left(), rcValueAxis.top(), rcValueAxis.left(), rcValueAxis.bottom());
painter.drawLine(rcValueAxis.right(), rcValueAxis.top(), rcValueAxis.right(), rcValueAxis.bottom());
painter.drawLine(rcValueAxis.left() + rcValueAxis.width() / 2, rcValueAxis.top(), rcValueAxis.left() + rcValueAxis.width() / 2, rcValueAxis.bottom());
painter.setPen(QColor::fromRgb(50,255,50));
painter.setBrush(hGradientBrush);
if (_showMinMax) {
QString text;
// Draw the Min numeric value display to the left
painter.drawText(0, rowHeigth, minMaxDisplayWidth, fontHeight, Qt::AlignHCenter | Qt::AlignBottom, "Min");
if (_minValid) {
text = QString::number(_min);
} else {
text = "----";
}
painter.drawText(0, rowHeigth * 2, minMaxDisplayWidth, fontHeight, Qt::AlignHCenter | Qt::AlignBottom, text);
// Draw the Max numeric value display to the right
painter.drawText(width() - minMaxDisplayWidth, rowHeigth, minMaxDisplayWidth, fontHeight, Qt::AlignHCenter | Qt::AlignBottom, "Max");
if (_maxValid) {
text = QString::number(_max);
} else {
text = QString::number(_max);
}
painter.drawText(width() - minMaxDisplayWidth, rowHeigth * 2, minMaxDisplayWidth, fontHeight, Qt::AlignHCenter | Qt::AlignBottom, text);
// Draw the Min/Max tick marks on the axis
int xTick;
if (_minValid) {
int xTick = rcValueAxis.left() + (rcValueAxis.width() * ((float)(_min-_minRange) / (_maxRange-_minRange)));
painter.drawLine(xTick, rcValueAxis.top(), xTick, rcValueAxis.bottom());
}
if (_maxValid) {
xTick = rcValueAxis.left() + (rcValueAxis.width() * ((float)(_max-_minRange) / (_maxRange-_minRange)));
painter.drawLine(xTick, rcValueAxis.top(), xTick, rcValueAxis.bottom());
}
}
if (_showTrim) {
// Draw the Trim value pointer
_drawValuePointer(&painter,
rcValueAxis.left() + (rcValueAxis.width() * ((float)(_trim-_minRange) / (_maxRange-_minRange))), // x position for tip of triangle
(rowHeigth * 2) + (rowHeigth / 2) - 1, // y position for tip of triangle
rowHeigth / 2, // heigth of triangle
false); // draw upside down
// Draw the Trim value label
QString trimStr = tr("Trim %1").arg(QString::number(_trim));
int trimTextWidth = painter.fontMetrics().width(trimStr);
painter.drawText(rcValueAxis.left() + (rcValueAxis.width() * ((float)(_trim-_minRange) / (_maxRange-_minRange))) - (trimTextWidth / 2),
rowHeigth,
trimTextWidth,
fontHeight,
Qt::AlignLeft | Qt::AlignBottom,
trimStr);
}
// Draw the RC value pointer
_drawValuePointer(&painter,
rcValueAxis.left() + (rcValueAxis.width() * ((float)(curVal-_minRange) / (_maxRange-_minRange))), // x position for tip of triangle
(rowHeigth * 2) + (rowHeigth / 2) + 1, // y position for tip of triangle
rowHeigth / 2, // heigth of triangle
true); // draw right side up
// Draw the control value
QString valueStr = QString::number(_value);
int valueTextWidth = painter.fontMetrics().width(valueStr);
painter.drawText(rcValueAxis.left() + (rcValueAxis.width() * ((float)(_value-_minRange) / (_maxRange-_minRange))) - (valueTextWidth / 2),
rowHeigth * 3,
valueTextWidth,
fontHeight,
Qt::AlignLeft | Qt::AlignBottom,
valueStr);
painter.setPen(QColor::fromRgb(0,128,0));
painter.setBrush(hGradientBrush);
} else {
painter.setPen(QColor(Qt::gray));
painter.drawText(0, 0, width(), height(), Qt::AlignHCenter | Qt::AlignVCenter, tr("not available"));
}
}
void RCChannelWidget::setValue(int value)
{
_value = value;
update();
}
void RCChannelWidget::showMinMax(bool show)
{
_showMinMax = show;
update();
}
void RCChannelWidget::showTrim(bool show)
{
_showTrim = show;
update();
}
void RCChannelWidget::setValueAndMinMax(int val, int min, int max)
{
setValue(val);
setMinMax(min,max);
}
void RCChannelWidget::setMinMax(int min, int max)
{
_min = min;
_max = max;
update();
}
void RCChannelWidget::setTrim(int value)
{
_trim = value;
update();
}
/// @brief Draw rc value pointer triangle.
/// @param painter Draw using this painter
/// @param x X position for tip of triangle
/// @param y Y position for tip of triangle
/// @param heigth Height of triangle
/// @param rightSideUp true: draw triangle right side up, false: draw triangle upside down
void RCChannelWidget::_drawValuePointer(QPainter* painter, int xTip, int yTip, int height, bool rightSideUp)
{
QPointF trianglePoints[3];
// Topmost tip of triangle points to value
trianglePoints[0].setX(xTip);
trianglePoints[0].setY(yTip);
int yBottom;
if (rightSideUp) {
yBottom = yTip + height;
} else {
yBottom = yTip - height;
}
// Right bottom tip of triangle
trianglePoints[1].setX(xTip + (height * 0.75));
trianglePoints[1].setY(yBottom);
// Left bottom tip of triangle
trianglePoints[2].setX(xTip - (height * 0.75));
trianglePoints[2].setY(yBottom);
painter->drawPolygon (trianglePoints, 3);
}
/// @brief Set whether the Min range value is valid or not.
void RCChannelWidget::setMinValid(bool valid)
{
_minValid = valid;
update();
}
/// @brief Set whether the Max range value is valid or not.
void RCChannelWidget::setMaxValid(bool valid)
{
_maxValid = valid;
update();
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment