From de439a7c1986ba6a6b7387df0f6aa17b59e17fc3 Mon Sep 17 00:00:00 2001 From: pixhawk Date: Tue, 11 Jan 2011 07:59:59 +0100 Subject: [PATCH] Working on param slider --- src/ui/designer/QGCParamSlider.cc | 103 +++++++++++++++++++++++------- src/ui/designer/QGCParamSlider.h | 10 +++ src/ui/designer/QGCParamSlider.ui | 97 +++++++++++----------------- 3 files changed, 128 insertions(+), 82 deletions(-) diff --git a/src/ui/designer/QGCParamSlider.cc b/src/ui/designer/QGCParamSlider.cc index f5290b034..5af21c837 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 51bd73b85..07b9cdea3 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 c7022526a..7f195cb5d 100644 --- a/src/ui/designer/QGCParamSlider.ui +++ b/src/ui/designer/QGCParamSlider.ui @@ -6,8 +6,8 @@ 0 0 - 436 - 136 + 499 + 173 @@ -15,50 +15,21 @@ - + Informal Name.. - - - - - Float - - - - - Integer - - - - - Double - - - - - Short - - - - - Byte/Char - - - - - - + + Min - - + + Max @@ -78,37 +49,45 @@ - - + + - + Qt::Horizontal - - + + - - + + - Done + Please configure the parameter slider now: - - - - - Select Parameter.. - - + + + + TextLabel + - - + + + + + + + Done + + + + + true @@ -117,11 +96,13 @@ - - - - Please configure the parameter slider now: - + + + + + Select Parameter.. + + -- 2.22.0