18#include "spinslider.h"
32void SpinSlider::init(
QString text, GROWTH_TYPE type, VALUE_TYPE dataType, qreal min, qreal max)
37 Q_ASSERT_X(min > 0.0,
"SpinSlider",
"Real type value must larger than 0!!");
42 mValueType = dataType;
46 mLabel =
new QLabel(text +
": ");
66void SpinSlider::changeValue(qreal value)
69 emit valueChanged(value);
72void SpinSlider::onSliderValueChanged(
int v)
75 if (mGrowthType == LINEAR)
77 value2 = mMin + v * (mMax - mMin) / mSlider->
maximum();
79 else if (mGrowthType == LOG)
81 value2 = mMin * std::exp(v * std::log(mMax / mMin) / mSlider->
maximum());
83 else if (mGrowthType == EXPONENT) {
84 value2 = mMin + std::pow(v, mExp) * (mMax - mMin) / std::pow(mSlider->
maximum(), mExp);
89void SpinSlider::setLabel(
QString newText)
94void SpinSlider::setValue(qreal v)
96 Q_ASSERT(mMin <= v && v <= mMax);
99 if (mGrowthType == LINEAR)
101 value2 =qRound((mSlider->
maximum() * (v - mMin) / (mMax - mMin)));
103 else if (mGrowthType == LOG)
105 value2 = qRound(std::log(v / mMin) * mSlider->
maximum() / std::log(mMax / mMin));
107 else if (mGrowthType == EXPONENT)
109 value2 = qRound(std::pow((v - mMin) * std::pow(mSlider->
maximum(), mExp) / (mMax - mMin), 1 / mExp));
116void SpinSlider::setPixelPos(qreal min, qreal max,
int val,
int space,
bool upsideDown)
119 static_cast<int>(max), val, space, upsideDown));
122void SpinSlider::setExponent(
const qreal exp)
void setSliderPosition(int)
void valueChanged(int value)
void setText(const QString &)
void setContentsMargins(int left, int top, int right, int bottom)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int sliderValueFromPosition(int min, int max, int position, int span, bool upsideDown)