86 lines
2.6 KiB
C++
86 lines
2.6 KiB
C++
#include "slidergroup.h"
|
|
#include <cmath>
|
|
#include <QWidget>
|
|
#include <QVBoxLayout>
|
|
|
|
SliderGroup::SliderGroup(QString name,
|
|
int min,
|
|
int max,
|
|
int decimals,
|
|
QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
QBoxLayout *layout;
|
|
if (decimals) {
|
|
layout = new QVBoxLayout;
|
|
slider.setOrientation(Qt::Vertical);
|
|
}
|
|
else {
|
|
layout = new QHBoxLayout;
|
|
slider.setOrientation(Qt::Horizontal);
|
|
slider.setMinimumHeight(10);
|
|
}
|
|
layout->setAlignment(Qt::AlignHCenter);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
slider.setFocusPolicy(Qt::StrongFocus);
|
|
slider.setTickPosition(QSlider::TicksBothSides);
|
|
slider.setTickInterval((max - min) / 11);
|
|
slider.setMinimumHeight(0);
|
|
slider.setSingleStep(1);
|
|
slider.setRange(min, max);
|
|
slider.setValue(0);
|
|
slider.setMinimumWidth(50);
|
|
slider.setToolTip(name);
|
|
slider.setStyleSheet("QSlider {"
|
|
"border: 1px solid #5a4855;"
|
|
"margin: 0px;}"
|
|
);
|
|
slider.setContentsMargins(0, 0, 0, 0);
|
|
valueBox.setFocusPolicy(Qt::NoFocus);
|
|
valueBox.setButtonSymbols(QAbstractSpinBox::NoButtons);
|
|
valueBox.setMinimumWidth(50);
|
|
if (decimals)
|
|
valueBox.setRange(-100, 100);
|
|
else
|
|
valueBox.setRange(min, max);
|
|
valueBox.setValue(0);
|
|
valueBox.setDecimals(decimals);
|
|
valueBox.setObjectName(name);
|
|
valueBox.setToolTip(name);
|
|
valueBox.setAlignment(Qt::AlignHCenter);
|
|
valueBox.setContentsMargins(0, 0, 0, 0);
|
|
connect(&slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
|
|
connect(&valueBox, SIGNAL(click()), this, SLOT(enableSlider()));
|
|
layout->addWidget(&slider);
|
|
layout->addWidget(&valueBox);
|
|
this->setStyleSheet("border: 1px solid #5a4855;"
|
|
"width: 60px;"
|
|
"margin: 0px;"
|
|
"background-color: #383034;"
|
|
);
|
|
layout->setSpacing(0);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
void SliderGroup::sliderValueChanged(int value)
|
|
{
|
|
valueBox.blockSignals(true);
|
|
valueBox.setValue(value);
|
|
valueBox.blockSignals(false);
|
|
emit valueChanged(value);
|
|
};
|
|
|
|
void SliderGroup::setValue(float value)
|
|
{
|
|
slider.blockSignals(true);
|
|
valueBox.blockSignals(true);
|
|
if (int(value) != slider.value())
|
|
slider.setValue(value);
|
|
if (valueBox.decimals())
|
|
valueBox.setValue(value - 100.0f);
|
|
else
|
|
valueBox.setValue(value);
|
|
slider.blockSignals(false);
|
|
valueBox.blockSignals(false);
|
|
}
|