Skip to content

Commit

Permalink
improved sliders labels alignment
Browse files Browse the repository at this point in the history
added a new option to set the number of decimal digits of the slider
FakeMotionControl added LIMITS::Max and LIMITS::Min options
  • Loading branch information
randaz81 committed Mar 2, 2023
1 parent 9ffd6c0 commit 54c1a6f
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 25 deletions.
12 changes: 12 additions & 0 deletions doc/release/master/yarpmotorgui_improved_labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
yarpmotorgui_improved_labels {#master}
-----------

### `yarpmotorgui`

* improved sliders labels alignment
* added a new option to set the number of decimal digits of the slider

### devices

* FakeMotionControl added LIMITS::Max and LIMITS::Min options

16 changes: 8 additions & 8 deletions src/devices/fakeMotionControl/fakeMotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,14 +1401,12 @@ bool FakeMotionControl::fromConfig(yarp::os::Searchable &config)
*/

/////// LIMITS
/*
Bottle &limits=config.findGroup("LIMITS");
if (limits.isNull())
{
yCWarning(FAKEMOTIONCONTROL) << "fromConfig() detected that Group LIMITS is not found in configuration file";
return false;
}
// current limit
/* // current limit
if (!extractGroup(limits, xtmp, "OverloadCurrents","a list of current limits", _njoints))
return false;
else
Expand All @@ -1425,19 +1423,19 @@ bool FakeMotionControl::fromConfig(yarp::os::Searchable &config)
return false;
else
for(i=1; i<xtmp.size(); i++) _currentLimits[i-1].peakCurrent=xtmp.get(i).asFloat64();
*/
// max limit
if (!extractGroup(limits, xtmp, "Max","a list of maximum angles (in degrees)", _njoints))
return false;
_limitsMax[i - 1] = 100;
else
for(i=1; i<xtmp.size(); i++) _limitsMax[i-1]=xtmp.get(i).asFloat64();

// min limit
if (!extractGroup(limits, xtmp, "Min","a list of minimum angles (in degrees)", _njoints))
return false;
_limitsMin[i - 1] = 0;
else
for(i=1; i<xtmp.size(); i++) _limitsMin[i-1]=xtmp.get(i).asFloat64();
/*
// Rotor max limit
if (!extractGroup(limits, xtmp, "RotorMax","a list of maximum rotor angles (in degrees)", _njoints))
return false;
Expand Down Expand Up @@ -2691,7 +2689,9 @@ bool FakeMotionControl::setLimitsRaw(int j, double min, double max)

bool FakeMotionControl::getLimitsRaw(int j, double *min, double *max)
{
return false;
*min = _limitsMin[j];
*max = _limitsMax[j];
return true;
}

bool FakeMotionControl::getGearboxRatioRaw(int j, double *gearbox)
Expand Down
10 changes: 10 additions & 0 deletions src/yarpmotorgui/jointitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,16 @@ void JointItem::enablePositionSliderDoubleValue(double value)
ui->sliderDirectPosition->resetTarget();
}

void JointItem::setNumberOfPositionSliderDecimals(size_t num)
{
ui->sliderMixedPosition->number_of_decimals=num;
ui->sliderTrajectoryPosition->number_of_decimals = num;
ui->sliderDirectPosition->number_of_decimals = num;
ui->sliderMixedPosition->number_of_decimals = num;
ui->sliderTrajectoryPosition->number_of_decimals = num;
ui->sliderDirectPosition->number_of_decimals = num;
}

void JointItem::disablePositionSliderDouble()
{
if (fabs(max_position - min_position) < 1.0)
Expand Down
2 changes: 2 additions & 0 deletions src/yarpmotorgui/jointitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class JointItem : public QWidget
void sequenceActivated();
void sequenceStopped();

void setNumberOfPositionSliderDecimals(size_t num);

void enablePositionSliderDoubleAuto();
void enablePositionSliderDoubleValue(double value);
void disablePositionSliderDouble();
Expand Down
6 changes: 3 additions & 3 deletions src/yarpmotorgui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ void MainWindow::onViewPositionTargetValue(bool val)
emit sig_viewPositionTargetValue(val);
}

void MainWindow::onSetPosSliderOptionMW(int choice, double val)
void MainWindow::onSetPosSliderOptionMW(int choice, double val, int digits)
{
emit sig_setPosSliderOptionMW(choice, val);
emit sig_setPosSliderOptionMW(choice, val, digits);
}
void MainWindow::onSetVelSliderOptionMW(int choice, double val)
{
Expand Down Expand Up @@ -682,7 +682,7 @@ bool MainWindow::init(QStringList enabledParts,
connect(this, SIGNAL(sig_viewCurrentValues(bool)), part, SLOT(onViewCurrentValues(bool)));
connect(this, SIGNAL(sig_viewMotorPositions(bool)), part, SLOT(onViewMotorPositions(bool)));
connect(this, SIGNAL(sig_viewDutyCycles(bool)), part, SLOT(onViewDutyCycles(bool)));
connect(this, SIGNAL(sig_setPosSliderOptionMW(int,double)), part, SLOT(onSetPosSliderOptionPI(int,double)));
connect(this, SIGNAL(sig_setPosSliderOptionMW(int,double,int)), part, SLOT(onSetPosSliderOptionPI(int,double,int)));
connect(this, SIGNAL(sig_setVelSliderOptionMW(int,double)), part, SLOT(onSetVelSliderOptionPI(int,double)));
connect(this, SIGNAL(sig_setTrqSliderOptionMW(int,double)), part, SLOT(onSetTrqSliderOptionPI(int,double)));
connect(this, SIGNAL(sig_viewPositionTargetBox(bool)), part, SLOT(onViewPositionTargetBox(bool)));
Expand Down
4 changes: 2 additions & 2 deletions src/yarpmotorgui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private slots:
void onEnableControlPWM(bool val);
void onEnableControlCurrent(bool val);
void onSliderOptionsClicked();
void onSetPosSliderOptionMW(int, double);
void onSetPosSliderOptionMW(int, double, int);
void onSetVelSliderOptionMW(int, double);
void onSetTrqSliderOptionMW(int, double);
void onJointClicked(int partIndex, int jointIndex);
Expand All @@ -142,7 +142,7 @@ private slots:
void sig_viewCurrentValues(bool);
void sig_viewMotorPositions(bool);
void sig_viewDutyCycles(bool);
void sig_setPosSliderOptionMW(int, double);
void sig_setPosSliderOptionMW(int, double, int);
void sig_setVelSliderOptionMW(int, double);
void sig_setTrqSliderOptionMW(int, double);
void sig_viewPositionTargetBox(bool);
Expand Down
6 changes: 4 additions & 2 deletions src/yarpmotorgui/partitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder&
int val_pos_choice = settings.value("val_pos_choice", 0).toInt();
int val_trq_choice = settings.value("val_trq_choice", 0).toInt();
int val_vel_choice = settings.value("val_vel_choice", 0).toInt();
int num_of_pos_decimals = settings.value("num_of_pos_decimals", 3).toInt();
double val_pos_custom_step = settings.value("val_pos_custom_step", 1.0).toDouble();
double val_trq_custom_step = settings.value("val_trq_custom_step", 1.0).toDouble();
double val_vel_custom_step = settings.value("val_vel_custom_step", 1.0).toDouble();
onSetPosSliderOptionPI(val_pos_choice, val_pos_custom_step);
onSetPosSliderOptionPI(val_pos_choice, val_pos_custom_step, num_of_pos_decimals);
onSetVelSliderOptionPI(val_vel_choice, val_vel_custom_step);
onSetTrqSliderOptionPI(val_trq_choice, val_trq_custom_step);
onSetCurSliderOptionPI(val_trq_choice, val_trq_custom_step);
Expand Down Expand Up @@ -2007,7 +2008,7 @@ void PartItem::onViewPositionTargetValue(bool ena)
}
}

void PartItem::onSetPosSliderOptionPI(int mode, double step)
void PartItem::onSetPosSliderOptionPI(int mode, double step, int numOfDec)
{
for (int i = 0; i<m_layout->count(); i++)
{
Expand All @@ -2028,6 +2029,7 @@ void PartItem::onSetPosSliderOptionPI(int mode, double step)
{
joint->disablePositionSliderDouble();
}
joint->setNumberOfPositionSliderDecimals(numOfDec);
}
}
void PartItem::onSetVelSliderOptionPI(int mode, double step)
Expand Down
2 changes: 1 addition & 1 deletion src/yarpmotorgui/partitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public slots:
void onViewMotorPositions(bool);
void onViewDutyCycles(bool);
void onViewCurrentValues(bool);
void onSetPosSliderOptionPI(int mode, double step);
void onSetPosSliderOptionPI(int mode, double step, int numOfDec);
void onSetVelSliderOptionPI(int mode, double step);
void onSetTrqSliderOptionPI(int mode, double step);
void onSetCurSliderOptionPI(int mode, double step);
Expand Down
15 changes: 11 additions & 4 deletions src/yarpmotorgui/sliderOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ sliderOptions::sliderOptions( QWidget *parent) :
val_pos_choice = settings.value("val_pos_choice", 0).toInt();
val_trq_choice = settings.value("val_trq_choice", 0).toInt();
val_vel_choice = settings.value("val_vel_choice", 0).toInt();
val_pos_digits = settings.value("num_of_pos_decimals", 3).toInt();
val_pos_custom_step = settings.value("val_pos_custom_step", 1.0).toDouble();
val_trq_custom_step = settings.value("val_trq_custom_step", 1.0).toDouble();
val_vel_custom_step = settings.value("val_vel_custom_step", 1.0).toDouble();
val_vel_limit = settings.value("velocity_slider_limit", 100.0).toDouble();

pos_digits_validator = new QIntValidator(this);
pos_step_validator = new QDoubleValidator(this);
vel_step_validator = new QDoubleValidator(this);
trq_step_validator = new QDoubleValidator(this);
vel_lims_validator = new QDoubleValidator(this);
vel_lims_validator->setRange(0 , 100);

ui->pos_step->setValidator(vel_step_validator);
ui->pos_decimal_digits->setValidator(pos_digits_validator);
ui->pos_step->setValidator(pos_step_validator);
ui->vel_step->setValidator(vel_step_validator);
ui->trq_step->setValidator(trq_step_validator);
ui->vel_limiter->setValidator(vel_lims_validator);

ui->pos_decimal_digits->setText(QString("%1").arg(val_pos_digits));
ui->pos_step->setText(QString("%1").arg(val_pos_custom_step));
ui->trq_step->setText(QString("%1").arg(val_trq_custom_step));
ui->vel_step->setText(QString("%1").arg(val_vel_custom_step));
ui->vel_limiter->setText(QString("%1").arg(val_vel_limit));

connect(this, SIGNAL(sig_setPosSliderOptionSO(int, double)), parent, SLOT(onSetPosSliderOptionMW(int, double)));
connect(this, SIGNAL(sig_setPosSliderOptionSO(int, double, int)), parent, SLOT(onSetPosSliderOptionMW(int, double, int)));
connect(this, SIGNAL(sig_setVelSliderOptionSO(int, double)), parent, SLOT(onSetVelSliderOptionMW(int, double)));
connect(this, SIGNAL(sig_setTrqSliderOptionSO(int, double)), parent, SLOT(onSetTrqSliderOptionMW(int, double)));

Expand Down Expand Up @@ -123,6 +127,7 @@ sliderOptions::~sliderOptions()
val_vel_custom_step = ui->vel_step->text().toDouble();
val_trq_custom_step = ui->trq_step->text().toDouble();
val_vel_limit = ui->vel_limiter->text().toDouble();
val_pos_digits = ui->pos_decimal_digits->text().toInt();

QSettings settings("YARP", "yarpmotorgui");
settings.setValue("val_pos_choice", val_pos_choice);
Expand All @@ -132,13 +137,15 @@ sliderOptions::~sliderOptions()
settings.setValue("val_trq_custom_step", val_trq_custom_step);
settings.setValue("val_vel_custom_step", val_vel_custom_step);
settings.setValue("velocity_slider_limit", val_vel_limit);
emit sig_setPosSliderOptionSO(val_pos_choice, val_pos_custom_step);
settings.setValue("num_of_pos_decimals", val_pos_digits);
emit sig_setPosSliderOptionSO(val_pos_choice, val_pos_custom_step, val_pos_digits);
emit sig_setVelSliderOptionSO(val_vel_choice, val_vel_custom_step);
emit sig_setTrqSliderOptionSO(val_trq_choice, val_trq_custom_step);
disconnect(this, SIGNAL(sig_setPosSliderOptionSO(int, double)), nullptr, nullptr);
disconnect(this, SIGNAL(sig_setPosSliderOptionSO(int, double, int)), nullptr, nullptr);
disconnect(this, SIGNAL(sig_setVelSliderOptionSO(int, double)), nullptr, nullptr);
disconnect(this, SIGNAL(sig_setTrqSliderOptionSO(int, double)), nullptr, nullptr);

delete pos_digits_validator;
delete pos_step_validator;
delete vel_step_validator;
delete trq_step_validator;
Expand Down
4 changes: 3 additions & 1 deletion src/yarpmotorgui/sliderOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,23 @@ class sliderOptions : public QDialog

private:
Ui::sliderOptions *ui;
int val_pos_digits;
double val_pos_custom_step;
double val_vel_custom_step;
double val_trq_custom_step;
double val_vel_limit;
int val_pos_choice;
int val_vel_choice;
int val_trq_choice;
QIntValidator* pos_digits_validator;
QDoubleValidator* pos_step_validator;
QDoubleValidator* vel_step_validator;
QDoubleValidator* trq_step_validator;
QDoubleValidator* vel_lims_validator;


signals:
void sig_setPosSliderOptionSO(int, double);
void sig_setPosSliderOptionSO(int, double, int);
void sig_setVelSliderOptionSO(int, double);
void sig_setTrqSliderOptionSO(int, double);
};
Expand Down
26 changes: 26 additions & 0 deletions src/yarpmotorgui/sliderOptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@
</rect>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>20</x>
<y>270</y>
<width>101</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Number of slider decimal digits:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="pos_decimal_digits">
<property name="geometry">
<rect>
<x>130</x>
<y>290</y>
<width>51</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
Expand Down
26 changes: 22 additions & 4 deletions src/yarpmotorgui/sliderWithTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,32 @@ void SliderWithTarget::paintEvent(QPaintEvent *e)
{
double value = this->value();
double newX = ((double)w / (double)totValues) * ((double)value + abs(this->minimum()));
sliderCurrentLabel->setGeometry(newX, -10, 40, 20);
sliderCurrentLabel->setText(QString("%L1").arg((double)value / sliderStep, 0, 'f', 3));
QString label_text = QString("%L1").arg((double)value / sliderStep, 0, 'f', number_of_decimals);
int label_text_siz = label_text.size();
sliderCurrentLabel->setText(label_text);
sliderCurrentLabel->setAlignment(Qt::AlignLeft);
sliderCurrentLabel->setAlignment(Qt::AlignVCenter);
//these adjustment are required to have the label properly aligned and
//to avoid overflow
double newX2 = newX;
if (newX2<0) newX2 = 0;
if (newX2>w-30) newX2 = w-30;
sliderCurrentLabel->setGeometry(newX2, -10, 60, 20);
}
if (enableViewTargetValue)
{
double newX = ((double)w / (double)totValues) * ((double)target + abs(this->minimum()));
sliderTargetLabel->setGeometry(newX, +10, 80, 20);
sliderTargetLabel->setText(QString("Ref:%L1").arg((double)target, 0, 'f', 3));
QString label_text = QString("Ref:%L1").arg((double)target, 0, 'f', number_of_decimals);
int label_text_siz = label_text.size();
sliderTargetLabel->setText(label_text);
sliderCurrentLabel->setAlignment(Qt::AlignLeft);
sliderCurrentLabel->setAlignment(Qt::AlignVCenter);
//these adjustment are required to have the label properly aligned and
//to avoid overflow
double newX2 = newX;
if (newX2 < 0) newX2 = 0;
if (newX2 > w - 30) newX2 = w - 30;
sliderTargetLabel->setGeometry(newX2, +10, 60, 20);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/yarpmotorgui/sliderWithTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SliderWithTarget : public QSlider
bool enableViewLabel = true;
bool enableViewTargetBox = true;
bool enableViewTargetValue = false;
int number_of_decimals = 0;
bool disableClickOutOfHandle;
SliderWithTarget(QWidget * parent = 0);
~SliderWithTarget();
Expand Down

0 comments on commit 54c1a6f

Please sign in to comment.