Commit cc82e27b authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

fix broken double slider

parent 2bea9e11
......@@ -37,6 +37,7 @@ int main(int argc, char **argv)
dtkWidgetsParameter *first_real_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBox");
dtkWidgetsParameter *second_real_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterScientificSpinBox");
dtkWidgetsParameter *slider_real_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSlider");
real_parameter.connect([=] (QVariant v) {
double value = v.value<dtk::d_real>().value();
......@@ -47,6 +48,8 @@ int main(int argc, char **argv)
//scientific_parameter = 8.654321;
//scientific_parameter->setDecimals(6);
real_parameter.setMin(-10);
  • Fails to compile without a new version of dtk-core that includes dtkCoreParameterNumeric<T, E>::setMin(const T& min)

    I am working on publishing such a release.

  • Ouais, c'est ce que j'ai commenté un peu plus bas y'a une semaine ,-)

    La release est deja dispo nan ?

Please register or sign in to reply
real_parameter.setMax(3);
dtkWidgetsParameter *scientific_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&scientific_parameter, "dtkWidgetsParameterScientificSpinBox");
scientific_parameter.connect([=] (QVariant v) {
......@@ -54,6 +57,7 @@ int main(int argc, char **argv)
printf("scientific_parameter(XXX) = %.12f\n", value);
});
dtk::d_int longlong_parameter("A long long parameter", 666, 665, 800); // doc, value, min, max, decimals
dtkWidgetsParameter *longlong_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&longlong_parameter, "dtkWidgetsParameterLongLongSpinBox");
longlong_parameter.connect([=] (QVariant v) {
......@@ -107,6 +111,7 @@ int main(int argc, char **argv)
frame->setLayout(real_layout);
real_layout->addWidget(first_real_parameter_widget);
real_layout->addWidget(second_real_parameter_widget);
real_layout->addWidget(slider_real_parameter_widget);
central_layout->addWidget(new QSplitter);
central_layout->addWidget(scientific_parameter_widget);
......
# Version: $Id$
#
#
# Commentary:
#
#
# Change Log:
#
#
# Code:
name: dtk-widgets
channels:
- dtk
- dtk-forge-staging
- conda-forge
dependencies:
- qt >=5.9.0
- dtk-core >=2.6.0
- dtk-fonts >=2.1.1
- dtk-log
- dtk-themes
#
# dtk-visualization.yaml ends here
- qt >=5.9.0
- dtk-core >=2.6.0
- dtk-fonts >=2.1.1
- dtk-log
- dtk-themes
......@@ -29,8 +29,9 @@ public:
QLabel *min = nullptr;
QLabel *max = nullptr;
QLineEdit *val = nullptr;
QDoubleValidator *validator = nullptr;
double factor = 1.0;
double nx = 1000.0;
};
......@@ -44,25 +45,23 @@ dtkWidgetsParameterDoubleSlider::dtkWidgetsParameterDoubleSlider(QWidget* parent
d->min = new QLabel("min");
d->max = new QLabel("max");
d->val = new QLineEdit;
d->validator = new QDoubleValidator;
d->slider= new QSlider;
d->validator->setNotation(QDoubleValidator::StandardNotation);
d->validator->setLocale(QLocale::C);
d->slider->setOrientation(Qt::Horizontal);
d->slider->setTickPosition(QSlider::TicksBelow);
d->val->setValidator(d->validator);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->val);
layout->addWidget(d->min);
layout->addWidget(d->slider);
layout->addWidget(d->max);
QObject::connect(d->slider, &QSlider::valueChanged, [=](int value) {
d->val->setText(QString::number(value/d->factor));
});
QObject::connect(d->val, &QLineEdit::textChanged, [=](const QString& v) {
double value = v.toDouble();
d->slider->setValue(value * d->factor);
});
this->setLayout(layout);
}
......@@ -91,15 +90,19 @@ bool dtkWidgetsParameterDoubleSlider::connect(dtkCoreParameter *p)
return false;
}
int decimals = m_parameter->decimals();
d->factor = std::pow(10, decimals);
int minimum = m_parameter->min() * d->factor;
int maximum = m_parameter->max() * d->factor;
d->slider->setMinimum(minimum);
d->slider->setMaximum(maximum);
d->slider->setMinimum(0);
d->slider->setMaximum((int)d->nx);
d->min->setText(QString::number(m_parameter->min()));
d->max->setText(QString::number(m_parameter->max()));
d->validator->setRange(m_parameter->min(), m_parameter->max(), decimals);
d->slider->setToolTip(m_parameter->documentation());
int value = m_parameter->value() * d->factor;
if ((m_parameter->max()-m_parameter->min()) > std::numeric_limits<int>::max()) {
dtkWarn() << "Min/Max range too wide, the slider will be broken";
}
int value = (m_parameter->value()-m_parameter->min()) * d->nx / (m_parameter->max()-m_parameter->min());
// try to get the number of digits (integer part + decimals). first get the integer part
int max_i = std::max((int)std::abs(m_parameter->max()), (int)std::abs(m_parameter->min())) ;
int max_chars = std::to_string(max_i).length()+1+decimals;
......@@ -107,22 +110,32 @@ bool dtkWidgetsParameterDoubleSlider::connect(dtkCoreParameter *p)
QString text = QString::number(m_parameter->value());
d->val->setText(text);
d->slider->setValue(value);
d->slider->setTickInterval((maximum - minimum) / 10 );
d->slider->setTickInterval(1);
m_parameter->connect([=] (QVariant v)
{
double value = v.value<dtk::d_real>().value();
d->slider->blockSignals(true);
d->slider->setValue(value * d->factor);
d->min->setText(QString::number(m_parameter->min()));
d->max->setText(QString::number(m_parameter->max()));
d->validator->setRange(m_parameter->min(),m_parameter->max(), m_parameter->decimals());
int i = (value-m_parameter->min()) * d->nx / (m_parameter->max()-m_parameter->min());
d->slider->setValue(i);
d->val->setText(QString::number(value));
d->slider->blockSignals(false);
});
QObject::connect(d->slider, QOverload<int>::of(&QSlider::valueChanged), [=] (int v)
{
double value = (double)v / d->factor;
double value = m_parameter->min() + double(v)*(m_parameter->max()-m_parameter->min())/d->nx;
m_parameter->shareValue(QVariant::fromValue(value));
d->val->setText(QString::number(value));
});
QObject::connect(d->val, &QLineEdit::editingFinished, [=]() {
double value = d->val->text().toDouble();
m_parameter->shareValue(QVariant::fromValue(value));
});
return true;
......
Supports Markdown
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