23#include "effectwidget.h"
24#include "effectwidget_p.h"
26#include <QtAlgorithms>
30#include "effectparameter.h"
31#include "phonondefs_p.h"
46static const qreal DEFAULT_MIN = std::numeric_limits<qreal>::min();
47static const qreal DEFAULT_MAX = std::numeric_limits<qreal>::max();
48static const int DEFAULT_MIN_INT = std::numeric_limits<int>::min();
49static const int DEFAULT_MAX_INT = std::numeric_limits<int>::max();
50static const int SLIDER_RANGE = 8;
51static const int TICKINTERVAL = 4;
54#ifndef QT_NO_PHONON_EFFECTWIDGET
59EffectWidget::EffectWidget(Effect *effect,
QWidget *parent)
61 k_ptr(new EffectWidgetPrivate(effect))
68EffectWidget::~EffectWidget()
84EffectWidgetPrivate::EffectWidgetPrivate(Effect *e)
93void EffectWidgetPrivate::autogenerateUi()
99 for (
int i = 0; i < parameters.
count(); ++i) {
100 const EffectParameter ¶ = parameters.
at(i);
101 QVariant value = effect->parameterValue(para);
107 label->setText(para.name());
109 label->setToolTip(para.description());
113 switch (
int(para.type())) {
120 for (
int i = 0; i < para.possibleValues().count(); ++i) {
121 cb->
addItem(para.possibleValues().at(i).toString());
124 QObject::connect(cb, SIGNAL(currentIndexChanged(
int)), q, SLOT(_k_setIntParameter(
int)));
126 for (
int i = 0; i < para.possibleValues().count(); ++i) {
127 const QVariant &item = para.possibleValues().at(i);
142 QObject::connect(cb, SIGNAL(toggled(
bool)), q, SLOT(_k_setToggleParameter(
bool)));
149 bool minValueOk =
false;
150 bool maxValueOk =
false;
151 const int minValue = para.minimumValue().toInt(&minValueOk);
152 const int maxValue = para.maximumValue().toInt(&maxValueOk);
154 sb->
setRange(minValueOk ? minValue : DEFAULT_MIN_INT, maxValueOk ? maxValue : DEFAULT_MAX_INT);
156 QObject::connect(sb, SIGNAL(valueChanged(
int)), q, SLOT(_k_setIntParameter(
int)));
163 para.minimumValue().toReal() : DEFAULT_MIN;
165 para.maximumValue().toReal() : DEFAULT_MAX;
167 if (minValue == -1. && maxValue == 1.) {
171 slider->
setRange(-SLIDER_RANGE, +SLIDER_RANGE);
175 QObject::connect(slider, SIGNAL(valueChanged(
int)), q, SLOT(_k_setSliderParameter(
int)));
178 if (qAbs(maxValue - minValue) > 50)
186 SLOT(_k_setDoubleParameter(
double)));
198#ifndef QT_NO_SHORTCUT
199 label->setBuddy(control);
202 parameterForObject.insert(control, para);
207void EffectWidgetPrivate::_k_setToggleParameter(
bool checked)
210 if (parameterForObject.contains(q->sender())) {
211 effect->setParameterValue(parameterForObject[q->sender()], checked);
215void EffectWidgetPrivate::_k_setIntParameter(
int value)
218 if (parameterForObject.contains(q->sender())) {
219 effect->setParameterValue(parameterForObject[q->sender()], value);
223void EffectWidgetPrivate::_k_setDoubleParameter(
double value)
226 if (parameterForObject.contains(q->sender())) {
227 effect->setParameterValue(parameterForObject[q->sender()], value);
231void EffectWidgetPrivate::_k_setStringParameter(
const QString &value)
234 if (parameterForObject.contains(q->sender())) {
235 effect->setParameterValue(parameterForObject[q->sender()], value);
239void EffectWidgetPrivate::_k_setSliderParameter(
int value)
242 if (parameterForObject.contains(q->sender())) {
243 effect->setParameterValue(parameterForObject[q->sender()],
double(value) /
double(SLIDER_RANGE));
253#include "moc_effectwidget.cpp"
QString label(StandardShortcut id)
void setRange(int min, int max)
void addLayout(QLayout *layout, int stretch)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setCurrentIndex(int index)
void setRange(double minimum, double maximum)
void setSingleStep(double val)
void setValue(double val)
void setContentsMargins(const QMargins &margins)
const_reference at(qsizetype i) const const
qsizetype count() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setTickInterval(int ti)
void setTickPosition(TickPosition position)
void setRange(int minimum, int maximum)
bool toBool() const const
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qreal toReal(bool *ok) const const
QString toString() const const