diff --git a/src/ui/designer/QGCParamSlider.cc b/src/ui/designer/QGCParamSlider.cc index f5290b0..5af21c8 100644 --- a/src/ui/designer/QGCParamSlider.cc +++ b/src/ui/designer/QGCParamSlider.cc @@ -16,8 +16,22 @@ QGCParamSlider::QGCParamSlider(QWidget *parent) : ui(new Ui::QGCParamSlider) { ui->setupUi(this); - endEditMode(); - connect(ui->doneButton, SIGNAL(clicked()), this, SLOT(endEditMode())); + + scaledInt = ui->valueSlider->maximum() - ui->valueSlider->minimum(); + + ui->editDoneButton->show(); + ui->editMaxLabel->show(); + ui->editMinLabel->show(); + ui->editNameLineEdit->show(); + ui->editInstructionsLabel->show(); + ui->editRefreshParamsButton->show(); + ui->editSelectParamComboBox->show(); + ui->editSelectComponentComboBox->show(); + ui->editStatusLabel->show(); + ui->editMinSpinBox->show(); + ui->editMaxSpinBox->show(); + ui->editTypeComboBox->show(); + connect(ui->editDoneButton, SIGNAL(clicked()), this, SLOT(endEditMode())); } QGCParamSlider::~QGCParamSlider() @@ -27,31 +41,34 @@ QGCParamSlider::~QGCParamSlider() void QGCParamSlider::startEditMode() { - ui->doneButton->show(); - ui->maxLabel->show(); - ui->minLabel->show(); - ui->nameLineEdit->show(); - ui->instructionsLabel->show(); - ui->refreshParamsButton->show(); - ui->selectParamComboBox->show(); - ui->minSpinBox->show(); - ui->maxSpinBox->show(); - ui->typeComboBox->show(); + ui->editDoneButton->show(); + ui->editMaxLabel->show(); + ui->editMinLabel->show(); + ui->editNameLineEdit->show(); + ui->editInstructionsLabel->show(); + ui->editRefreshParamsButton->show(); + ui->editSelectParamComboBox->show(); + ui->editSelectComponentComboBox->show(); + ui->editStatusLabel->show(); + ui->editMinSpinBox->show(); + ui->editMaxSpinBox->show(); isInEditMode = true; } void QGCParamSlider::endEditMode() { - ui->doneButton->hide(); - ui->maxLabel->hide(); - ui->minLabel->hide(); - ui->nameLineEdit->hide(); - ui->instructionsLabel->hide(); - ui->refreshParamsButton->hide(); - ui->selectParamComboBox->hide(); - ui->minSpinBox->hide(); - ui->maxSpinBox->hide(); - ui->typeComboBox->hide(); + ui->editDoneButton->hide(); + ui->editMaxLabel->hide(); + ui->editMinLabel->hide(); + ui->editNameLineEdit->hide(); + ui->editInstructionsLabel->hide(); + ui->editRefreshParamsButton->hide(); + ui->editSelectParamComboBox->hide(); + ui->editSelectComponentComboBox->hide(); + ui->editStatusLabel->hide(); + ui->editMinSpinBox->hide(); + ui->editMaxSpinBox->hide(); + ui->editTypeComboBox->hide(); isInEditMode = false; emit editingFinished(); } @@ -68,6 +85,21 @@ void QGCParamSlider::sendParameter() } } +void QGCParamSlider::setSliderValue(int sliderValue) +{ + parameterValue = scaledIntToFloat(sliderValue); + QString unit(""); + ui->valueLabel->setText(QString("%1 %2").arg(parameterValue, 0, 'f', 3).arg(unit)); +} + +void QGCParamSlider::setParameterValue(int uas, int component, QString parameterName, float value) +{ + parameterValue = value; + QString unit(""); + ui->valueLabel->setText(QString("%1 %2").arg(value, 0, 'f', 3).arg(unit)); + ui->valueSlider->setValue(floatToScaledInt(value)); +} + void QGCParamSlider::changeEvent(QEvent *e) { QWidget::changeEvent(e); @@ -80,12 +112,35 @@ void QGCParamSlider::changeEvent(QEvent *e) } } -void QGCParamSlider::writeSettings(QSettings& settings) +float QGCParamSlider::scaledIntToFloat(int sliderValue) { + return (((double)sliderValue)/scaledInt)*(parameterMax - parameterMin); +} +int QGCParamSlider::floatToScaledInt(float value) +{ + return ((value - parameterMin)/(parameterMax - parameterMin))*scaledInt; } -void QGCParamSlider::readSettings(const QSettings& settings) +void QGCParamSlider::writeSettings(QSettings& settings) { + settings.setValue("TYPE", "SLIDER"); + settings.setValue("QGC_PARAM_SLIDER_DESCRIPTION", ui->nameLabel->text()); + //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); + settings.setValue("QGC_PARAM_SLIDER_PARAMID", ui->editSelectParamComboBox->currentText()); + settings.setValue("QGC_PARAM_SLIDER_COMPONENTID", ui->editSelectComponentComboBox->currentText()); + settings.setValue("QGC_PARAM_SLIDER_MIN", ui->editMinSpinBox->value()); + settings.setValue("QGC_PARAM_SLIDER_MAX", ui->editMaxSpinBox->value()); + settings.sync(); +} +void QGCParamSlider::readSettings(const QSettings& settings) +{ + ui->nameLabel->setText(settings.value("QGC_PARAM_SLIDER_DESCRIPTION").toString()); + //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); + ui->editSelectParamComboBox->setCurrentText(settings.value("QGC_PARAM_SLIDER_PARAMID").toString()); + ui->editSelectComponentsComboBox->setCurrentText(settings.value("QGC_PARAM_SLIDER_COMPONENTID").toString()); + ui->editMinSpinBox(settings.value("QGC_PARAM_SLIDER_MIN").toFloat()); + ui->editMaxSpinBox(settings.value("QGC_PARAM_SLIDER_MAX").toFloat()); + qDebug() << "DONE READING SETTINGS"; } diff --git a/src/ui/designer/QGCParamSlider.h b/src/ui/designer/QGCParamSlider.h index 51bd73b..07b9cde 100644 --- a/src/ui/designer/QGCParamSlider.h +++ b/src/ui/designer/QGCParamSlider.h @@ -24,6 +24,10 @@ public slots: void endEditMode(); /** @brief Send the parameter to the MAV */ void sendParameter(); + /** @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 component, QString parameterName, float value); void writeSettings(QSettings& settings); void readSettings(const QSettings& settings); @@ -34,8 +38,14 @@ protected: float parameterMin; float parameterMax; int component; ///< 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; }; diff --git a/src/ui/designer/QGCParamSlider.ui b/src/ui/designer/QGCParamSlider.ui index c702252..7f195cb 100644 --- a/src/ui/designer/QGCParamSlider.ui +++ b/src/ui/designer/QGCParamSlider.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>436</width> - <height>136</height> + <width>499</width> + <height>173</height> </rect> </property> <property name="windowTitle"> @@ -15,50 +15,21 @@ </property> <layout class="QGridLayout" name="gridLayout"> <item row="1" column="0"> - <widget class="QLineEdit" name="nameLineEdit"> + <widget class="QLineEdit" name="editNameLabel"> <property name="text"> <string>Informal Name..</string> </property> </widget> </item> - <item row="1" column="1" colspan="2"> - <widget class="QComboBox" name="typeComboBox"> - <item> - <property name="text"> - <string>Float</string> - </property> - </item> - <item> - <property name="text"> - <string>Integer</string> - </property> - </item> - <item> - <property name="text"> - <string>Double</string> - </property> - </item> - <item> - <property name="text"> - <string>Short</string> - </property> - </item> - <item> - <property name="text"> - <string>Byte/Char</string> - </property> - </item> - </widget> - </item> - <item row="1" column="3"> - <widget class="QLabel" name="minLabel"> + <item row="1" column="4"> + <widget class="QLabel" name="editMinLabel"> <property name="text"> <string>Min</string> </property> </widget> </item> - <item row="1" column="5"> - <widget class="QLabel" name="maxLabel"> + <item row="1" column="6"> + <widget class="QLabel" name="editMaxLabel"> <property name="text"> <string>Max</string> </property> @@ -78,37 +49,45 @@ </property> </widget> </item> - <item row="2" column="2" colspan="2"> - <widget class="QDoubleSpinBox" name="minSpinBox"/> + <item row="2" column="3" colspan="2"> + <widget class="QDoubleSpinBox" name="editMinSpinBox"/> </item> - <item row="2" column="4"> + <item row="2" column="5"> <widget class="QSlider" name="valueSlider"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="2" column="5"> - <widget class="QDoubleSpinBox" name="maxSpinBox"/> + <item row="2" column="6"> + <widget class="QDoubleSpinBox" name="editMaxSpinBox"/> </item> - <item row="3" column="5"> - <widget class="QPushButton" name="doneButton"> + <item row="0" column="0" colspan="7"> + <widget class="QLabel" name="editInstructionsLabel"> <property name="text"> - <string>Done</string> + <string>Please configure the parameter slider now:</string> </property> </widget> </item> - <item row="3" column="0" colspan="2"> - <widget class="QComboBox" name="selectParamComboBox"> - <item> - <property name="text"> - <string>Select Parameter..</string> - </property> - </item> + <item row="5" column="0" colspan="6"> + <widget class="QLabel" name="editStatusLabel"> + <property name="text"> + <string>TextLabel</string> + </property> </widget> </item> - <item row="3" column="2" colspan="2"> - <widget class="QPushButton" name="refreshParamsButton"> + <item row="3" column="0" colspan="3"> + <widget class="QComboBox" name="editSelectComponentComboBox"/> + </item> + <item row="5" column="6"> + <widget class="QPushButton" name="editDoneButton"> + <property name="text"> + <string>Done</string> + </property> + </widget> + </item> + <item row="3" column="6"> + <widget class="QPushButton" name="editRefreshParamsButton"> <property name="enabled"> <bool>true</bool> </property> @@ -117,11 +96,13 @@ </property> </widget> </item> - <item row="0" column="0" colspan="6"> - <widget class="QLabel" name="instructionsLabel"> - <property name="text"> - <string>Please configure the parameter slider now:</string> - </property> + <item row="3" column="4" colspan="2"> + <widget class="QComboBox" name="editSelectParamComboBox"> + <item> + <property name="text"> + <string>Select Parameter..</string> + </property> + </item> </widget> </item> </layout>