113 lines
3.6 KiB
C++
113 lines
3.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.setMaximumHeight(15);
|
|
valueBox.setMaximumHeight(15);
|
|
}
|
|
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 #aa8895;"
|
|
"background: #20182d;"
|
|
"margin: 0px;}"
|
|
"QSlider::groove:vertical {"
|
|
"border: 1px solid #999999;"
|
|
"width: 25px;"
|
|
"margin: -4px;}"
|
|
"QSlider::handle:vertical {"
|
|
"background: white;"
|
|
"border: 1px solid #5c5c5c;"
|
|
"width: 29px;"
|
|
"height: 7px;"
|
|
"margin: -2px;"
|
|
"border-radius: 2px;}"
|
|
"Qslider::tickmarks:vertical {background: white;"
|
|
"color: white;}"
|
|
"QSlider::add-page:vertical {background: blue;}"
|
|
"QSlider::sub-page:vertical {background: #20182d;}");
|
|
slider.setContentsMargins(0, 0, 0, 0);
|
|
valueBox.setFocusPolicy(Qt::NoFocus);
|
|
valueBox.setButtonSymbols(QAbstractSpinBox::NoButtons);
|
|
valueBox.setMinimumWidth(50);
|
|
if (decimals) {
|
|
valueBox.setRange(-84.0f, 0.0f);
|
|
valueBox.setSpecialValueText("-inf");
|
|
} 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 #aa8895;"
|
|
"background-color: black;"
|
|
"margin: 1px;"
|
|
);
|
|
layout->setSpacing(0);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
void SliderGroup::sliderValueChanged(int value)
|
|
{
|
|
valueBox.blockSignals(true);
|
|
if (valueBox.decimals()) {
|
|
float db = ((float)value / 771.0f) - 85.0f;
|
|
if (db <= -84.5f) {
|
|
valueBox.setSpecialValueText("-inf");
|
|
} else
|
|
valueBox.setValue(db);
|
|
} else {
|
|
valueBox.setValue(value);
|
|
}
|
|
valueBox.blockSignals(false);
|
|
emit valueChanged(value);
|
|
};
|
|
|
|
void SliderGroup::setValue(float value)
|
|
{
|
|
float db;
|
|
|
|
slider.blockSignals(true);
|
|
valueBox.blockSignals(true);
|
|
if (int(value) != slider.value())
|
|
slider.setValue(value);
|
|
if (valueBox.decimals()) {
|
|
db = (float)(value / 771.0f) - 85.0f;
|
|
valueBox.setValue(db);
|
|
} else
|
|
valueBox.setValue(value);
|
|
slider.blockSignals(false);
|
|
valueBox.blockSignals(false);
|
|
}
|